-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix thumbnail generation for website entries
This was accomplished by moving the thumbnail generation (using vite-imagetools) from the server to the client. This is supposedly because SvelteKit does not currently have support for loading non-raw assets on the server side (per <sveltejs/kit#5240>). At least, moving the logic to the front end worked like a charm.
- Loading branch information
Showing
4 changed files
with
37 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { get, readable, type Readable } from 'svelte/store'; | ||
import type { WebsiteEntry } from '../types'; | ||
|
||
type ImagetoolsResult = { default: string[] }; | ||
type GlobUrlStore = Readable<Record<string, ImagetoolsResult>>; | ||
|
||
// Resize the website images at build time so that the appropriate (smaller) | ||
// versions of each website image can be served | ||
export const resizedWebsiteUrlMap: GlobUrlStore = readable( | ||
import.meta.glob('../../images/websites/*.jpg', { | ||
// Generate additional sizes for each pregenerated website image | ||
query: { format: 'jpg', width: '256;512' }, | ||
// Resolve each import promise and store the final values | ||
eager: true | ||
}) | ||
); | ||
|
||
// Retrieve the URL to the regular-sized thumbnail for this website | ||
export function getWebsite1xThumbnailUrl(website: WebsiteEntry): string { | ||
const $resizedWebsiteUrlMap = get(resizedWebsiteUrlMap); | ||
const imagePath = `../../images/websites/${website.id}.jpg`; | ||
return $resizedWebsiteUrlMap[imagePath].default[0]; | ||
} | ||
|
||
// Retrieve the URL to the high-density (Retina) thumbnail for this website | ||
export function getWebsite2xThumbnailUrl(website: WebsiteEntry): string { | ||
const $resizedWebsiteUrlMap = get(resizedWebsiteUrlMap); | ||
const imagePath = `../../images/websites/${website.id}.jpg`; | ||
return $resizedWebsiteUrlMap[imagePath].default[1]; | ||
} |