@kensio/colophon 2.1.0 → 2.3.0
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/README.md +608 -34
- package/dist/cli/args.d.ts +14 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +67 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/config.d.ts +12 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +43 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +35 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli.js +34 -6
- package/dist/cli.js.map +1 -1
- package/dist/config/defaults.d.ts +64 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +64 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/index.d.ts +22 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +52 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/resolve.d.ts +24 -0
- package/dist/config/resolve.d.ts.map +1 -0
- package/dist/config/resolve.js +66 -0
- package/dist/config/resolve.js.map +1 -0
- package/dist/config/size.d.ts +20 -0
- package/dist/config/size.d.ts.map +1 -0
- package/dist/config/size.js +46 -0
- package/dist/config/size.js.map +1 -0
- package/dist/config.d.ts +33 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +94 -4
- package/dist/config.js.map +1 -1
- package/dist/content/index.d.ts +5 -51
- package/dist/content/index.d.ts.map +1 -1
- package/dist/content/index.js +3 -115
- package/dist/content/index.js.map +1 -1
- package/dist/content/props.d.ts +15 -0
- package/dist/content/props.d.ts.map +1 -0
- package/dist/content/props.js +71 -0
- package/dist/content/props.js.map +1 -0
- package/dist/content/slug.d.ts +23 -0
- package/dist/content/slug.d.ts.map +1 -0
- package/dist/content/slug.js +52 -0
- package/dist/content/slug.js.map +1 -0
- package/dist/content/walk.d.ts +17 -0
- package/dist/content/walk.d.ts.map +1 -0
- package/dist/content/walk.js +57 -0
- package/dist/content/walk.js.map +1 -0
- package/dist/fonts/index.d.ts +10 -0
- package/dist/fonts/index.d.ts.map +1 -0
- package/dist/fonts/index.js +11 -0
- package/dist/fonts/index.js.map +1 -0
- package/dist/fonts/materialise.d.ts +7 -0
- package/dist/fonts/materialise.d.ts.map +1 -0
- package/dist/fonts/materialise.js +47 -0
- package/dist/fonts/materialise.js.map +1 -0
- package/dist/fonts/resolve.d.ts +7 -0
- package/dist/fonts/resolve.d.ts.map +1 -0
- package/dist/fonts/resolve.js +50 -0
- package/dist/fonts/resolve.js.map +1 -0
- package/dist/fonts.d.ts +18 -0
- package/dist/fonts.d.ts.map +1 -0
- package/dist/fonts.js +102 -0
- package/dist/fonts.js.map +1 -0
- package/dist/generate/extra.d.ts +16 -0
- package/dist/generate/extra.d.ts.map +1 -0
- package/dist/generate/extra.js +60 -0
- package/dist/generate/extra.js.map +1 -0
- package/dist/generate/index.d.ts +19 -0
- package/dist/generate/index.d.ts.map +1 -0
- package/dist/generate/index.js +46 -0
- package/dist/generate/index.js.map +1 -0
- package/dist/generate/job.d.ts +35 -0
- package/dist/generate/job.d.ts.map +1 -0
- package/dist/generate/job.js +2 -0
- package/dist/generate/job.js.map +1 -0
- package/dist/generate/options.d.ts +56 -0
- package/dist/generate/options.d.ts.map +1 -0
- package/dist/generate/options.js +17 -0
- package/dist/generate/options.js.map +1 -0
- package/dist/generate/output-path.d.ts +12 -0
- package/dist/generate/output-path.d.ts.map +1 -0
- package/dist/generate/output-path.js +18 -0
- package/dist/generate/output-path.js.map +1 -0
- package/dist/generate/outputs.d.ts +28 -0
- package/dist/generate/outputs.d.ts.map +1 -0
- package/dist/generate/outputs.js +71 -0
- package/dist/generate/outputs.js.map +1 -0
- package/dist/generate/plan.d.ts +21 -0
- package/dist/generate/plan.d.ts.map +1 -0
- package/dist/generate/plan.js +72 -0
- package/dist/generate/plan.js.map +1 -0
- package/dist/generate/render-image.d.ts +11 -0
- package/dist/generate/render-image.d.ts.map +1 -0
- package/dist/generate/render-image.js +27 -0
- package/dist/generate/render-image.js.map +1 -0
- package/dist/generate.d.ts +27 -6
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +77 -15
- package/dist/generate.js.map +1 -1
- package/dist/highlight/color.d.ts +9 -0
- package/dist/highlight/color.d.ts.map +1 -0
- package/dist/highlight/color.js +15 -0
- package/dist/highlight/color.js.map +1 -0
- package/dist/highlight/grid.d.ts +14 -0
- package/dist/highlight/grid.d.ts.map +1 -0
- package/dist/highlight/grid.js +36 -0
- package/dist/highlight/grid.js.map +1 -0
- package/dist/highlight/index.d.ts +12 -0
- package/dist/highlight/index.d.ts.map +1 -0
- package/dist/highlight/index.js +31 -0
- package/dist/highlight/index.js.map +1 -0
- package/dist/highlight/language.d.ts +14 -0
- package/dist/highlight/language.d.ts.map +1 -0
- package/dist/highlight/language.js +42 -0
- package/dist/highlight/language.js.map +1 -0
- package/dist/highlight/normalise.d.ts +17 -0
- package/dist/highlight/normalise.d.ts.map +1 -0
- package/dist/highlight/normalise.js +37 -0
- package/dist/highlight/normalise.js.map +1 -0
- package/dist/highlight/types.d.ts +40 -0
- package/dist/highlight/types.d.ts.map +1 -0
- package/dist/highlight/types.js +2 -0
- package/dist/highlight/types.js.map +1 -0
- package/dist/highlight.d.ts +10 -0
- package/dist/highlight.d.ts.map +1 -1
- package/dist/highlight.js +25 -2
- package/dist/highlight.js.map +1 -1
- package/dist/index.d.ts +15 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/manifest/build.d.ts +14 -0
- package/dist/manifest/build.d.ts.map +1 -0
- package/dist/manifest/build.js +43 -0
- package/dist/manifest/build.js.map +1 -0
- package/dist/manifest/index.d.ts +27 -0
- package/dist/manifest/index.d.ts.map +1 -0
- package/dist/manifest/index.js +31 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/order.d.ts +12 -0
- package/dist/manifest/order.d.ts.map +1 -0
- package/dist/manifest/order.js +17 -0
- package/dist/manifest/order.js.map +1 -0
- package/dist/manifest/page.d.ts +24 -0
- package/dist/manifest/page.d.ts.map +1 -0
- package/dist/manifest/page.js +55 -0
- package/dist/manifest/page.js.map +1 -0
- package/dist/meta/html.d.ts +14 -0
- package/dist/meta/html.d.ts.map +1 -0
- package/dist/meta/html.js +24 -0
- package/dist/meta/html.js.map +1 -0
- package/dist/meta/index.d.ts +11 -0
- package/dist/meta/index.d.ts.map +1 -0
- package/dist/meta/index.js +11 -0
- package/dist/meta/index.js.map +1 -0
- package/dist/meta/tags.d.ts +21 -0
- package/dist/meta/tags.d.ts.map +1 -0
- package/dist/meta/tags.js +72 -0
- package/dist/meta/tags.js.map +1 -0
- package/dist/meta/url.d.ts +15 -0
- package/dist/meta/url.d.ts.map +1 -0
- package/dist/meta/url.js +34 -0
- package/dist/meta/url.js.map +1 -0
- package/dist/placement/check.d.ts +16 -0
- package/dist/placement/check.d.ts.map +1 -0
- package/dist/placement/check.js +40 -0
- package/dist/placement/check.js.map +1 -0
- package/dist/placement/index.d.ts +29 -0
- package/dist/placement/index.d.ts.map +1 -0
- package/dist/placement/index.js +61 -0
- package/dist/placement/index.js.map +1 -0
- package/dist/placement/relative.d.ts +31 -0
- package/dist/placement/relative.d.ts.map +1 -0
- package/dist/placement/relative.js +53 -0
- package/dist/placement/relative.js.map +1 -0
- package/dist/pool.d.ts +18 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/pool.js +56 -0
- package/dist/pool.js.map +1 -0
- package/dist/render/index.d.ts +10 -0
- package/dist/render/index.d.ts.map +1 -0
- package/dist/render/index.js +27 -0
- package/dist/render/index.js.map +1 -0
- package/dist/render/png.d.ts +10 -0
- package/dist/render/png.d.ts.map +1 -0
- package/dist/render/png.js +30 -0
- package/dist/render/png.js.map +1 -0
- package/dist/render/svg.d.ts +10 -0
- package/dist/render/svg.d.ts.map +1 -0
- package/dist/render/svg.js +20 -0
- package/dist/render/svg.js.map +1 -0
- package/dist/render/template.d.ts +9 -0
- package/dist/render/template.d.ts.map +1 -0
- package/dist/render/template.js +17 -0
- package/dist/render/template.js.map +1 -0
- package/dist/render.d.ts +6 -2
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +31 -10
- package/dist/render.js.map +1 -1
- package/dist/stamp/chunk.d.ts +16 -0
- package/dist/stamp/chunk.d.ts.map +1 -0
- package/dist/stamp/chunk.js +46 -0
- package/dist/stamp/chunk.js.map +1 -0
- package/dist/stamp/config-digest.d.ts +11 -0
- package/dist/stamp/config-digest.d.ts.map +1 -0
- package/dist/stamp/config-digest.js +43 -0
- package/dist/stamp/config-digest.js.map +1 -0
- package/dist/stamp/digest.d.ts +8 -0
- package/dist/stamp/digest.d.ts.map +1 -0
- package/dist/stamp/digest.js +20 -0
- package/dist/stamp/digest.js.map +1 -0
- package/dist/stamp/index.d.ts +20 -0
- package/dist/stamp/index.d.ts.map +1 -0
- package/dist/stamp/index.js +40 -0
- package/dist/stamp/index.js.map +1 -0
- package/dist/stamp/read.d.ts +7 -0
- package/dist/stamp/read.d.ts.map +1 -0
- package/dist/stamp/read.js +62 -0
- package/dist/stamp/read.js.map +1 -0
- package/dist/stamp.d.ts +29 -0
- package/dist/stamp.d.ts.map +1 -0
- package/dist/stamp.js +198 -0
- package/dist/stamp.js.map +1 -0
- package/dist/templates/banner/badge.d.ts +7 -0
- package/dist/templates/banner/badge.d.ts.map +1 -0
- package/dist/templates/banner/badge.js +24 -0
- package/dist/templates/banner/badge.js.map +1 -0
- package/dist/templates/banner/index.d.ts +9 -0
- package/dist/templates/banner/index.d.ts.map +1 -0
- package/dist/templates/banner/index.js +66 -0
- package/dist/templates/banner/index.js.map +1 -0
- package/dist/templates/banner/lines.d.ts +27 -0
- package/dist/templates/banner/lines.d.ts.map +1 -0
- package/dist/templates/banner/lines.js +46 -0
- package/dist/templates/banner/lines.js.map +1 -0
- package/dist/templates/card/index.d.ts +7 -0
- package/dist/templates/card/index.d.ts.map +1 -0
- package/dist/templates/card/index.js +43 -0
- package/dist/templates/card/index.js.map +1 -0
- package/dist/templates/card/lines.d.ts +17 -0
- package/dist/templates/card/lines.d.ts.map +1 -0
- package/dist/templates/card/lines.js +32 -0
- package/dist/templates/card/lines.js.map +1 -0
- package/dist/templates/code/chrome.d.ts +9 -0
- package/dist/templates/code/chrome.d.ts.map +1 -0
- package/dist/templates/code/chrome.js +32 -0
- package/dist/templates/code/chrome.js.map +1 -0
- package/dist/templates/code/clip.d.ts +18 -0
- package/dist/templates/code/clip.d.ts.map +1 -0
- package/dist/templates/code/clip.js +44 -0
- package/dist/templates/code/clip.js.map +1 -0
- package/dist/templates/code/ellipsis.d.ts +3 -0
- package/dist/templates/code/ellipsis.d.ts.map +1 -0
- package/dist/templates/code/ellipsis.js +3 -0
- package/dist/templates/code/ellipsis.js.map +1 -0
- package/dist/templates/code/fit.d.ts +27 -0
- package/dist/templates/code/fit.d.ts.map +1 -0
- package/dist/templates/code/fit.js +59 -0
- package/dist/templates/code/fit.js.map +1 -0
- package/dist/templates/code/index.d.ts +12 -0
- package/dist/templates/code/index.d.ts.map +1 -0
- package/dist/templates/code/index.js +64 -0
- package/dist/templates/code/index.js.map +1 -0
- package/dist/templates/code/layout.d.ts +21 -0
- package/dist/templates/code/layout.d.ts.map +1 -0
- package/dist/templates/code/layout.js +21 -0
- package/dist/templates/code/layout.js.map +1 -0
- package/dist/templates/code/panel.d.ts +17 -0
- package/dist/templates/code/panel.d.ts.map +1 -0
- package/dist/templates/code/panel.js +20 -0
- package/dist/templates/code/panel.js.map +1 -0
- package/dist/templates/code/plate.d.ts +15 -0
- package/dist/templates/code/plate.d.ts.map +1 -0
- package/dist/templates/code/plate.js +32 -0
- package/dist/templates/code/plate.js.map +1 -0
- package/dist/templates/code/spans.d.ts +19 -0
- package/dist/templates/code/spans.d.ts.map +1 -0
- package/dist/templates/code/spans.js +36 -0
- package/dist/templates/code/spans.js.map +1 -0
- package/dist/templates/code/warn.d.ts +11 -0
- package/dist/templates/code/warn.d.ts.map +1 -0
- package/dist/templates/code/warn.js +24 -0
- package/dist/templates/code/warn.js.map +1 -0
- package/dist/templates/code.d.ts.map +1 -1
- package/dist/templates/code.js +101 -29
- package/dist/templates/code.js.map +1 -1
- package/dist/templates/footer.d.ts +21 -0
- package/dist/templates/footer.d.ts.map +1 -0
- package/dist/templates/footer.js +25 -0
- package/dist/templates/footer.js.map +1 -0
- package/dist/templates/index.d.ts +3 -3
- package/dist/templates/index.d.ts.map +1 -1
- package/dist/templates/index.js +6 -6
- package/dist/templates/index.js.map +1 -1
- package/dist/text/element.d.ts +18 -0
- package/dist/text/element.d.ts.map +1 -0
- package/dist/text/element.js +19 -0
- package/dist/text/element.js.map +1 -0
- package/dist/text/escape.d.ts +5 -0
- package/dist/text/escape.d.ts.map +1 -0
- package/dist/text/escape.js +12 -0
- package/dist/text/escape.js.map +1 -0
- package/dist/text/index.d.ts +7 -0
- package/dist/text/index.d.ts.map +1 -0
- package/dist/text/index.js +5 -0
- package/dist/text/index.js.map +1 -0
- package/dist/text/stack.d.ts +24 -0
- package/dist/text/stack.d.ts.map +1 -0
- package/dist/text/stack.js +18 -0
- package/dist/text/stack.js.map +1 -0
- package/dist/text/wrap.d.ts +12 -0
- package/dist/text/wrap.d.ts.map +1 -0
- package/dist/text/wrap.js +33 -0
- package/dist/text/wrap.js.map +1 -0
- package/dist/types.d.ts +345 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/validate/check.d.ts +13 -0
- package/dist/validate/check.d.ts.map +1 -0
- package/dist/validate/check.js +34 -0
- package/dist/validate/check.js.map +1 -0
- package/dist/validate/index.d.ts +15 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/dist/validate/index.js +41 -0
- package/dist/validate/index.js.map +1 -0
- package/dist/validate/keys.d.ts +58 -0
- package/dist/validate/keys.d.ts.map +1 -0
- package/dist/validate/keys.js +166 -0
- package/dist/validate/keys.js.map +1 -0
- package/dist/validate/overrides.d.ts +5 -0
- package/dist/validate/overrides.d.ts.map +1 -0
- package/dist/validate/overrides.js +43 -0
- package/dist/validate/overrides.js.map +1 -0
- package/dist/validate/placement.d.ts +10 -0
- package/dist/validate/placement.d.ts.map +1 -0
- package/dist/validate/placement.js +38 -0
- package/dist/validate/placement.js.map +1 -0
- package/dist/validate/sizes.d.ts +9 -0
- package/dist/validate/sizes.d.ts.map +1 -0
- package/dist/validate/sizes.js +27 -0
- package/dist/validate/sizes.js.map +1 -0
- package/dist/validate/suggest.d.ts +10 -0
- package/dist/validate/suggest.d.ts.map +1 -0
- package/dist/validate/suggest.js +55 -0
- package/dist/validate/suggest.js.map +1 -0
- package/dist/validate/values.d.ts +21 -0
- package/dist/validate/values.d.ts.map +1 -0
- package/dist/validate/values.js +57 -0
- package/dist/validate/values.js.map +1 -0
- package/dist/validate.d.ts +15 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +300 -0
- package/dist/validate.js.map +1 -0
- package/package.json +14 -7
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ColophonConfig, OutputSize, ResolvedConfig } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Apply a size's own overrides to a config and resolve the result: the config
|
|
4
|
+
* one image is actually rendered with.
|
|
5
|
+
*
|
|
6
|
+
* The overrides are folded into the user config and the whole thing resolved
|
|
7
|
+
* again, rather than patched onto an already-resolved config, so that anything
|
|
8
|
+
* derived stays consistent — a size that overrides `colors.brand` gets the
|
|
9
|
+
* default gradient rebuilt around its brand, exactly as a config setting the
|
|
10
|
+
* same colour at the top level would.
|
|
11
|
+
*
|
|
12
|
+
* `colors` and `code` merge over their config-level counterparts, because both
|
|
13
|
+
* are bags of independent settings and the point of the feature is to change
|
|
14
|
+
* one of them. The rest replace: a `background` is a union whose variants have
|
|
15
|
+
* different keys, so half of one over half of another is not a background at
|
|
16
|
+
* all, and `badge` carries a required `text` that a partial override could not
|
|
17
|
+
* supply.
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveConfigForSize(config: ColophonConfig | undefined, size: OutputSize): ResolvedConfig;
|
|
20
|
+
//# sourceMappingURL=size.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size.d.ts","sourceRoot":"","sources":["../../src/config/size.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,cAAc,EACd,UAAU,EACV,cAAc,EACf,MAAM,aAAa,CAAC;AAoBrB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,cAAc,GAAG,SAAS,EAClC,IAAI,EAAE,UAAU,GACf,cAAc,CAchB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { DEFAULT_COLORS } from "./defaults.js";
|
|
2
|
+
import { resolveConfig } from "./index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Merge a size's colour overrides onto the config's.
|
|
5
|
+
*
|
|
6
|
+
* A size may name any single shade, so the merge starts from the full default
|
|
7
|
+
* palette when the config sets no colours of its own. Starting from nothing
|
|
8
|
+
* instead would hand `resolveColors` a lone `foreground`, and its rule that a
|
|
9
|
+
* bare `brand` colours the whole gradient would then flatten the default
|
|
10
|
+
* gradient — a size asking only for darker text would silently lose it.
|
|
11
|
+
*/
|
|
12
|
+
function mergeColors(base, overrides) {
|
|
13
|
+
return { ...(base ?? DEFAULT_COLORS), ...overrides };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Apply a size's own overrides to a config and resolve the result: the config
|
|
17
|
+
* one image is actually rendered with.
|
|
18
|
+
*
|
|
19
|
+
* The overrides are folded into the user config and the whole thing resolved
|
|
20
|
+
* again, rather than patched onto an already-resolved config, so that anything
|
|
21
|
+
* derived stays consistent — a size that overrides `colors.brand` gets the
|
|
22
|
+
* default gradient rebuilt around its brand, exactly as a config setting the
|
|
23
|
+
* same colour at the top level would.
|
|
24
|
+
*
|
|
25
|
+
* `colors` and `code` merge over their config-level counterparts, because both
|
|
26
|
+
* are bags of independent settings and the point of the feature is to change
|
|
27
|
+
* one of them. The rest replace: a `background` is a union whose variants have
|
|
28
|
+
* different keys, so half of one over half of another is not a background at
|
|
29
|
+
* all, and `badge` carries a required `text` that a partial override could not
|
|
30
|
+
* supply.
|
|
31
|
+
*/
|
|
32
|
+
export function resolveConfigForSize(config, size) {
|
|
33
|
+
const base = config ?? {};
|
|
34
|
+
return resolveConfig({
|
|
35
|
+
...base,
|
|
36
|
+
...(size.colors !== undefined && {
|
|
37
|
+
colors: mergeColors(base.colors, size.colors),
|
|
38
|
+
}),
|
|
39
|
+
...(size.code !== undefined && { code: { ...base.code, ...size.code } }),
|
|
40
|
+
...(size.background !== undefined && { background: size.background }),
|
|
41
|
+
...(size.fontFamily !== undefined && { fontFamily: size.fontFamily }),
|
|
42
|
+
...(size.footer !== undefined && { footer: size.footer }),
|
|
43
|
+
...(size.badge !== undefined && { badge: size.badge }),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=size.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size.js","sourceRoot":"","sources":["../../src/config/size.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;GAQG;AACH,SAAS,WAAW,CAClB,IAA6B,EAC7B,SAA+B;IAE/B,OAAO,EAAE,GAAG,CAAC,IAAI,IAAI,cAAc,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC;AACvD,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAkC,EAClC,IAAgB;IAEhB,MAAM,IAAI,GAAG,MAAM,IAAI,EAAE,CAAC;IAE1B,OAAO,aAAa,CAAC;QACnB,GAAG,IAAI;QACP,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI;YAC/B,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;SAC9C,CAAC;QACF,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;QACxE,GAAG,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;QACrE,GAAG,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;QACrE,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;QACzD,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;KACvD,CAAC,CAAC;AACL,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -36,7 +36,11 @@ export declare const SIZE_PRESETS: {
|
|
|
36
36
|
* they satisfy `og:image` and both `twitter:image` card types.
|
|
37
37
|
*/
|
|
38
38
|
export declare const DEFAULT_SIZES: readonly OutputSize[];
|
|
39
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Default font stack, used when no fonts are configured. It names families and
|
|
41
|
+
* hopes the machine has them, which is exactly what `config.fonts` exists to
|
|
42
|
+
* avoid: supply a font file and the output stops depending on the machine.
|
|
43
|
+
*/
|
|
40
44
|
export declare const DEFAULT_FONT_FAMILY = "Arial, Helvetica, sans-serif";
|
|
41
45
|
/** Neutral default palette, used when no `colors.brand` is supplied. */
|
|
42
46
|
export declare const DEFAULT_COLORS: Required<BrandColors>;
|
|
@@ -49,7 +53,12 @@ export declare const DEFAULT_CODE_FONT_FAMILY = "\"JetBrains Mono\", \"Source Co
|
|
|
49
53
|
/**
|
|
50
54
|
* Default `code` template styling. `charWidthRatio` and `lineHeight` drive the
|
|
51
55
|
* monospace grid the snippet is laid out on; the font-size bounds are
|
|
52
|
-
* fractions of the image
|
|
56
|
+
* fractions of the image width so they hold at every output size.
|
|
57
|
+
*
|
|
58
|
+
* `minFontScale` of `0.025` is roughly 30px on a 1200px-wide image, which
|
|
59
|
+
* still reads when a feed shows that image at half size. A snippet too long to
|
|
60
|
+
* fit at that size is truncated rather than shrunk, so a long sample loses
|
|
61
|
+
* lines on the shorter landscape formats.
|
|
53
62
|
*/
|
|
54
63
|
export declare const DEFAULT_CODE_STYLE: Required<CodeStyle>;
|
|
55
64
|
/**
|
|
@@ -59,6 +68,28 @@ export declare const DEFAULT_CODE_STYLE: Required<CodeStyle>;
|
|
|
59
68
|
export declare function defineConfig(config: ColophonConfig): ColophonConfig;
|
|
60
69
|
/**
|
|
61
70
|
* Apply defaults to a user config. Safe to call with no argument.
|
|
71
|
+
*
|
|
72
|
+
* Unknown options are rejected before anything is resolved, so a config
|
|
73
|
+
* written against a different version of the package is a build error rather
|
|
74
|
+
* than a set of images quietly rendered with the defaults.
|
|
62
75
|
*/
|
|
63
76
|
export declare function resolveConfig(config?: ColophonConfig): ResolvedConfig;
|
|
77
|
+
/**
|
|
78
|
+
* Apply a size's own overrides to a config and resolve the result: the config
|
|
79
|
+
* one image is actually rendered with.
|
|
80
|
+
*
|
|
81
|
+
* The overrides are folded into the user config and the whole thing resolved
|
|
82
|
+
* again, rather than patched onto an already-resolved config, so that anything
|
|
83
|
+
* derived stays consistent — a size that overrides `colors.brand` gets the
|
|
84
|
+
* default gradient rebuilt around its brand, exactly as a config setting the
|
|
85
|
+
* same colour at the top level would.
|
|
86
|
+
*
|
|
87
|
+
* `colors` and `code` merge over their config-level counterparts, because both
|
|
88
|
+
* are bags of independent settings and the point of the feature is to change
|
|
89
|
+
* one of them. The rest replace: a `background` is a union whose variants have
|
|
90
|
+
* different keys, so half of one over half of another is not a background at
|
|
91
|
+
* all, and `badge` carries a required `text` that a partial override could not
|
|
92
|
+
* supply.
|
|
93
|
+
*/
|
|
94
|
+
export declare function resolveConfigForSize(config: ColophonConfig | undefined, size: OutputSize): ResolvedConfig;
|
|
64
95
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,WAAW,EACX,SAAS,EACT,cAAc,EAEd,UAAU,EACV,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY;;iBACjB,IAAI,EAAE,IAAI;iBAAE,KAAK,EAAE,IAAI;iBAAE,MAAM,EAAE,GAAG;;;iBAChC,IAAI,EAAE,QAAQ;iBAAE,KAAK,EAAE,IAAI;iBAAE,MAAM,EAAE,IAAI;;;iBACxC,IAAI,EAAE,SAAS;iBAAE,KAAK,EAAE,IAAI;iBAAE,MAAM,EAAE,GAAG;;;iBACvC,IAAI,EAAE,WAAW;iBAAE,KAAK,EAAE,IAAI;iBAAE,MAAM,EAAE,IAAI;;CACZ,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,UAAU,EAG9C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,iCAAiC,CAAC;AAElE,wEAAwE;AACxE,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,WAAW,CAKhD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,8FACkD,CAAC;AAExF;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,SAAS,CASlD,CAAC;AAcF;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAEnE;AA2ED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,GAAE,cAAmB,GAAG,cAAc,CAoBzE;AAkBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,cAAc,GAAG,SAAS,EAClC,IAAI,EAAE,UAAU,GACf,cAAc,CAchB"}
|
package/dist/config.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { resolveFonts } from "./fonts.js";
|
|
1
2
|
import { builtinTemplates } from "./templates/index.js";
|
|
3
|
+
import { validateConfig } from "./validate.js";
|
|
2
4
|
/**
|
|
3
5
|
* Named output-size presets covering the common social-image standards. Each
|
|
4
6
|
* `name` becomes the filename suffix (e.g. `my-post-og.png`).
|
|
@@ -23,7 +25,11 @@ export const DEFAULT_SIZES = [
|
|
|
23
25
|
SIZE_PRESETS.og,
|
|
24
26
|
SIZE_PRESETS.square,
|
|
25
27
|
];
|
|
26
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Default font stack, used when no fonts are configured. It names families and
|
|
30
|
+
* hopes the machine has them, which is exactly what `config.fonts` exists to
|
|
31
|
+
* avoid: supply a font file and the output stops depending on the machine.
|
|
32
|
+
*/
|
|
27
33
|
export const DEFAULT_FONT_FAMILY = "Arial, Helvetica, sans-serif";
|
|
28
34
|
/** Neutral default palette, used when no `colors.brand` is supplied. */
|
|
29
35
|
export const DEFAULT_COLORS = {
|
|
@@ -41,7 +47,12 @@ export const DEFAULT_CODE_FONT_FAMILY = '"JetBrains Mono", "Source Code Pro", "D
|
|
|
41
47
|
/**
|
|
42
48
|
* Default `code` template styling. `charWidthRatio` and `lineHeight` drive the
|
|
43
49
|
* monospace grid the snippet is laid out on; the font-size bounds are
|
|
44
|
-
* fractions of the image
|
|
50
|
+
* fractions of the image width so they hold at every output size.
|
|
51
|
+
*
|
|
52
|
+
* `minFontScale` of `0.025` is roughly 30px on a 1200px-wide image, which
|
|
53
|
+
* still reads when a feed shows that image at half size. A snippet too long to
|
|
54
|
+
* fit at that size is truncated rather than shrunk, so a long sample loses
|
|
55
|
+
* lines on the shorter landscape formats.
|
|
45
56
|
*/
|
|
46
57
|
export const DEFAULT_CODE_STYLE = {
|
|
47
58
|
theme: "github-dark",
|
|
@@ -51,8 +62,19 @@ export const DEFAULT_CODE_STYLE = {
|
|
|
51
62
|
tabSize: 2,
|
|
52
63
|
cornerScale: 0.025,
|
|
53
64
|
maxFontScale: 0.075,
|
|
54
|
-
minFontScale: 0.
|
|
65
|
+
minFontScale: 0.025,
|
|
55
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* Default warning handler. Colophon runs at build time, so a compromise the
|
|
69
|
+
* renderer had to make belongs in the build log by default — silence is opt-in
|
|
70
|
+
* via `config.onWarning`.
|
|
71
|
+
*/
|
|
72
|
+
function warnToConsole(message) {
|
|
73
|
+
// The console is the point: this is the default sink, replaced wholesale by
|
|
74
|
+
// a caller-supplied `onWarning`.
|
|
75
|
+
// eslint-disable-next-line no-console
|
|
76
|
+
console.warn(`colophon: ${message}`);
|
|
77
|
+
}
|
|
56
78
|
/**
|
|
57
79
|
* Identity helper that returns its argument typed as {@link ColophonConfig}.
|
|
58
80
|
* Use it in a config module to get editor completion and type-checking.
|
|
@@ -99,20 +121,88 @@ function resolveSizes(sizes) {
|
|
|
99
121
|
}
|
|
100
122
|
return sizes;
|
|
101
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Whether to load the machine's own fonts. Configured fonts are meant to make
|
|
126
|
+
* the output the same everywhere, so supplying any turns system fonts off
|
|
127
|
+
* unless the project asks for them back.
|
|
128
|
+
*/
|
|
129
|
+
function shouldLoadSystemFonts(systemFonts, fonts) {
|
|
130
|
+
if (systemFonts === undefined) {
|
|
131
|
+
return fonts.length === 0;
|
|
132
|
+
}
|
|
133
|
+
if (!systemFonts && fonts.length === 0) {
|
|
134
|
+
throw new Error("systemFonts is false and no fonts are configured, so no text could be" +
|
|
135
|
+
" rendered. Add fonts, or leave systemFonts unset.");
|
|
136
|
+
}
|
|
137
|
+
return systemFonts;
|
|
138
|
+
}
|
|
102
139
|
/**
|
|
103
140
|
* Apply defaults to a user config. Safe to call with no argument.
|
|
141
|
+
*
|
|
142
|
+
* Unknown options are rejected before anything is resolved, so a config
|
|
143
|
+
* written against a different version of the package is a build error rather
|
|
144
|
+
* than a set of images quietly rendered with the defaults.
|
|
104
145
|
*/
|
|
105
146
|
export function resolveConfig(config = {}) {
|
|
147
|
+
validateConfig(config);
|
|
106
148
|
const colors = resolveColors(config.colors);
|
|
149
|
+
const fonts = resolveFonts(config.fonts);
|
|
107
150
|
return {
|
|
108
151
|
colors,
|
|
109
152
|
background: config.background ?? defaultBackground(colors),
|
|
110
|
-
|
|
153
|
+
fonts,
|
|
154
|
+
systemFonts: shouldLoadSystemFonts(config.systemFonts, fonts),
|
|
155
|
+
// A project that supplies one font should not have to name it twice.
|
|
156
|
+
fontFamily: config.fontFamily ?? fonts[0]?.family ?? DEFAULT_FONT_FAMILY,
|
|
111
157
|
footer: config.footer,
|
|
112
158
|
badge: config.badge,
|
|
113
159
|
code: resolveCode(config.code),
|
|
160
|
+
onWarning: config.onWarning ?? warnToConsole,
|
|
114
161
|
sizes: resolveSizes(config.sizes),
|
|
115
162
|
templates: { ...builtinTemplates, ...config.templates },
|
|
116
163
|
};
|
|
117
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Merge a size's colour overrides onto the config's.
|
|
167
|
+
*
|
|
168
|
+
* A size may name any single shade, so the merge starts from the full default
|
|
169
|
+
* palette when the config sets no colours of its own. Starting from nothing
|
|
170
|
+
* instead would hand `resolveColors` a lone `foreground`, and its rule that a
|
|
171
|
+
* bare `brand` colours the whole gradient would then flatten the default
|
|
172
|
+
* gradient — a size asking only for darker text would silently lose it.
|
|
173
|
+
*/
|
|
174
|
+
function mergeColors(base, overrides) {
|
|
175
|
+
return { ...(base ?? DEFAULT_COLORS), ...overrides };
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Apply a size's own overrides to a config and resolve the result: the config
|
|
179
|
+
* one image is actually rendered with.
|
|
180
|
+
*
|
|
181
|
+
* The overrides are folded into the user config and the whole thing resolved
|
|
182
|
+
* again, rather than patched onto an already-resolved config, so that anything
|
|
183
|
+
* derived stays consistent — a size that overrides `colors.brand` gets the
|
|
184
|
+
* default gradient rebuilt around its brand, exactly as a config setting the
|
|
185
|
+
* same colour at the top level would.
|
|
186
|
+
*
|
|
187
|
+
* `colors` and `code` merge over their config-level counterparts, because both
|
|
188
|
+
* are bags of independent settings and the point of the feature is to change
|
|
189
|
+
* one of them. The rest replace: a `background` is a union whose variants have
|
|
190
|
+
* different keys, so half of one over half of another is not a background at
|
|
191
|
+
* all, and `badge` carries a required `text` that a partial override could not
|
|
192
|
+
* supply.
|
|
193
|
+
*/
|
|
194
|
+
export function resolveConfigForSize(config, size) {
|
|
195
|
+
const base = config ?? {};
|
|
196
|
+
return resolveConfig({
|
|
197
|
+
...base,
|
|
198
|
+
...(size.colors !== undefined && {
|
|
199
|
+
colors: mergeColors(base.colors, size.colors),
|
|
200
|
+
}),
|
|
201
|
+
...(size.code !== undefined && { code: { ...base.code, ...size.code } }),
|
|
202
|
+
...(size.background !== undefined && { background: size.background }),
|
|
203
|
+
...(size.fontFamily !== undefined && { fontFamily: size.fontFamily }),
|
|
204
|
+
...(size.footer !== undefined && { footer: size.footer }),
|
|
205
|
+
...(size.badge !== undefined && { badge: size.badge }),
|
|
206
|
+
});
|
|
207
|
+
}
|
|
118
208
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAA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E,IAAI,CAAC,MAAM,EAAE,CAAC;QACzD,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;KACvD,CAAC,CAAC;AACL,CAAC"}
|
package/dist/content/index.d.ts
CHANGED
|
@@ -1,52 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
/** Root directory to search recursively for content files. */
|
|
7
|
-
readonly dir: string;
|
|
8
|
-
/** Frontmatter key holding the image props object. Default `meta_img_props`. */
|
|
9
|
-
readonly propsKey?: string;
|
|
10
|
-
/** Field within the props object naming the template. Default `template`. */
|
|
11
|
-
readonly templateField?: string;
|
|
12
|
-
/** Template to use when the template field is absent. */
|
|
13
|
-
readonly defaultTemplate?: string;
|
|
14
|
-
/**
|
|
15
|
-
* Top-level frontmatter field to read the post slug from (used as the base
|
|
16
|
-
* filename). Default `slug`; falls back to the file/directory name.
|
|
17
|
-
*/
|
|
18
|
-
readonly slugField?: string;
|
|
19
|
-
/** File extensions to include. Default `.md` and `.markdown`. */
|
|
20
|
-
readonly extensions?: readonly string[];
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* A discovered content file with the image props read from its frontmatter.
|
|
24
|
-
*/
|
|
25
|
-
export interface ContentFile {
|
|
26
|
-
/** Path relative to the walk `dir`. */
|
|
27
|
-
readonly contentPath: string;
|
|
28
|
-
/** Absolute path on disk. */
|
|
29
|
-
readonly absolutePath: string;
|
|
30
|
-
/** Base filename for this post's images (frontmatter slug, or path-derived). */
|
|
31
|
-
readonly slug: string;
|
|
32
|
-
readonly props: MetaImageProps;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Derive a slug from a file path: the filename without extension, or the
|
|
36
|
-
* parent directory name when the file is `index.*` (the common page-bundle
|
|
37
|
-
* convention).
|
|
38
|
-
*/
|
|
39
|
-
export declare function slugFromPath(filePath: string): string;
|
|
40
|
-
/**
|
|
41
|
-
* Extract {@link MetaImageProps} from a parsed frontmatter object, or return
|
|
42
|
-
* `undefined` if this file should be skipped (no props object, or no usable
|
|
43
|
-
* template/title). Pure — no filesystem access.
|
|
44
|
-
*/
|
|
45
|
-
export declare function extractProps(frontmatter: Record<string, unknown>, options?: Pick<WalkOptions, "propsKey" | "templateField" | "defaultTemplate">): MetaImageProps | undefined;
|
|
46
|
-
/**
|
|
47
|
-
* Walk a content tree, read each file's frontmatter with `gray-matter`, and
|
|
48
|
-
* return the files that declare image props. This is the host-project concern
|
|
49
|
-
* — finding content and reading frontmatter — kept separate from rendering.
|
|
50
|
-
*/
|
|
51
|
-
export declare function walkContent(options: WalkOptions): Promise<ContentFile[]>;
|
|
1
|
+
export { extractProps } from "./props.js";
|
|
2
|
+
export { slugFromPath } from "./slug.js";
|
|
3
|
+
export { walkContent } from "./walk.js";
|
|
4
|
+
export type { WalkOptions } from "./walk.js";
|
|
5
|
+
export type { ContentFile } from "../types.js";
|
|
52
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/content/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/content/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/content/index.js
CHANGED
|
@@ -1,116 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const defaultPropsKey = "meta_img_props";
|
|
5
|
-
const defaultTemplateField = "template";
|
|
6
|
-
const defaultSlugField = "slug";
|
|
7
|
-
const defaultExtensions = [".md", ".markdown"];
|
|
8
|
-
function coerceString(value) {
|
|
9
|
-
if (typeof value === "string") {
|
|
10
|
-
return value;
|
|
11
|
-
}
|
|
12
|
-
if (typeof value === "number" ||
|
|
13
|
-
typeof value === "boolean" ||
|
|
14
|
-
typeof value === "bigint") {
|
|
15
|
-
return String(value);
|
|
16
|
-
}
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Derive a slug from a file path: the filename without extension, or the
|
|
21
|
-
* parent directory name when the file is `index.*` (the common page-bundle
|
|
22
|
-
* convention).
|
|
23
|
-
*/
|
|
24
|
-
export function slugFromPath(filePath) {
|
|
25
|
-
const extension = path.extname(filePath);
|
|
26
|
-
const base = path.basename(filePath, extension);
|
|
27
|
-
return base === "index" ? path.basename(path.dirname(filePath)) : base;
|
|
28
|
-
}
|
|
29
|
-
function isRecord(value) {
|
|
30
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Extract {@link MetaImageProps} from a parsed frontmatter object, or return
|
|
34
|
-
* `undefined` if this file should be skipped (no props object, or no usable
|
|
35
|
-
* template/title). Pure — no filesystem access.
|
|
36
|
-
*/
|
|
37
|
-
export function extractProps(frontmatter, options = {}) {
|
|
38
|
-
const propsKey = options.propsKey ?? defaultPropsKey;
|
|
39
|
-
const templateField = options.templateField ?? defaultTemplateField;
|
|
40
|
-
const record = frontmatter[propsKey];
|
|
41
|
-
if (!isRecord(record)) {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
const templateRaw = record[templateField];
|
|
45
|
-
const template = typeof templateRaw === "string" ? templateRaw : options.defaultTemplate;
|
|
46
|
-
if (template === undefined) {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
// Title is optional: templates such as `code` describe the image entirely
|
|
50
|
-
// from their own fields, and requiring a title would be pure boilerplate.
|
|
51
|
-
const title = coerceString(record["title"]);
|
|
52
|
-
const subtitle = coerceString(record["subtitle"]);
|
|
53
|
-
const version = coerceString(record["version"]);
|
|
54
|
-
const extras = {};
|
|
55
|
-
for (const [key, value] of Object.entries(record)) {
|
|
56
|
-
if (key !== templateField &&
|
|
57
|
-
key !== "template" &&
|
|
58
|
-
key !== "title" &&
|
|
59
|
-
key !== "subtitle" &&
|
|
60
|
-
key !== "version") {
|
|
61
|
-
extras[key] = value;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
...extras,
|
|
66
|
-
template,
|
|
67
|
-
...(title !== undefined && { title }),
|
|
68
|
-
...(subtitle !== undefined && { subtitle }),
|
|
69
|
-
...(version !== undefined && { version }),
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
async function collectContentFiles(dir, extensions) {
|
|
73
|
-
const entries = await readdir(dir, { withFileTypes: true });
|
|
74
|
-
const nested = await Promise.all(entries.map(async (entry) => {
|
|
75
|
-
const entryPath = path.join(dir, entry.name);
|
|
76
|
-
if (entry.isDirectory()) {
|
|
77
|
-
return collectContentFiles(entryPath, extensions);
|
|
78
|
-
}
|
|
79
|
-
if (entry.isFile() &&
|
|
80
|
-
extensions.some((extension) => entry.name.endsWith(extension))) {
|
|
81
|
-
return [entryPath];
|
|
82
|
-
}
|
|
83
|
-
return [];
|
|
84
|
-
}));
|
|
85
|
-
return nested.flat();
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Walk a content tree, read each file's frontmatter with `gray-matter`, and
|
|
89
|
-
* return the files that declare image props. This is the host-project concern
|
|
90
|
-
* — finding content and reading frontmatter — kept separate from rendering.
|
|
91
|
-
*/
|
|
92
|
-
export async function walkContent(options) {
|
|
93
|
-
const extensions = options.extensions ?? defaultExtensions;
|
|
94
|
-
const filePaths = await collectContentFiles(options.dir, extensions);
|
|
95
|
-
const slugField = options.slugField ?? defaultSlugField;
|
|
96
|
-
const files = await Promise.all(filePaths.map(async (filePath) => {
|
|
97
|
-
const raw = await readFile(filePath, "utf8");
|
|
98
|
-
const frontmatter = matter(raw).data;
|
|
99
|
-
const props = extractProps(frontmatter, options);
|
|
100
|
-
if (props === undefined) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const declaredSlug = coerceString(frontmatter[slugField])?.trim();
|
|
104
|
-
const slug = declaredSlug !== undefined && declaredSlug !== ""
|
|
105
|
-
? declaredSlug
|
|
106
|
-
: slugFromPath(filePath);
|
|
107
|
-
return {
|
|
108
|
-
contentPath: path.relative(options.dir, filePath),
|
|
109
|
-
absolutePath: filePath,
|
|
110
|
-
slug,
|
|
111
|
-
props,
|
|
112
|
-
};
|
|
113
|
-
}));
|
|
114
|
-
return files.filter((file) => file !== undefined);
|
|
115
|
-
}
|
|
1
|
+
export { extractProps } from "./props.js";
|
|
2
|
+
export { slugFromPath } from "./slug.js";
|
|
3
|
+
export { walkContent } from "./walk.js";
|
|
116
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/content/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/content/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ContentOptions, MetaImageProps } from "../types.js";
|
|
2
|
+
/** Read a frontmatter scalar as a string, ignoring anything else. */
|
|
3
|
+
export declare function coerceString(value: unknown): string | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Extract {@link MetaImageProps} from a parsed frontmatter object, or return
|
|
6
|
+
* `undefined` if this file should be skipped (nothing to build props from, or
|
|
7
|
+
* no usable template). Pure — no filesystem access.
|
|
8
|
+
*
|
|
9
|
+
* Props can come from two places: the post's own props object, and a project's
|
|
10
|
+
* `props` mapper reading the frontmatter it already has. Where both speak the
|
|
11
|
+
* post wins, field by field — the mapper describes the site's usual shape, and
|
|
12
|
+
* a post that says otherwise is saying so on purpose.
|
|
13
|
+
*/
|
|
14
|
+
export declare function extractProps(frontmatter: Record<string, unknown>, options?: Pick<ContentOptions, "propsKey" | "templateField" | "defaultTemplate" | "props">): MetaImageProps | undefined;
|
|
15
|
+
//# sourceMappingURL=props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/content/props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAKlE,qEAAqE;AACrE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAc/D;AASD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,OAAO,GAAE,IAAI,CACX,cAAc,EACd,UAAU,GAAG,eAAe,GAAG,iBAAiB,GAAG,OAAO,CACtD,GACL,cAAc,GAAG,SAAS,CAiD5B"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const defaultPropsKey = "meta_img_props";
|
|
2
|
+
const defaultTemplateField = "template";
|
|
3
|
+
/** Read a frontmatter scalar as a string, ignoring anything else. */
|
|
4
|
+
export function coerceString(value) {
|
|
5
|
+
if (typeof value === "string") {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
if (typeof value === "number" ||
|
|
9
|
+
typeof value === "boolean" ||
|
|
10
|
+
typeof value === "bigint") {
|
|
11
|
+
return String(value);
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
function isRecord(value) {
|
|
16
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
/** The fields the props shape names itself, which never become extras. */
|
|
19
|
+
const namedFields = new Set(["template", "title", "subtitle", "version"]);
|
|
20
|
+
/**
|
|
21
|
+
* Extract {@link MetaImageProps} from a parsed frontmatter object, or return
|
|
22
|
+
* `undefined` if this file should be skipped (nothing to build props from, or
|
|
23
|
+
* no usable template). Pure — no filesystem access.
|
|
24
|
+
*
|
|
25
|
+
* Props can come from two places: the post's own props object, and a project's
|
|
26
|
+
* `props` mapper reading the frontmatter it already has. Where both speak the
|
|
27
|
+
* post wins, field by field — the mapper describes the site's usual shape, and
|
|
28
|
+
* a post that says otherwise is saying so on purpose.
|
|
29
|
+
*/
|
|
30
|
+
export function extractProps(frontmatter, options = {}) {
|
|
31
|
+
const propsKey = options.propsKey ?? defaultPropsKey;
|
|
32
|
+
const templateField = options.templateField ?? defaultTemplateField;
|
|
33
|
+
const declared = frontmatter[propsKey];
|
|
34
|
+
const hasDeclared = isRecord(declared);
|
|
35
|
+
const mapped = options.props?.(frontmatter);
|
|
36
|
+
// A mapper opting a post out cannot overrule a post that asked for an image
|
|
37
|
+
// outright, so the skip only applies where the post says nothing itself.
|
|
38
|
+
if (!hasDeclared && mapped === undefined) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
// Merged rather than replaced, so a post correcting one field does not have
|
|
42
|
+
// to restate everything the mapper already got right.
|
|
43
|
+
const record = {
|
|
44
|
+
...mapped,
|
|
45
|
+
...(hasDeclared && declared),
|
|
46
|
+
};
|
|
47
|
+
const templateRaw = record[templateField];
|
|
48
|
+
const template = typeof templateRaw === "string" ? templateRaw : options.defaultTemplate;
|
|
49
|
+
if (template === undefined) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
// Title is optional: templates such as `code` describe the image entirely
|
|
53
|
+
// from their own fields, and requiring a title would be pure boilerplate.
|
|
54
|
+
const title = coerceString(record["title"]);
|
|
55
|
+
const subtitle = coerceString(record["subtitle"]);
|
|
56
|
+
const version = coerceString(record["version"]);
|
|
57
|
+
const extras = {};
|
|
58
|
+
for (const [key, value] of Object.entries(record)) {
|
|
59
|
+
if (key !== templateField && !namedFields.has(key)) {
|
|
60
|
+
extras[key] = value;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
...extras,
|
|
65
|
+
template,
|
|
66
|
+
...(title !== undefined && { title }),
|
|
67
|
+
...(subtitle !== undefined && { subtitle }),
|
|
68
|
+
...(version !== undefined && { version }),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=props.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.js","sourceRoot":"","sources":["../../src/content/props.ts"],"names":[],"mappings":"AAEA,MAAM,eAAe,GAAG,gBAAgB,CAAC;AACzC,MAAM,oBAAoB,GAAG,UAAU,CAAC;AAExC,qEAAqE;AACrE,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,KAAK,SAAS;QAC1B,OAAO,KAAK,KAAK,QAAQ,EACzB,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,0EAA0E;AAC1E,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC;AAE1E;;;;;;;;;GASG;AACH,MAAM,UAAU,YAA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M,CAAC,EAAE,CAAC;QAClD,IAAI,GAAG,KAAK,aAAa,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACnD,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACtB,CAAC;IACH,CAAC;IAED,OAAO;QACL,GAAG,MAAM;QACT,QAAQ;QACR,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,CAAC;QACrC,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,QAAQ,EAAE,CAAC;QAC3C,GAAG,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,OAAO,EAAE,CAAC;KAC1C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SlugStrategy } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Derive a slug from a content file's path, relative to the root of the walk.
|
|
4
|
+
*
|
|
5
|
+
* `basename` gives the filename without extension, or the parent directory for
|
|
6
|
+
* `index.*` — the page-bundle convention, where an image sits beside its post.
|
|
7
|
+
* `route` keeps the directories, so a site addressed by route gets a slug that
|
|
8
|
+
* matches the address rather than just its last segment.
|
|
9
|
+
*
|
|
10
|
+
* The path must be relative to the content root for `route` to mean anything;
|
|
11
|
+
* `basename` reads the same either way.
|
|
12
|
+
*/
|
|
13
|
+
export declare function slugFromPath(contentPath: string, strategy?: SlugStrategy): string;
|
|
14
|
+
/**
|
|
15
|
+
* Reject a slug that would name a file outside the tree it came from.
|
|
16
|
+
*
|
|
17
|
+
* A slug is a filename, and may carry directories under the `route` strategy —
|
|
18
|
+
* but a declared one is written by hand, and `slug: ../../../tmp/x` would have
|
|
19
|
+
* `generate` create directories and write an image there. Nothing derived from
|
|
20
|
+
* a path can look like this, so the check only ever fires on frontmatter.
|
|
21
|
+
*/
|
|
22
|
+
export declare function assertSlugStaysInside(slug: string, contentPath: string): void;
|
|
23
|
+
//# sourceMappingURL=slug.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slug.d.ts","sourceRoot":"","sources":["../../src/content/slug.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,EACnB,QAAQ,GAAE,YAAyB,GAClC,MAAM,CAqBR;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAe7E"}
|