@geekity/cms 0.50.0 → 0.50.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/assets.d.ts +1 -1
- package/dist/admin/assets.d.ts.map +1 -1
- package/dist/admin/assets.js +3 -5
- package/dist/admin/assets.js.map +1 -1
- package/dist/admin/routes.js +1 -1
- package/dist/admin/routes.js.map +1 -1
- package/dist/admin/settings-general.js +4 -3
- package/dist/admin/settings-general.js.map +1 -1
- package/dist/avatars/avatars.d.ts +12 -9
- package/dist/avatars/avatars.d.ts.map +1 -1
- package/dist/avatars/avatars.js +66 -33
- package/dist/avatars/avatars.js.map +1 -1
- package/dist/cms/services.d.ts.map +1 -1
- package/dist/cms/services.js +2 -0
- package/dist/cms/services.js.map +1 -1
- package/dist/content/image-tags.d.ts +5 -1
- package/dist/content/image-tags.d.ts.map +1 -1
- package/dist/content/image-tags.js +8 -11
- package/dist/content/image-tags.js.map +1 -1
- package/dist/content/uploads.js +2 -3
- package/dist/content/uploads.js.map +1 -1
- package/dist/files/static-files.js +7 -4
- package/dist/files/static-files.js.map +1 -1
- package/dist/files/upload-types.d.ts +2 -5
- package/dist/files/upload-types.d.ts.map +1 -1
- package/dist/files/upload-types.js +2 -5
- package/dist/files/upload-types.js.map +1 -1
- package/dist/fonts/index.d.ts +1 -1
- package/dist/fonts/index.d.ts.map +1 -1
- package/dist/fonts/index.js +1 -1
- package/dist/fonts/index.js.map +1 -1
- package/dist/fonts/roles.d.ts +11 -2
- package/dist/fonts/roles.d.ts.map +1 -1
- package/dist/fonts/roles.js +57 -11
- package/dist/fonts/roles.js.map +1 -1
- package/dist/fonts/store.d.ts.map +1 -1
- package/dist/fonts/store.js +9 -7
- package/dist/fonts/store.js.map +1 -1
- package/dist/images/derived-sets.d.ts +56 -0
- package/dist/images/derived-sets.d.ts.map +1 -0
- package/dist/images/derived-sets.js +116 -0
- package/dist/images/derived-sets.js.map +1 -0
- package/dist/images/icon-setting.d.ts.map +1 -1
- package/dist/images/icon-setting.js +6 -10
- package/dist/images/icon-setting.js.map +1 -1
- package/dist/images/icons.d.ts +16 -13
- package/dist/images/icons.d.ts.map +1 -1
- package/dist/images/icons.js +103 -43
- package/dist/images/icons.js.map +1 -1
- package/dist/images/markup.d.ts.map +1 -1
- package/dist/images/markup.js +2 -12
- package/dist/images/markup.js.map +1 -1
- package/dist/images/paths.d.ts +32 -1
- package/dist/images/paths.d.ts.map +1 -1
- package/dist/images/paths.js +27 -3
- package/dist/images/paths.js.map +1 -1
- package/dist/images/variants.d.ts +34 -32
- package/dist/images/variants.d.ts.map +1 -1
- package/dist/images/variants.js +157 -168
- package/dist/images/variants.js.map +1 -1
- package/dist/media/library.js +3 -3
- package/dist/media/library.js.map +1 -1
- package/dist/theme/assets.d.ts +8 -0
- package/dist/theme/assets.d.ts.map +1 -1
- package/dist/theme/assets.js +92 -9
- package/dist/theme/assets.js.map +1 -1
- package/dist/util/public-address.d.ts +19 -1
- package/dist/util/public-address.d.ts.map +1 -1
- package/dist/util/public-address.js +51 -1
- package/dist/util/public-address.js.map +1 -1
- package/dist/util/queue.d.ts +5 -0
- package/dist/util/queue.d.ts.map +1 -1
- package/dist/util/queue.js +21 -0
- package/dist/util/queue.js.map +1 -1
- package/dist/util/url.d.ts +10 -0
- package/dist/util/url.d.ts.map +1 -1
- package/dist/util/url.js +27 -0
- package/dist/util/url.js.map +1 -1
- package/dist/web/asset-routes.d.ts.map +1 -1
- package/dist/web/asset-routes.js +33 -33
- package/dist/web/asset-routes.js.map +1 -1
- package/dist/web/avatar-routes.d.ts.map +1 -1
- package/dist/web/avatar-routes.js +5 -7
- package/dist/web/avatar-routes.js.map +1 -1
- package/dist/web/compression.d.ts +1 -0
- package/dist/web/compression.d.ts.map +1 -1
- package/dist/web/compression.js +22 -8
- package/dist/web/compression.js.map +1 -1
- package/dist/web/document-page.js +2 -2
- package/dist/web/document-page.js.map +1 -1
- package/dist/web/font-routes.d.ts.map +1 -1
- package/dist/web/font-routes.js +2 -4
- package/dist/web/font-routes.js.map +1 -1
- package/dist/web/markdown-representation.js +2 -2
- package/dist/web/markdown-representation.js.map +1 -1
- package/dist/web/opensearch.js +2 -2
- package/dist/web/opensearch.js.map +1 -1
- package/dist/web/paths.js +1 -1
- package/dist/web/paths.js.map +1 -1
- package/dist/web/request.d.ts +6 -2
- package/dist/web/request.d.ts.map +1 -1
- package/dist/web/request.js +9 -7
- package/dist/web/request.js.map +1 -1
- package/dist/web/routes.d.ts.map +1 -1
- package/dist/web/routes.js +2 -1
- package/dist/web/routes.js.map +1 -1
- package/dist/web/site-index.js +2 -2
- package/dist/web/site-index.js.map +1 -1
- package/dist/webmention/cited-picture.d.ts.map +1 -1
- package/dist/webmention/cited-picture.js +2 -1
- package/dist/webmention/cited-picture.js.map +1 -1
- package/dist/webmention/fetch-public.d.ts.map +1 -1
- package/dist/webmention/fetch-public.js +5 -3
- package/dist/webmention/fetch-public.js.map +1 -1
- package/package.json +3 -2
package/dist/images/paths.js
CHANGED
|
@@ -3,12 +3,36 @@ import { UPLOAD_DIRECTORY } from '../content/uploads.js';
|
|
|
3
3
|
import { IMAGES, dataPath } from '../files/data-files.js';
|
|
4
4
|
import { findAsset } from '../files/static-files.js';
|
|
5
5
|
import { assetVersion, ASSET_VERSION_PARAM } from '../theme/assets.js';
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The most pixels a derived image is decoded from: a 60 megapixel camera's
|
|
8
|
+
* full frame, and well under sharp's own default. A flat PNG of a few hundred
|
|
9
|
+
* kilobytes can declare far more, and decoding it costs memory in proportion.
|
|
10
|
+
*/
|
|
11
|
+
export const MAX_INPUT_PIXELS = 60_000_000;
|
|
12
|
+
/** sharp's input options for a picture the site derives from. */
|
|
13
|
+
export const DECODE_OPTIONS = { autoOrient: true, limitInputPixels: MAX_INPUT_PIXELS };
|
|
14
|
+
/** Whether a header's dimensions are within {@link MAX_INPUT_PIXELS}. */
|
|
15
|
+
export function decodable(size) {
|
|
16
|
+
return size.width * size.height <= MAX_INPUT_PIXELS;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The upload a source path names, or `undefined` when it names none.
|
|
20
|
+
*
|
|
21
|
+
* The source is rebuilt from the resolved file, so however a caller spelled
|
|
22
|
+
* it, a record and the URLs built from it carry the canonical path.
|
|
23
|
+
*/
|
|
24
|
+
export function locateUpload(config, source) {
|
|
7
25
|
const file = sourceFile(config, source);
|
|
8
26
|
if (file === undefined)
|
|
9
27
|
return undefined;
|
|
10
|
-
const
|
|
11
|
-
|
|
28
|
+
const segments = path
|
|
29
|
+
.relative(path.resolve(config.contentDir, UPLOAD_DIRECTORY), file)
|
|
30
|
+
.split(path.sep);
|
|
31
|
+
return {
|
|
32
|
+
source: segments.join('/'),
|
|
33
|
+
file,
|
|
34
|
+
directory: dataPath(config.dataDir, IMAGES, ...segments),
|
|
35
|
+
};
|
|
12
36
|
}
|
|
13
37
|
/**
|
|
14
38
|
* The upload as an absolute path, or `undefined` when it is not one.
|
package/dist/images/paths.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/images/paths.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAiBvE,MAAM,UAAU,UAAU,CAAC,MAAmB,EAAE,MAAc;
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/images/paths.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAiBvE;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAAC;AAE3C,iEAAiE;AACjE,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,gBAAgB,EAAE,gBAAgB,EAAW,CAAC;AAEhG,yEAAyE;AACzE,MAAM,UAAU,SAAS,CAAC,IAAuC;IAC/D,OAAO,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,IAAI,gBAAgB,CAAC;AACtD,CAAC;AAYD;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,MAAmB,EAAE,MAAc;IAC9D,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACzC,MAAM,QAAQ,GAAG,IAAI;SAClB,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,gBAAgB,CAAC,EAAE,IAAI,CAAC;SACjE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO;QACL,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;QAC1B,IAAI;QACJ,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;KACzD,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACxB,MAAuC,EACvC,MAAc;IAEd,IAAI,MAAM,KAAK,EAAE,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IAC7D,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;IAC/D,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACxC,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,MAAmB,EAAE,MAAc;IAC/D,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAClF,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,OAA2B;IACjE,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,mBAAmB,IAAI,OAAO,EAAE,CAAC;AACpF,CAAC"}
|
|
@@ -31,9 +31,10 @@ export interface ImageVariant {
|
|
|
31
31
|
* What was derived from one upload, and the intrinsic size of the upload
|
|
32
32
|
* itself.
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
* an image: the dimensions are
|
|
36
|
-
* variants are generated and read back, never probed per
|
|
34
|
+
* The sidecar holds it with the version of the bytes it was derived from. It
|
|
35
|
+
* exists so that rendering a page never opens an image: the dimensions are
|
|
36
|
+
* recorded when the variants are generated and read back, never probed per
|
|
37
|
+
* request.
|
|
37
38
|
*/
|
|
38
39
|
export interface ImageRecord {
|
|
39
40
|
/** The upload it was derived from, relative to `content/uploads/`. */
|
|
@@ -44,14 +45,7 @@ export interface ImageRecord {
|
|
|
44
45
|
height: number;
|
|
45
46
|
/** The original's own format, which is the one the `<img>` falls back to. */
|
|
46
47
|
format: string;
|
|
47
|
-
/**
|
|
48
|
-
* The original's modification time in milliseconds.
|
|
49
|
-
*
|
|
50
|
-
* It is what makes a stale record notice it is stale. The CMS never
|
|
51
|
-
* overwrites an upload — a second `photo.png` becomes `photo-2.png` — but a
|
|
52
|
-
* file dropped in by hand can be replaced, and a record that outlived its
|
|
53
|
-
* original would give the page the wrong dimensions.
|
|
54
|
-
*/
|
|
48
|
+
/** The original's modification time in milliseconds when it was derived from. */
|
|
55
49
|
sourceModified: number;
|
|
56
50
|
/** Every derived copy, by format in configured order and then by width. */
|
|
57
51
|
variants: ImageVariant[];
|
|
@@ -60,41 +54,42 @@ export interface ImageRecord {
|
|
|
60
54
|
export declare function imageMediaType(format: string): string | undefined;
|
|
61
55
|
/**
|
|
62
56
|
* A record as a page renders it: what was derived, and the hash of the
|
|
63
|
-
* original's bytes that every derived URL carries.
|
|
64
|
-
* sidecar; it is read off the original, so a sidecar written before URLs
|
|
65
|
-
* carried it needs no rewrite.
|
|
57
|
+
* original's bytes that every derived URL carries.
|
|
66
58
|
*/
|
|
67
59
|
export interface DescribedImage extends ImageRecord {
|
|
68
60
|
/** See {@link sourceVersion}. Without it a derived URL is served for a day, not a year. */
|
|
69
61
|
version?: string | undefined;
|
|
70
62
|
}
|
|
63
|
+
/** A derived file, and the version of the upload's bytes it was derived from. */
|
|
64
|
+
export interface DerivedAsset extends StaticAsset {
|
|
65
|
+
version: string;
|
|
66
|
+
}
|
|
71
67
|
/** The public URL of one derived file, naming the original's bytes when `version` is given. */
|
|
72
68
|
export declare function variantUrl(source: string, variant: ImageVariant, version?: string): string;
|
|
73
69
|
/**
|
|
74
|
-
* Derive every variant of one upload and record what was derived
|
|
70
|
+
* Derive every variant of one upload and record what was derived, unless the
|
|
71
|
+
* bytes it holds now have been derived already.
|
|
75
72
|
*
|
|
76
|
-
* Returns `undefined`
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* those is an error: an upload that has no variants is the ordinary case
|
|
80
|
-
* most of what a site holds, and the caller
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
73
|
+
* Returns `undefined` when optimization is off, when the file is not a raster
|
|
74
|
+
* image the CMS derives from (a GIF, a PDF, a text file), when it is animated,
|
|
75
|
+
* larger than {@link MAX_INPUT_PIXELS}, undecodable, or not there at all. None
|
|
76
|
+
* of those is an error: an upload that has no variants is the ordinary case
|
|
77
|
+
* for most of what a site holds, and the caller falls back to the original,
|
|
78
|
+
* which is what it would have served anyway. A source that could not be
|
|
79
|
+
* derived is remembered as such until its bytes change. A failure to make
|
|
80
|
+
* the directory or write a file is thrown, because it is the server failing
|
|
81
|
+
* and not the upload.
|
|
85
82
|
*
|
|
86
83
|
* Two callers asking for the same image at once share one encode.
|
|
87
84
|
*/
|
|
88
85
|
export declare function generateImageVariants(config: ImageConfig, source: string): Promise<ImageRecord | undefined>;
|
|
89
86
|
/**
|
|
90
|
-
* Wait for every
|
|
87
|
+
* Wait for every derivation still running under one site's data directory.
|
|
91
88
|
*
|
|
92
89
|
* A render starts derivation in the background and returns, so an encode can
|
|
93
90
|
* outlive the request that asked for it and, without this, the site it was
|
|
94
91
|
* writing into: closing a site waits here so nothing is left writing under
|
|
95
|
-
* `dataDir` once close returns.
|
|
96
|
-
* for too. A failure is not this caller's to report; the render that started
|
|
97
|
-
* the generation already logged it.
|
|
92
|
+
* `dataDir` once close returns.
|
|
98
93
|
*/
|
|
99
94
|
export declare function settleImageVariants(config: Pick<ImageConfig, 'dataDir'>): Promise<void>;
|
|
100
95
|
/**
|
|
@@ -102,11 +97,13 @@ export declare function settleImageVariants(config: Pick<ImageConfig, 'dataDir'>
|
|
|
102
97
|
*
|
|
103
98
|
* Synchronous and cached, because it is called once per image while a page
|
|
104
99
|
* renders. `undefined` means the caller should serve the plain original: the
|
|
105
|
-
* upload is not an image,
|
|
100
|
+
* upload is not an image, nothing has been derived from the bytes it holds
|
|
101
|
+
* now, or nothing could be.
|
|
106
102
|
*/
|
|
107
103
|
export declare function describeImage(config: ImageConfig, source: string): DescribedImage | undefined;
|
|
108
104
|
/**
|
|
109
|
-
* Take one upload's derived files away
|
|
105
|
+
* Take one upload's derived files away, once any derivation writing them has
|
|
106
|
+
* finished.
|
|
110
107
|
*
|
|
111
108
|
* Forgiving by design: an upload with nothing derived from it is the ordinary
|
|
112
109
|
* case, and this runs after the original has already gone, so refusing to
|
|
@@ -121,8 +118,13 @@ export declare function removeImageVariants(config: ImageConfig, source: string)
|
|
|
121
118
|
* rebuilds the whole set for that source and then serves it, which is what
|
|
122
119
|
* makes the derived directory disposable, as everything derived must be. A
|
|
123
120
|
* request for a width or a format the site does not offer is a 404 and encodes
|
|
124
|
-
* nothing, so nobody can make the server work by asking for sizes.
|
|
121
|
+
* nothing, so nobody can make the server work by asking for sizes. An icon
|
|
122
|
+
* name is answered only under `iconSource`, the site icon's upload. A file
|
|
123
|
+
* whose upload has gone is answered with nothing and removed.
|
|
124
|
+
*
|
|
125
|
+
* The file comes back with the version of the bytes it was derived from, and
|
|
126
|
+
* a set derived from older bytes is derived again first.
|
|
125
127
|
*/
|
|
126
|
-
export declare function findImageVariant(config: ImageConfig, relative: string): Promise<
|
|
128
|
+
export declare function findImageVariant(config: ImageConfig, relative: string, iconSource?: string): Promise<DerivedAsset | undefined>;
|
|
127
129
|
export declare function thumbnailUrl(config: ImageConfig, source: string, url: string): string;
|
|
128
130
|
//# sourceMappingURL=variants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../src/images/variants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../src/images/variants.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAc5D,OAAO,KAAK,EAAE,WAAW,EAAU,MAAM,YAAY,CAAC;AAEtD;;;;;;;;;;;;GAYG;AAEH,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,gFAAgF;AAChF,eAAO,MAAM,iBAAiB,eAAe,CAAC;AAE9C,qCAAqC;AACrC,MAAM,WAAW,YAAY;IAC3B,4EAA4E;IAC5E,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAW;IAC1B,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,MAAM,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,cAAc,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B;AAgCD,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEjE;AAED;;;GAGG;AACH,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,2FAA2F;IAC3F,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B;AAED,iFAAiF;AACjF,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,+FAA+F;AAC/F,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAE1F;AA8BD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAOlC;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7F;AA4JD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAK7F;AAgCD;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAI5F;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAqBnC;AAID,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAQrF"}
|
package/dist/images/variants.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { statSync
|
|
2
|
-
import { mkdir
|
|
1
|
+
import { statSync } from 'node:fs';
|
|
2
|
+
import { mkdir } from 'node:fs/promises';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import sharp from 'sharp';
|
|
5
5
|
import { writeFileAtomically } from '../files/atomic.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
6
|
+
import { messageOf } from '../util/errors.js';
|
|
7
|
+
import { encodePath, plainRelativePath } from '../util/url.js';
|
|
8
|
+
import { deriveSet, findDerivedFile, forgetDerivedSets, settleDerivedSets, settledSet, } from './derived-sets.js';
|
|
9
|
+
import { isDerivedIcon, SITE_ICONS } from './icons.js';
|
|
10
|
+
import { DECODE_OPTIONS, decodable, locateUpload, sourceVersion, versioned } from './paths.js';
|
|
10
11
|
import { VARIANT_ASSET_PREFIX } from '../content/uploads.js';
|
|
11
12
|
/** The sidecar that records what was derived, beside the files it describes. */
|
|
12
13
|
export const IMAGE_RECORD_NAME = 'image.json';
|
|
@@ -43,86 +44,82 @@ export function imageMediaType(format) {
|
|
|
43
44
|
}
|
|
44
45
|
/** The public URL of one derived file, naming the original's bytes when `version` is given. */
|
|
45
46
|
export function variantUrl(source, variant, version) {
|
|
46
|
-
return versioned(`${VARIANT_ASSET_PREFIX}${source}/${variant.file}`, version);
|
|
47
|
+
return versioned(`${VARIANT_ASSET_PREFIX}${encodePath(`${source}/${variant.file}`)}`, version);
|
|
48
|
+
}
|
|
49
|
+
/** The widths kind of derived set, recorded in `image.json`. */
|
|
50
|
+
function widths(config) {
|
|
51
|
+
return {
|
|
52
|
+
sidecar: IMAGE_RECORD_NAME,
|
|
53
|
+
parse: parseRecord,
|
|
54
|
+
derive: (upload) => deriveWidths(config, upload),
|
|
55
|
+
offers: async (upload, name) => (await planWidths(config, upload))?.targets.some((target) => target.file === name) === true,
|
|
56
|
+
holds: (record, name) => record.variants.some((variant) => variant.file === name),
|
|
57
|
+
};
|
|
47
58
|
}
|
|
48
59
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* per process rather than once per request. The entry survives the sidecar
|
|
53
|
-
* being deleted on purpose: the derived directory is disposable and a request
|
|
54
|
-
* for a missing variant rebuilds it, so a page whose images have been swept
|
|
55
|
-
* away still renders the markup that asks for them back.
|
|
60
|
+
* The upload a source names and the version of its bytes, when it is one the
|
|
61
|
+
* widths can be derived from at all: GIF is not, and nor is anything that is
|
|
62
|
+
* not there.
|
|
56
63
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
function widthSource(config, source) {
|
|
65
|
+
if (!SOURCE_FORMATS.has(path.extname(source).toLowerCase()))
|
|
66
|
+
return undefined;
|
|
67
|
+
const upload = locateUpload(config, source);
|
|
68
|
+
if (upload === undefined)
|
|
69
|
+
return undefined;
|
|
70
|
+
const version = sourceVersion(config, upload.source);
|
|
71
|
+
return version === undefined ? undefined : { upload, version };
|
|
72
|
+
}
|
|
60
73
|
/**
|
|
61
|
-
* Derive every variant of one upload and record what was derived
|
|
74
|
+
* Derive every variant of one upload and record what was derived, unless the
|
|
75
|
+
* bytes it holds now have been derived already.
|
|
62
76
|
*
|
|
63
|
-
* Returns `undefined`
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* those is an error: an upload that has no variants is the ordinary case
|
|
67
|
-
* most of what a site holds, and the caller
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
77
|
+
* Returns `undefined` when optimization is off, when the file is not a raster
|
|
78
|
+
* image the CMS derives from (a GIF, a PDF, a text file), when it is animated,
|
|
79
|
+
* larger than {@link MAX_INPUT_PIXELS}, undecodable, or not there at all. None
|
|
80
|
+
* of those is an error: an upload that has no variants is the ordinary case
|
|
81
|
+
* for most of what a site holds, and the caller falls back to the original,
|
|
82
|
+
* which is what it would have served anyway. A source that could not be
|
|
83
|
+
* derived is remembered as such until its bytes change. A failure to make
|
|
84
|
+
* the directory or write a file is thrown, because it is the server failing
|
|
85
|
+
* and not the upload.
|
|
72
86
|
*
|
|
73
87
|
* Two callers asking for the same image at once share one encode.
|
|
74
88
|
*/
|
|
75
|
-
export function generateImageVariants(config, source) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
return started;
|
|
89
|
+
export async function generateImageVariants(config, source) {
|
|
90
|
+
if (!config.imageOptimization)
|
|
91
|
+
return undefined;
|
|
92
|
+
const found = widthSource(config, source);
|
|
93
|
+
if (found === undefined)
|
|
94
|
+
return undefined;
|
|
95
|
+
const kind = widths(config);
|
|
96
|
+
const known = settledSet(kind, found.upload, found.version);
|
|
97
|
+
return known === undefined ? deriveSet(kind, found.upload, found.version) : known.set;
|
|
85
98
|
}
|
|
86
99
|
/**
|
|
87
|
-
* Wait for every
|
|
100
|
+
* Wait for every derivation still running under one site's data directory.
|
|
88
101
|
*
|
|
89
102
|
* A render starts derivation in the background and returns, so an encode can
|
|
90
103
|
* outlive the request that asked for it and, without this, the site it was
|
|
91
104
|
* writing into: closing a site waits here so nothing is left writing under
|
|
92
|
-
* `dataDir` once close returns.
|
|
93
|
-
* for too. A failure is not this caller's to report; the render that started
|
|
94
|
-
* the generation already logged it.
|
|
105
|
+
* `dataDir` once close returns.
|
|
95
106
|
*/
|
|
96
107
|
export async function settleImageVariants(config) {
|
|
97
|
-
|
|
98
|
-
for (;;) {
|
|
99
|
-
const running = [...generating]
|
|
100
|
-
.filter(([directory]) => directory.startsWith(root))
|
|
101
|
-
.map(([, generation]) => generation);
|
|
102
|
-
if (running.length === 0)
|
|
103
|
-
return;
|
|
104
|
-
await Promise.allSettled(running);
|
|
105
|
-
}
|
|
108
|
+
await settleDerivedSets(config.dataDir);
|
|
106
109
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (file === undefined)
|
|
110
|
+
/**
|
|
111
|
+
* What would be derived from one upload, read off its header alone, or
|
|
112
|
+
* `undefined` when nothing would.
|
|
113
|
+
*/
|
|
114
|
+
async function planWidths(config, upload) {
|
|
115
|
+
const format = SOURCE_FORMATS.get(path.extname(upload.source).toLowerCase());
|
|
116
|
+
if (format === undefined)
|
|
115
117
|
return undefined;
|
|
116
118
|
let modified;
|
|
117
|
-
try {
|
|
118
|
-
modified = Math.trunc(statSync(file).mtimeMs);
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
119
|
let metadata;
|
|
124
120
|
try {
|
|
125
|
-
|
|
121
|
+
modified = Math.trunc(statSync(upload.file).mtimeMs);
|
|
122
|
+
metadata = await sharp(upload.file, DECODE_OPTIONS).metadata();
|
|
126
123
|
}
|
|
127
124
|
catch {
|
|
128
125
|
return undefined;
|
|
@@ -130,6 +127,8 @@ async function derive(config, source, directory) {
|
|
|
130
127
|
const stored = { width: metadata.width, height: metadata.height };
|
|
131
128
|
if (stored.width === undefined || stored.height === undefined)
|
|
132
129
|
return undefined;
|
|
130
|
+
if (!decodable({ width: stored.width, height: stored.height }))
|
|
131
|
+
return undefined;
|
|
133
132
|
// An animated WebP or AVIF is the GIF case wearing another extension: sharp
|
|
134
133
|
// would flatten it to its first frame, which is not what anybody uploaded.
|
|
135
134
|
if ((metadata.pages ?? 1) > 1)
|
|
@@ -141,24 +140,44 @@ async function derive(config, source, directory) {
|
|
|
141
140
|
const upright = (metadata.orientation ?? 1) >= 5;
|
|
142
141
|
const width = upright ? stored.height : stored.width;
|
|
143
142
|
const height = upright ? stored.width : stored.height;
|
|
143
|
+
const targets = outputFormats(config, format).flatMap((output) => outputWidths(config, output, width, height).map((target) => ({
|
|
144
|
+
format: output,
|
|
145
|
+
width: target,
|
|
146
|
+
file: `${String(target)}${FORMAT_EXTENSIONS.get(output) ?? '.bin'}`,
|
|
147
|
+
})));
|
|
148
|
+
return { width, height, format, sourceModified: modified, targets };
|
|
149
|
+
}
|
|
150
|
+
async function deriveWidths(config, upload) {
|
|
151
|
+
const plan = await planWidths(config, upload);
|
|
152
|
+
if (plan === undefined)
|
|
153
|
+
return undefined;
|
|
154
|
+
await mkdir(upload.directory, { recursive: true });
|
|
144
155
|
const variants = [];
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
156
|
+
for (const target of plan.targets) {
|
|
157
|
+
let encoded;
|
|
158
|
+
try {
|
|
159
|
+
encoded = await encode(upload.file, target);
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
console.warn(`Could not derive image variants for ${upload.source}: ${messageOf(error)}`);
|
|
163
|
+
return undefined;
|
|
149
164
|
}
|
|
165
|
+
await writeFileAtomically(path.join(upload.directory, target.file), encoded.data);
|
|
166
|
+
variants.push({
|
|
167
|
+
width: encoded.info.width,
|
|
168
|
+
height: encoded.info.height,
|
|
169
|
+
format: target.format,
|
|
170
|
+
file: target.file,
|
|
171
|
+
});
|
|
150
172
|
}
|
|
151
|
-
|
|
152
|
-
source,
|
|
153
|
-
width,
|
|
154
|
-
height,
|
|
155
|
-
format:
|
|
156
|
-
sourceModified:
|
|
173
|
+
return {
|
|
174
|
+
source: upload.source,
|
|
175
|
+
width: plan.width,
|
|
176
|
+
height: plan.height,
|
|
177
|
+
format: plan.format,
|
|
178
|
+
sourceModified: plan.sourceModified,
|
|
157
179
|
variants,
|
|
158
180
|
};
|
|
159
|
-
await writeFileAtomically(path.join(directory, IMAGE_RECORD_NAME), `${JSON.stringify(record)}\n`);
|
|
160
|
-
records.set(directory, record);
|
|
161
|
-
return record;
|
|
162
181
|
}
|
|
163
182
|
/**
|
|
164
183
|
* The formats to write: the site's, then the original's own.
|
|
@@ -171,38 +190,40 @@ function outputFormats(config, sourceFormat) {
|
|
|
171
190
|
const formats = config.imageFormats.filter((format) => format !== sourceFormat);
|
|
172
191
|
return [...formats, sourceFormat];
|
|
173
192
|
}
|
|
193
|
+
/** The largest width or height each encoder can write. PNG has no such limit. */
|
|
194
|
+
const FORMAT_MAX_DIMENSIONS = new Map([
|
|
195
|
+
['avif', 16384],
|
|
196
|
+
['jpeg', 65500],
|
|
197
|
+
['webp', 16383],
|
|
198
|
+
]);
|
|
174
199
|
/**
|
|
175
|
-
* The widths to write: the configured ones narrower than the
|
|
176
|
-
* original's own width.
|
|
200
|
+
* The widths to write in one format: the configured ones narrower than the
|
|
201
|
+
* original, and the original's own width, or as near it as the format can go.
|
|
177
202
|
*
|
|
178
203
|
* Nothing is ever upscaled — a browser given a blown-up copy pays for pixels
|
|
179
204
|
* that carry no detail — and the full size is always there, so a wide display
|
|
180
|
-
* has something to pick that is not the unoptimised original.
|
|
205
|
+
* has something to pick that is not the unoptimised original. A panorama
|
|
206
|
+
* wider or taller than the encoder allows gets its widest copy at the limit.
|
|
181
207
|
*/
|
|
182
|
-
function outputWidths(config, width) {
|
|
183
|
-
const
|
|
184
|
-
|
|
208
|
+
function outputWidths(config, format, width, height) {
|
|
209
|
+
const limit = FORMAT_MAX_DIMENSIONS.get(format) ?? Infinity;
|
|
210
|
+
const widest = Math.min(width, limit, Math.floor((width * limit) / height));
|
|
211
|
+
if (widest < 1)
|
|
212
|
+
return [];
|
|
213
|
+
const widths = new Set(config.imageWidths.filter((candidate) => candidate < widest));
|
|
214
|
+
widths.add(widest);
|
|
185
215
|
return [...widths].sort((a, b) => a - b);
|
|
186
216
|
}
|
|
187
|
-
/**
|
|
188
|
-
async function encode(
|
|
189
|
-
const extension = FORMAT_EXTENSIONS.get(input.format) ?? '.bin';
|
|
190
|
-
const name = `${String(input.width)}${extension}`;
|
|
217
|
+
/** Encode one variant. A throw here is sharp failing on the source's pixels. */
|
|
218
|
+
async function encode(file, target) {
|
|
191
219
|
// `autoOrient` applies the EXIF rotation, and sharp drops metadata unless
|
|
192
220
|
// asked to keep it, so the variant comes out the right way up and carrying
|
|
193
221
|
// no camera, no timestamp and no location.
|
|
194
|
-
const pipeline = sharp(
|
|
195
|
-
width:
|
|
222
|
+
const pipeline = sharp(file, DECODE_OPTIONS).resize({
|
|
223
|
+
width: target.width,
|
|
196
224
|
withoutEnlargement: true,
|
|
197
225
|
});
|
|
198
|
-
|
|
199
|
-
await writeFileAtomically(path.join(input.directory, name), encoded.data);
|
|
200
|
-
return {
|
|
201
|
-
width: encoded.info.width,
|
|
202
|
-
height: encoded.info.height,
|
|
203
|
-
format: input.format,
|
|
204
|
-
file: name,
|
|
205
|
-
};
|
|
226
|
+
return formatted(pipeline, target.format).toBuffer({ resolveWithObject: true });
|
|
206
227
|
}
|
|
207
228
|
/** The encoder for one format, at settings that trade a little fidelity for a lot of bytes. */
|
|
208
229
|
function formatted(pipeline, format) {
|
|
@@ -222,54 +243,21 @@ function formatted(pipeline, format) {
|
|
|
222
243
|
*
|
|
223
244
|
* Synchronous and cached, because it is called once per image while a page
|
|
224
245
|
* renders. `undefined` means the caller should serve the plain original: the
|
|
225
|
-
* upload is not an image,
|
|
246
|
+
* upload is not an image, nothing has been derived from the bytes it holds
|
|
247
|
+
* now, or nothing could be.
|
|
226
248
|
*/
|
|
227
249
|
export function describeImage(config, source) {
|
|
228
|
-
const
|
|
229
|
-
if (
|
|
230
|
-
return undefined;
|
|
231
|
-
let record = records.get(directory);
|
|
232
|
-
if (record === undefined) {
|
|
233
|
-
record = readRecord(path.join(directory, IMAGE_RECORD_NAME), source);
|
|
234
|
-
if (record === undefined)
|
|
235
|
-
return undefined;
|
|
236
|
-
records.set(directory, record);
|
|
237
|
-
}
|
|
238
|
-
if (!current(config, record))
|
|
250
|
+
const found = widthSource(config, source);
|
|
251
|
+
if (found === undefined)
|
|
239
252
|
return undefined;
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Whether a record still describes the file it was derived from.
|
|
244
|
-
*
|
|
245
|
-
* The original having gone, or having been replaced under the same name,
|
|
246
|
-
* makes the record rubbish; anything else — including the whole derived
|
|
247
|
-
* directory having been swept away — leaves it true, which is what lets a page
|
|
248
|
-
* keep rendering the markup that asks for the variants back.
|
|
249
|
-
*/
|
|
250
|
-
function current(config, record) {
|
|
251
|
-
const file = sourceFile(config, record.source);
|
|
252
|
-
if (file === undefined)
|
|
253
|
-
return false;
|
|
254
|
-
try {
|
|
255
|
-
return Math.trunc(statSync(file).mtimeMs) === record.sourceModified;
|
|
256
|
-
}
|
|
257
|
-
catch {
|
|
258
|
-
return false;
|
|
259
|
-
}
|
|
253
|
+
const record = settledSet(widths(config), found.upload, found.version)?.set;
|
|
254
|
+
return record === undefined ? undefined : { ...record, version: found.version };
|
|
260
255
|
}
|
|
261
|
-
/** Parse one sidecar, refusing anything that is not the shape it should be. */
|
|
262
|
-
function
|
|
263
|
-
|
|
264
|
-
try {
|
|
265
|
-
parsed = JSON.parse(readFileSync(file, 'utf8'));
|
|
266
|
-
}
|
|
267
|
-
catch {
|
|
268
|
-
return undefined;
|
|
269
|
-
}
|
|
270
|
-
if (typeof parsed !== 'object' || parsed === null)
|
|
256
|
+
/** Parse one sidecar's record, refusing anything that is not the shape it should be. */
|
|
257
|
+
function parseRecord(value, upload) {
|
|
258
|
+
if (typeof value !== 'object' || value === null)
|
|
271
259
|
return undefined;
|
|
272
|
-
const candidate =
|
|
260
|
+
const candidate = value;
|
|
273
261
|
if (typeof candidate.width !== 'number' ||
|
|
274
262
|
typeof candidate.height !== 'number' ||
|
|
275
263
|
typeof candidate.format !== 'string' ||
|
|
@@ -278,7 +266,7 @@ function readRecord(file, source) {
|
|
|
278
266
|
return undefined;
|
|
279
267
|
}
|
|
280
268
|
return {
|
|
281
|
-
source,
|
|
269
|
+
source: upload.source,
|
|
282
270
|
width: candidate.width,
|
|
283
271
|
height: candidate.height,
|
|
284
272
|
format: candidate.format,
|
|
@@ -290,18 +278,18 @@ function readRecord(file, source) {
|
|
|
290
278
|
};
|
|
291
279
|
}
|
|
292
280
|
/**
|
|
293
|
-
* Take one upload's derived files away
|
|
281
|
+
* Take one upload's derived files away, once any derivation writing them has
|
|
282
|
+
* finished.
|
|
294
283
|
*
|
|
295
284
|
* Forgiving by design: an upload with nothing derived from it is the ordinary
|
|
296
285
|
* case, and this runs after the original has already gone, so refusing to
|
|
297
286
|
* finish would leave the site worse than it found it.
|
|
298
287
|
*/
|
|
299
288
|
export async function removeImageVariants(config, source) {
|
|
300
|
-
const
|
|
301
|
-
if (
|
|
289
|
+
const upload = locateUpload(config, source);
|
|
290
|
+
if (upload === undefined)
|
|
302
291
|
return;
|
|
303
|
-
|
|
304
|
-
await rm(directory, { recursive: true, force: true });
|
|
292
|
+
await forgetDerivedSets(upload);
|
|
305
293
|
}
|
|
306
294
|
/**
|
|
307
295
|
* Find one derived file by its request path, generating it if it is not there.
|
|
@@ -311,34 +299,35 @@ export async function removeImageVariants(config, source) {
|
|
|
311
299
|
* rebuilds the whole set for that source and then serves it, which is what
|
|
312
300
|
* makes the derived directory disposable, as everything derived must be. A
|
|
313
301
|
* request for a width or a format the site does not offer is a 404 and encodes
|
|
314
|
-
* nothing, so nobody can make the server work by asking for sizes.
|
|
302
|
+
* nothing, so nobody can make the server work by asking for sizes. An icon
|
|
303
|
+
* name is answered only under `iconSource`, the site icon's upload. A file
|
|
304
|
+
* whose upload has gone is answered with nothing and removed.
|
|
305
|
+
*
|
|
306
|
+
* The file comes back with the version of the bytes it was derived from, and
|
|
307
|
+
* a set derived from older bytes is derived again first.
|
|
315
308
|
*/
|
|
316
|
-
export async function findImageVariant(config, relative) {
|
|
317
|
-
|
|
318
|
-
const found = findAsset(relative, [root]);
|
|
319
|
-
if (found !== undefined)
|
|
320
|
-
return found;
|
|
321
|
-
if (!config.imageOptimization)
|
|
309
|
+
export async function findImageVariant(config, relative, iconSource) {
|
|
310
|
+
if (!config.imageOptimization || plainRelativePath(relative) === undefined)
|
|
322
311
|
return undefined;
|
|
323
312
|
const cut = relative.lastIndexOf('/');
|
|
324
313
|
if (cut <= 0)
|
|
325
314
|
return undefined;
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
// The site's icons live beside the widths and are derived one at a time,
|
|
329
|
-
// because they are asked for one at a time and belong in no `srcset`.
|
|
330
|
-
if (isDerivedIcon(name)) {
|
|
331
|
-
return (await deriveSiteIcon(config, source, name)) ? findAsset(relative, [root]) : undefined;
|
|
332
|
-
}
|
|
333
|
-
const known = describeImage(config, source);
|
|
334
|
-
if (known !== undefined && !known.variants.some((variant) => variant.file === name)) {
|
|
315
|
+
const upload = locateUpload(config, relative.slice(0, cut));
|
|
316
|
+
if (upload === undefined)
|
|
335
317
|
return undefined;
|
|
336
|
-
|
|
337
|
-
const
|
|
338
|
-
if (
|
|
318
|
+
const name = relative.slice(cut + 1);
|
|
319
|
+
const version = sourceVersion(config, upload.source);
|
|
320
|
+
if (version === undefined) {
|
|
321
|
+
await forgetDerivedSets(upload);
|
|
339
322
|
return undefined;
|
|
340
323
|
}
|
|
341
|
-
|
|
324
|
+
const icon = iconSource === undefined ? undefined : locateUpload(config, iconSource);
|
|
325
|
+
const asset = !isDerivedIcon(name)
|
|
326
|
+
? await findDerivedFile(widths(config), upload, version, name)
|
|
327
|
+
: icon?.source === upload.source
|
|
328
|
+
? await findDerivedFile(SITE_ICONS, upload, version, name)
|
|
329
|
+
: undefined;
|
|
330
|
+
return asset === undefined ? undefined : { ...asset, version };
|
|
342
331
|
}
|
|
343
332
|
const THUMBNAIL_WIDTH = 400;
|
|
344
333
|
export function thumbnailUrl(config, source, url) {
|
|
@@ -347,7 +336,7 @@ export function thumbnailUrl(config, source, url) {
|
|
|
347
336
|
.filter((variant) => variant.format === image.variants[0]?.format)
|
|
348
337
|
.find((variant) => variant.width >= THUMBNAIL_WIDTH);
|
|
349
338
|
return image !== undefined && thumbnail !== undefined
|
|
350
|
-
? variantUrl(source, thumbnail, image.version)
|
|
339
|
+
? variantUrl(image.source, thumbnail, image.version)
|
|
351
340
|
: url;
|
|
352
341
|
}
|
|
353
342
|
//# sourceMappingURL=variants.js.map
|