@hagicode/hagilight-core 0.1.0-dev.148.1.e0c630e
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/Analytics51LA.astro +17 -0
- package/Copyright.astro +9 -0
- package/Footer.astro +208 -0
- package/FooterAvatarPicker.astro +9 -0
- package/FooterBrand.astro +339 -0
- package/GoogleAnalytics.astro +30 -0
- package/PostHog.astro +11 -0
- package/PromotoBanner.astro +582 -0
- package/README.md +485 -0
- package/RootTransit.astro +599 -0
- package/assets/footer/avatar.avif +0 -0
- package/assets/footer/avatar.webp +0 -0
- package/assets/footer/manifest.json +237 -0
- package/data/comparison-articles/de-DE/claude-vs-hagicode.json +294 -0
- package/data/comparison-articles/de-DE/codebuddy-vs-hagicode.json +266 -0
- package/data/comparison-articles/de-DE/codex-vs-hagicode.json +266 -0
- package/data/comparison-articles/de-DE/copilot-vs-hagicode.json +266 -0
- package/data/comparison-articles/de-DE/deepagents-vs-hagicode.json +266 -0
- package/data/comparison-articles/de-DE/gemini-vs-hagicode.json +266 -0
- package/data/comparison-articles/de-DE/hermes-vs-hagicode.json +266 -0
- package/data/comparison-articles/de-DE/kimi-vs-hagicode.json +266 -0
- package/data/comparison-articles/de-DE/kiro-vs-hagicode.json +266 -0
- package/data/comparison-articles/de-DE/opencode-vs-hagicode.json +266 -0
- package/data/comparison-articles/de-DE/pi-vs-hagicode.json +282 -0
- package/data/comparison-articles/de-DE/qoder-vs-hagicode.json +266 -0
- package/data/comparison-articles/de-DE/reasonix-vs-hagicode.json +281 -0
- package/data/comparison-articles/en-US/claude-vs-hagicode.json +346 -0
- package/data/comparison-articles/en-US/codebuddy-vs-hagicode.json +322 -0
- package/data/comparison-articles/en-US/codex-vs-hagicode.json +321 -0
- package/data/comparison-articles/en-US/copilot-vs-hagicode.json +320 -0
- package/data/comparison-articles/en-US/deepagents-vs-hagicode.json +323 -0
- package/data/comparison-articles/en-US/dsh-vs-hagicode.json +323 -0
- package/data/comparison-articles/en-US/gemini-vs-hagicode.json +320 -0
- package/data/comparison-articles/en-US/hermes-vs-hagicode.json +323 -0
- package/data/comparison-articles/en-US/junie-vs-hagicode.json +323 -0
- package/data/comparison-articles/en-US/kimi-vs-hagicode.json +319 -0
- package/data/comparison-articles/en-US/kiro-vs-hagicode.json +319 -0
- package/data/comparison-articles/en-US/omp-vs-hagicode.json +345 -0
- package/data/comparison-articles/en-US/opencode-vs-hagicode.json +333 -0
- package/data/comparison-articles/en-US/pi-vs-hagicode.json +345 -0
- package/data/comparison-articles/en-US/qoder-vs-hagicode.json +323 -0
- package/data/comparison-articles/en-US/reasonix-vs-hagicode.json +344 -0
- package/data/comparison-articles/es-ES/claude-vs-hagicode.json +294 -0
- package/data/comparison-articles/es-ES/codebuddy-vs-hagicode.json +266 -0
- package/data/comparison-articles/es-ES/codex-vs-hagicode.json +266 -0
- package/data/comparison-articles/es-ES/copilot-vs-hagicode.json +266 -0
- package/data/comparison-articles/es-ES/deepagents-vs-hagicode.json +266 -0
- package/data/comparison-articles/es-ES/gemini-vs-hagicode.json +266 -0
- package/data/comparison-articles/es-ES/hermes-vs-hagicode.json +266 -0
- package/data/comparison-articles/es-ES/kimi-vs-hagicode.json +266 -0
- package/data/comparison-articles/es-ES/kiro-vs-hagicode.json +266 -0
- package/data/comparison-articles/es-ES/opencode-vs-hagicode.json +266 -0
- package/data/comparison-articles/es-ES/pi-vs-hagicode.json +281 -0
- package/data/comparison-articles/es-ES/qoder-vs-hagicode.json +266 -0
- package/data/comparison-articles/es-ES/reasonix-vs-hagicode.json +281 -0
- package/data/comparison-articles/fr-FR/claude-vs-hagicode.json +294 -0
- package/data/comparison-articles/fr-FR/codebuddy-vs-hagicode.json +266 -0
- package/data/comparison-articles/fr-FR/codex-vs-hagicode.json +266 -0
- package/data/comparison-articles/fr-FR/copilot-vs-hagicode.json +266 -0
- package/data/comparison-articles/fr-FR/deepagents-vs-hagicode.json +266 -0
- package/data/comparison-articles/fr-FR/gemini-vs-hagicode.json +266 -0
- package/data/comparison-articles/fr-FR/hermes-vs-hagicode.json +266 -0
- package/data/comparison-articles/fr-FR/kimi-vs-hagicode.json +266 -0
- package/data/comparison-articles/fr-FR/kiro-vs-hagicode.json +266 -0
- package/data/comparison-articles/fr-FR/opencode-vs-hagicode.json +266 -0
- package/data/comparison-articles/fr-FR/pi-vs-hagicode.json +281 -0
- package/data/comparison-articles/fr-FR/qoder-vs-hagicode.json +266 -0
- package/data/comparison-articles/fr-FR/reasonix-vs-hagicode.json +281 -0
- package/data/comparison-articles/ja-JP/claude-vs-hagicode.json +294 -0
- package/data/comparison-articles/ja-JP/codebuddy-vs-hagicode.json +266 -0
- package/data/comparison-articles/ja-JP/codex-vs-hagicode.json +266 -0
- package/data/comparison-articles/ja-JP/copilot-vs-hagicode.json +266 -0
- package/data/comparison-articles/ja-JP/deepagents-vs-hagicode.json +266 -0
- package/data/comparison-articles/ja-JP/gemini-vs-hagicode.json +266 -0
- package/data/comparison-articles/ja-JP/hermes-vs-hagicode.json +266 -0
- package/data/comparison-articles/ja-JP/kimi-vs-hagicode.json +266 -0
- package/data/comparison-articles/ja-JP/kiro-vs-hagicode.json +266 -0
- package/data/comparison-articles/ja-JP/opencode-vs-hagicode.json +266 -0
- package/data/comparison-articles/ja-JP/pi-vs-hagicode.json +281 -0
- package/data/comparison-articles/ja-JP/qoder-vs-hagicode.json +266 -0
- package/data/comparison-articles/ja-JP/reasonix-vs-hagicode.json +281 -0
- package/data/comparison-articles/ko-KR/claude-vs-hagicode.json +294 -0
- package/data/comparison-articles/ko-KR/codebuddy-vs-hagicode.json +266 -0
- package/data/comparison-articles/ko-KR/codex-vs-hagicode.json +266 -0
- package/data/comparison-articles/ko-KR/copilot-vs-hagicode.json +266 -0
- package/data/comparison-articles/ko-KR/deepagents-vs-hagicode.json +266 -0
- package/data/comparison-articles/ko-KR/gemini-vs-hagicode.json +266 -0
- package/data/comparison-articles/ko-KR/hermes-vs-hagicode.json +266 -0
- package/data/comparison-articles/ko-KR/kimi-vs-hagicode.json +266 -0
- package/data/comparison-articles/ko-KR/kiro-vs-hagicode.json +266 -0
- package/data/comparison-articles/ko-KR/opencode-vs-hagicode.json +266 -0
- package/data/comparison-articles/ko-KR/pi-vs-hagicode.json +281 -0
- package/data/comparison-articles/ko-KR/qoder-vs-hagicode.json +266 -0
- package/data/comparison-articles/ko-KR/reasonix-vs-hagicode.json +281 -0
- package/data/comparison-articles/pt-BR/claude-vs-hagicode.json +294 -0
- package/data/comparison-articles/pt-BR/codebuddy-vs-hagicode.json +266 -0
- package/data/comparison-articles/pt-BR/codex-vs-hagicode.json +266 -0
- package/data/comparison-articles/pt-BR/copilot-vs-hagicode.json +266 -0
- package/data/comparison-articles/pt-BR/deepagents-vs-hagicode.json +266 -0
- package/data/comparison-articles/pt-BR/gemini-vs-hagicode.json +266 -0
- package/data/comparison-articles/pt-BR/hermes-vs-hagicode.json +266 -0
- package/data/comparison-articles/pt-BR/kimi-vs-hagicode.json +266 -0
- package/data/comparison-articles/pt-BR/kiro-vs-hagicode.json +266 -0
- package/data/comparison-articles/pt-BR/opencode-vs-hagicode.json +266 -0
- package/data/comparison-articles/pt-BR/pi-vs-hagicode.json +281 -0
- package/data/comparison-articles/pt-BR/qoder-vs-hagicode.json +266 -0
- package/data/comparison-articles/pt-BR/reasonix-vs-hagicode.json +281 -0
- package/data/comparison-articles/ru-RU/claude-vs-hagicode.json +294 -0
- package/data/comparison-articles/ru-RU/codebuddy-vs-hagicode.json +266 -0
- package/data/comparison-articles/ru-RU/codex-vs-hagicode.json +266 -0
- package/data/comparison-articles/ru-RU/copilot-vs-hagicode.json +266 -0
- package/data/comparison-articles/ru-RU/deepagents-vs-hagicode.json +266 -0
- package/data/comparison-articles/ru-RU/gemini-vs-hagicode.json +266 -0
- package/data/comparison-articles/ru-RU/hermes-vs-hagicode.json +266 -0
- package/data/comparison-articles/ru-RU/kimi-vs-hagicode.json +266 -0
- package/data/comparison-articles/ru-RU/kiro-vs-hagicode.json +266 -0
- package/data/comparison-articles/ru-RU/opencode-vs-hagicode.json +266 -0
- package/data/comparison-articles/ru-RU/pi-vs-hagicode.json +281 -0
- package/data/comparison-articles/ru-RU/qoder-vs-hagicode.json +323 -0
- package/data/comparison-articles/ru-RU/reasonix-vs-hagicode.json +281 -0
- package/data/comparison-articles/zh-CN/claude-vs-hagicode.json +346 -0
- package/data/comparison-articles/zh-CN/codebuddy-vs-hagicode.json +322 -0
- package/data/comparison-articles/zh-CN/codex-vs-hagicode.json +321 -0
- package/data/comparison-articles/zh-CN/copilot-vs-hagicode.json +320 -0
- package/data/comparison-articles/zh-CN/deepagents-vs-hagicode.json +323 -0
- package/data/comparison-articles/zh-CN/dsh-vs-hagicode.json +323 -0
- package/data/comparison-articles/zh-CN/gemini-vs-hagicode.json +320 -0
- package/data/comparison-articles/zh-CN/hermes-vs-hagicode.json +323 -0
- package/data/comparison-articles/zh-CN/junie-vs-hagicode.json +323 -0
- package/data/comparison-articles/zh-CN/kimi-vs-hagicode.json +319 -0
- package/data/comparison-articles/zh-CN/kiro-vs-hagicode.json +319 -0
- package/data/comparison-articles/zh-CN/omp-vs-hagicode.json +345 -0
- package/data/comparison-articles/zh-CN/opencode-vs-hagicode.json +333 -0
- package/data/comparison-articles/zh-CN/pi-vs-hagicode.json +345 -0
- package/data/comparison-articles/zh-CN/qoder-vs-hagicode.json +323 -0
- package/data/comparison-articles/zh-CN/reasonix-vs-hagicode.json +344 -0
- package/data/comparison-articles/zh-Hant/claude-vs-hagicode.json +294 -0
- package/data/comparison-articles/zh-Hant/codebuddy-vs-hagicode.json +266 -0
- package/data/comparison-articles/zh-Hant/codex-vs-hagicode.json +266 -0
- package/data/comparison-articles/zh-Hant/copilot-vs-hagicode.json +266 -0
- package/data/comparison-articles/zh-Hant/deepagents-vs-hagicode.json +266 -0
- package/data/comparison-articles/zh-Hant/gemini-vs-hagicode.json +266 -0
- package/data/comparison-articles/zh-Hant/hermes-vs-hagicode.json +266 -0
- package/data/comparison-articles/zh-Hant/kimi-vs-hagicode.json +266 -0
- package/data/comparison-articles/zh-Hant/kiro-vs-hagicode.json +266 -0
- package/data/comparison-articles/zh-Hant/opencode-vs-hagicode.json +266 -0
- package/data/comparison-articles/zh-Hant/pi-vs-hagicode.json +281 -0
- package/data/comparison-articles/zh-Hant/qoder-vs-hagicode.json +266 -0
- package/data/comparison-articles/zh-Hant/reasonix-vs-hagicode.json +281 -0
- package/dist/analytics-events.d.ts +49 -0
- package/dist/analytics-events.js +113 -0
- package/dist/build-info-resolver.d.ts +8 -0
- package/dist/build-info-resolver.js +29 -0
- package/dist/build-info.d.ts +19 -0
- package/dist/build-info.js +60 -0
- package/dist/comparison-articles-source.d.ts +13 -0
- package/dist/comparison-articles-source.js +58 -0
- package/dist/comparison-articles.d.ts +127 -0
- package/dist/comparison-articles.js +260 -0
- package/dist/content-images.d.ts +126 -0
- package/dist/content-images.js +490 -0
- package/dist/favicon.d.ts +21 -0
- package/dist/favicon.js +27 -0
- package/dist/footer-avatar.d.ts +39 -0
- package/dist/footer-avatar.js +42 -0
- package/dist/footer-brand.d.ts +29 -0
- package/dist/footer-brand.js +86 -0
- package/dist/head.d.ts +7 -0
- package/dist/head.js +1 -0
- package/dist/link-policy.d.ts +33 -0
- package/dist/link-policy.js +93 -0
- package/dist/links.d.ts +70 -0
- package/dist/links.js +425 -0
- package/dist/posthog.d.ts +6 -0
- package/dist/posthog.js +17 -0
- package/dist/promotions.d.ts +50 -0
- package/dist/promotions.js +243 -0
- package/dist/promoto-banner.d.ts +14 -0
- package/dist/promoto-banner.js +499 -0
- package/dist/random-image.d.ts +69 -0
- package/dist/random-image.js +133 -0
- package/dist/related-sites.json +378 -0
- package/dist/root-transit.d.ts +12 -0
- package/dist/root-transit.js +221 -0
- package/dist/rss-footer-context.d.ts +6 -0
- package/dist/rss-footer-context.js +54 -0
- package/dist/rss-ownership.d.ts +26 -0
- package/dist/rss-ownership.js +63 -0
- package/dist/rss.d.ts +34 -0
- package/dist/rss.js +145 -0
- package/dist/seo-schema.d.ts +12 -0
- package/dist/seo-schema.js +20 -0
- package/dist/seo.d.ts +78 -0
- package/dist/seo.js +270 -0
- package/dist/site-metadata-ownership.d.ts +40 -0
- package/dist/site-metadata-ownership.js +72 -0
- package/dist/site-metadata-writer.d.ts +25 -0
- package/dist/site-metadata-writer.js +55 -0
- package/dist/site-metadata.d.ts +113 -0
- package/dist/site-metadata.js +256 -0
- package/dist/splash-images.d.ts +75 -0
- package/dist/splash-images.js +186 -0
- package/favicon.ico +0 -0
- package/logo.png +0 -0
- package/package.json +172 -0
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import { dirname, isAbsolute, relative, resolve, sep } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
export const CONTENT_IMAGE_CLASS = 'hagilight-content-image';
|
|
4
|
+
function isRecord(value) {
|
|
5
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
export function resolveContentImageOptions(options = {}) {
|
|
8
|
+
if (!isRecord(options))
|
|
9
|
+
throw new TypeError('Hagilight content image options must be an object.');
|
|
10
|
+
const { loading = 'lazy', decoding = 'async', className = CONTENT_IMAGE_CLASS } = options;
|
|
11
|
+
if (loading !== 'lazy' && loading !== 'eager') {
|
|
12
|
+
throw new TypeError('Hagilight content image loading option must be "lazy" or "eager".');
|
|
13
|
+
}
|
|
14
|
+
if (decoding !== 'async' && decoding !== 'sync' && decoding !== 'auto') {
|
|
15
|
+
throw new TypeError('Hagilight content image decoding option must be "async", "sync", or "auto".');
|
|
16
|
+
}
|
|
17
|
+
if (typeof className !== 'string' || className === '' || /\s/u.test(className)) {
|
|
18
|
+
throw new TypeError('Hagilight content image className option must be a non-empty class name without whitespace.');
|
|
19
|
+
}
|
|
20
|
+
return { loading, decoding, className };
|
|
21
|
+
}
|
|
22
|
+
export function contentImagePatch(author, options) {
|
|
23
|
+
const patch = {};
|
|
24
|
+
if (!author.hasLoading)
|
|
25
|
+
patch.loading = options.loading;
|
|
26
|
+
if (!author.hasDecoding)
|
|
27
|
+
patch.decoding = options.decoding;
|
|
28
|
+
if (!author.classNames.includes(options.className)) {
|
|
29
|
+
patch.classNames = [...author.classNames, options.className];
|
|
30
|
+
}
|
|
31
|
+
return patch;
|
|
32
|
+
}
|
|
33
|
+
function splitClassNames(value) {
|
|
34
|
+
return value.split(/\s+/u).filter(Boolean);
|
|
35
|
+
}
|
|
36
|
+
function classNamesOf(value) {
|
|
37
|
+
if (typeof value === 'string')
|
|
38
|
+
return splitClassNames(value);
|
|
39
|
+
if (Array.isArray(value)) {
|
|
40
|
+
return value.filter((item) => typeof item === 'string').flatMap(splitClassNames);
|
|
41
|
+
}
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
function mdxClassNames(attribute) {
|
|
45
|
+
if (attribute === undefined || attribute.value === undefined || attribute.value === null)
|
|
46
|
+
return [];
|
|
47
|
+
return typeof attribute.value === 'string' ? splitClassNames(attribute.value) : undefined;
|
|
48
|
+
}
|
|
49
|
+
export function hastImagePatch(properties, options) {
|
|
50
|
+
return contentImagePatch({
|
|
51
|
+
hasLoading: properties.loading !== undefined,
|
|
52
|
+
hasDecoding: properties.decoding !== undefined,
|
|
53
|
+
classNames: classNamesOf(properties.className),
|
|
54
|
+
}, options);
|
|
55
|
+
}
|
|
56
|
+
/** A class written as an expression cannot be merged statically, so its marker is left out. */
|
|
57
|
+
export function mdxImagePatch(attributes, options) {
|
|
58
|
+
const classNames = mdxClassNames(attributes.find((attribute) => attribute.name === 'class'));
|
|
59
|
+
const patch = contentImagePatch({
|
|
60
|
+
hasLoading: attributes.some((attribute) => attribute.name === 'loading'),
|
|
61
|
+
hasDecoding: attributes.some((attribute) => attribute.name === 'decoding'),
|
|
62
|
+
classNames: classNames ?? [options.className],
|
|
63
|
+
}, options);
|
|
64
|
+
return {
|
|
65
|
+
loading: patch.loading,
|
|
66
|
+
decoding: patch.decoding,
|
|
67
|
+
className: patch.classNames?.join(' '),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function isMdxJsx(node) {
|
|
71
|
+
return node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement';
|
|
72
|
+
}
|
|
73
|
+
function isPicture(node) {
|
|
74
|
+
return (node.type === 'element' && node.tagName === 'picture')
|
|
75
|
+
|| (isMdxJsx(node) && (node.name === 'picture' || node.name === 'Picture'));
|
|
76
|
+
}
|
|
77
|
+
function upsertMdxAttribute(attributes, name, value) {
|
|
78
|
+
const existing = attributes.find((attribute) => attribute.name === name);
|
|
79
|
+
if (existing)
|
|
80
|
+
existing.value = value;
|
|
81
|
+
else
|
|
82
|
+
attributes.push({ type: 'mdxJsxAttribute', name, value });
|
|
83
|
+
}
|
|
84
|
+
function applyUnifiedNode(node, options) {
|
|
85
|
+
if (node.type === 'element' && node.tagName === 'img') {
|
|
86
|
+
const properties = (node.properties ??= {});
|
|
87
|
+
const patch = hastImagePatch(properties, options);
|
|
88
|
+
if (patch.loading !== undefined)
|
|
89
|
+
properties.loading = patch.loading;
|
|
90
|
+
if (patch.decoding !== undefined)
|
|
91
|
+
properties.decoding = patch.decoding;
|
|
92
|
+
if (patch.classNames !== undefined)
|
|
93
|
+
properties.className = patch.classNames;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (isMdxJsx(node) && node.name === 'img') {
|
|
97
|
+
const attributes = (node.attributes ??= []);
|
|
98
|
+
const patch = mdxImagePatch(attributes, options);
|
|
99
|
+
if (patch.loading !== undefined)
|
|
100
|
+
upsertMdxAttribute(attributes, 'loading', patch.loading);
|
|
101
|
+
if (patch.decoding !== undefined)
|
|
102
|
+
upsertMdxAttribute(attributes, 'decoding', patch.decoding);
|
|
103
|
+
if (patch.className !== undefined)
|
|
104
|
+
upsertMdxAttribute(attributes, 'class', patch.className);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function applyUnifiedTree(node, options, inPicture) {
|
|
108
|
+
if (!inPicture)
|
|
109
|
+
applyUnifiedNode(node, options);
|
|
110
|
+
const childrenInPicture = inPicture || isPicture(node);
|
|
111
|
+
for (const child of node.children ?? [])
|
|
112
|
+
applyUnifiedTree(child, options, childrenInPicture);
|
|
113
|
+
}
|
|
114
|
+
/** Replaces each `img` outside a picture for which `replace` returns a node. */
|
|
115
|
+
function replaceUnifiedImages(node, inPicture, replace) {
|
|
116
|
+
const children = node.children;
|
|
117
|
+
if (!children)
|
|
118
|
+
return;
|
|
119
|
+
children.forEach((child, index) => {
|
|
120
|
+
if (!inPicture && child.type === 'element' && child.tagName === 'img') {
|
|
121
|
+
const replacement = replace(child);
|
|
122
|
+
if (replacement !== undefined) {
|
|
123
|
+
children[index] = replacement;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
replaceUnifiedImages(child, inPicture || isPicture(child), replace);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/** Unified rehype plugin for sites whose `markdown.processor` is `unified()`. */
|
|
131
|
+
export function rehypeContentImages(options = {}, picture = { enabled: true }) {
|
|
132
|
+
const resolved = resolveContentImageOptions(options);
|
|
133
|
+
let pictureCount = 0;
|
|
134
|
+
return (tree, file) => {
|
|
135
|
+
applyUnifiedTree(tree, resolved, false);
|
|
136
|
+
const format = documentFormat(file?.path);
|
|
137
|
+
if (!picture.enabled || format === undefined)
|
|
138
|
+
return;
|
|
139
|
+
const astro = file?.data?.astro;
|
|
140
|
+
const documentPath = toFilePath(file?.path);
|
|
141
|
+
const eligibleSrc = (img) => pictureSource(img.properties?.src, astro, picture, documentPath);
|
|
142
|
+
if (format === 'markdown') {
|
|
143
|
+
replaceUnifiedImages(tree, false, (img) => {
|
|
144
|
+
const src = eligibleSrc(img);
|
|
145
|
+
return src === undefined ? undefined : pictureElement(img, src, ++pictureCount);
|
|
146
|
+
});
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const scope = newMdxPictureScope();
|
|
150
|
+
replaceUnifiedImages(tree, false, (img) => {
|
|
151
|
+
const src = eligibleSrc(img);
|
|
152
|
+
if (src === undefined)
|
|
153
|
+
return undefined;
|
|
154
|
+
return pictureComponent(pictureProperties(img.properties ?? {}, resolved), assetIdentifier(scope, src, 'estree'), 'estree');
|
|
155
|
+
});
|
|
156
|
+
if (scope.pending.length > 0)
|
|
157
|
+
tree.children?.unshift(...scope.pending);
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function isInsidePicture(node, ctx) {
|
|
161
|
+
for (let parent = ctx.parent(node); parent; parent = ctx.parent(parent)) {
|
|
162
|
+
if (isPicture(parent))
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
const PICTURE_FORMATS = ['avif', 'webp'];
|
|
168
|
+
const PICTURE_FALLBACK_FORMAT = 'webp';
|
|
169
|
+
const PICTURE_COMPONENT = 'HagilightContentPicture';
|
|
170
|
+
const PICTURE_COMPONENT_SOURCE = 'astro:assets';
|
|
171
|
+
const NOOP_IMAGE_SERVICE = 'astro/assets/services/noop';
|
|
172
|
+
/** Extensions the picture step leaves alone: SVG is already vector, and a GIF would lose its animation. */
|
|
173
|
+
const VECTOR_OR_ANIMATED = /\.(?:svg|gif)$/iu;
|
|
174
|
+
function localImageSrc(value, astro) {
|
|
175
|
+
const localPaths = astro?.localImagePaths;
|
|
176
|
+
if (typeof value !== 'string' || localPaths === undefined)
|
|
177
|
+
return undefined;
|
|
178
|
+
const src = decodeURI(value);
|
|
179
|
+
const isLocal = localPaths instanceof Set ? localPaths.has(src) : localPaths.includes(src);
|
|
180
|
+
return isLocal ? src : undefined;
|
|
181
|
+
}
|
|
182
|
+
/** A file URL or absolute path as a filesystem path; `undefined` for anything else. */
|
|
183
|
+
function toFilePath(value) {
|
|
184
|
+
const text = value instanceof URL ? value.href : value;
|
|
185
|
+
if (typeof text !== 'string')
|
|
186
|
+
return undefined;
|
|
187
|
+
if (text.startsWith('file:'))
|
|
188
|
+
return fileURLToPath(text);
|
|
189
|
+
return isAbsolute(text) ? text : undefined;
|
|
190
|
+
}
|
|
191
|
+
function documentFormat(filePath) {
|
|
192
|
+
const text = String(filePath ?? '');
|
|
193
|
+
if (text.endsWith('.mdx'))
|
|
194
|
+
return 'mdx';
|
|
195
|
+
if (text.endsWith('.md'))
|
|
196
|
+
return 'markdown';
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
function withoutQueryOrFragment(src) {
|
|
200
|
+
return src.replace(/[?#].*$/u, '');
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* The file a relative reference names, resolved against the document's directory.
|
|
204
|
+
* Site-root, bare and aliased specifiers, and a missing document location, resolve to `undefined`.
|
|
205
|
+
*/
|
|
206
|
+
function resolveLocalFile(src, documentPath) {
|
|
207
|
+
if (documentPath === undefined)
|
|
208
|
+
return undefined;
|
|
209
|
+
const file = withoutQueryOrFragment(src);
|
|
210
|
+
if (!file.startsWith('./') && !file.startsWith('../'))
|
|
211
|
+
return undefined;
|
|
212
|
+
return resolve(dirname(documentPath), file);
|
|
213
|
+
}
|
|
214
|
+
function isInsideDirectory(directory, file) {
|
|
215
|
+
const offset = relative(directory, file);
|
|
216
|
+
return offset !== '..' && !offset.startsWith(`..${sep}`) && !isAbsolute(offset);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* The decoded `src` when the picture step may wrap this image, otherwise `undefined`. One rule for
|
|
220
|
+
* `.md` and `.mdx`: collected by Astro as local, not SVG or GIF, not inside `publicDir`, step enabled.
|
|
221
|
+
* Without a document location or a `publicDir`, the `public/` check is skipped.
|
|
222
|
+
*/
|
|
223
|
+
function pictureSource(value, astro, picture, documentPath) {
|
|
224
|
+
if (!picture.enabled)
|
|
225
|
+
return undefined;
|
|
226
|
+
const src = localImageSrc(value, astro);
|
|
227
|
+
if (src === undefined || VECTOR_OR_ANIMATED.test(withoutQueryOrFragment(src)))
|
|
228
|
+
return undefined;
|
|
229
|
+
const file = resolveLocalFile(src, documentPath);
|
|
230
|
+
if (picture.publicDir !== undefined && file !== undefined && isInsideDirectory(picture.publicDir, file)) {
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
return src;
|
|
234
|
+
}
|
|
235
|
+
function pictureElement(img, src, index) {
|
|
236
|
+
const sources = PICTURE_FORMATS.map((format) => ({
|
|
237
|
+
type: 'element',
|
|
238
|
+
tagName: 'source',
|
|
239
|
+
properties: {
|
|
240
|
+
__ASTRO_IMAGE_: JSON.stringify({
|
|
241
|
+
src,
|
|
242
|
+
format,
|
|
243
|
+
type: `image/${format}`,
|
|
244
|
+
densities: [1],
|
|
245
|
+
index: `picture-${format}-${index}`,
|
|
246
|
+
}),
|
|
247
|
+
},
|
|
248
|
+
children: [],
|
|
249
|
+
}));
|
|
250
|
+
return { type: 'element', tagName: 'picture', properties: {}, children: [...sources, img] };
|
|
251
|
+
}
|
|
252
|
+
function estreeProgram(body) {
|
|
253
|
+
return { type: 'Program', sourceType: 'module', comments: [], body };
|
|
254
|
+
}
|
|
255
|
+
function jsxAttributeNode(attribute, flavor) {
|
|
256
|
+
if ('text' in attribute)
|
|
257
|
+
return { type: 'mdxJsxAttribute', name: attribute.name, value: attribute.text };
|
|
258
|
+
const expression = 'identifier' in attribute ? attribute.identifier : JSON.stringify(attribute.list);
|
|
259
|
+
const value = { type: 'mdxJsxAttributeValueExpression', value: expression };
|
|
260
|
+
if (flavor === 'estree') {
|
|
261
|
+
const node = 'identifier' in attribute
|
|
262
|
+
? { type: 'Identifier', name: attribute.identifier }
|
|
263
|
+
: {
|
|
264
|
+
type: 'ArrayExpression',
|
|
265
|
+
elements: attribute.list.map((item) => ({ type: 'Literal', value: item, raw: JSON.stringify(item) })),
|
|
266
|
+
};
|
|
267
|
+
value.data = { estree: estreeProgram([{ type: 'ExpressionStatement', expression: node }]) };
|
|
268
|
+
}
|
|
269
|
+
return { type: 'mdxJsxAttribute', name: attribute.name, value };
|
|
270
|
+
}
|
|
271
|
+
function importNode(flavor, text, declaration) {
|
|
272
|
+
if (flavor === 'source')
|
|
273
|
+
return { type: 'mdxjsEsm', value: text };
|
|
274
|
+
return { type: 'mdxjsEsm', value: '', data: { estree: estreeProgram([declaration]) } };
|
|
275
|
+
}
|
|
276
|
+
function newMdxPictureScope() {
|
|
277
|
+
return { assets: new Map(), component: false, pending: [] };
|
|
278
|
+
}
|
|
279
|
+
/** The identifier an asset import binds for `src`, queuing the imports the first time each is needed. */
|
|
280
|
+
function assetIdentifier(scope, src, flavor) {
|
|
281
|
+
const existing = scope.assets.get(src);
|
|
282
|
+
if (existing !== undefined)
|
|
283
|
+
return existing;
|
|
284
|
+
const name = `HagilightContentImage${scope.assets.size}`;
|
|
285
|
+
if (!scope.component) {
|
|
286
|
+
scope.component = true;
|
|
287
|
+
scope.pending.push(importNode(flavor, `import { Picture as ${PICTURE_COMPONENT} } from "${PICTURE_COMPONENT_SOURCE}";`, {
|
|
288
|
+
type: 'ImportDeclaration',
|
|
289
|
+
attributes: [],
|
|
290
|
+
source: { type: 'Literal', value: PICTURE_COMPONENT_SOURCE, raw: JSON.stringify(PICTURE_COMPONENT_SOURCE) },
|
|
291
|
+
specifiers: [{
|
|
292
|
+
type: 'ImportSpecifier',
|
|
293
|
+
imported: { type: 'Identifier', name: 'Picture' },
|
|
294
|
+
local: { type: 'Identifier', name: PICTURE_COMPONENT },
|
|
295
|
+
}],
|
|
296
|
+
}));
|
|
297
|
+
}
|
|
298
|
+
scope.pending.push(importNode(flavor, `import ${name} from ${JSON.stringify(src)};`, {
|
|
299
|
+
type: 'ImportDeclaration',
|
|
300
|
+
attributes: [],
|
|
301
|
+
source: { type: 'Literal', value: src, raw: JSON.stringify(src) },
|
|
302
|
+
specifiers: [{ type: 'ImportDefaultSpecifier', local: { type: 'Identifier', name } }],
|
|
303
|
+
}));
|
|
304
|
+
scope.assets.set(src, name);
|
|
305
|
+
return name;
|
|
306
|
+
}
|
|
307
|
+
/** The image's properties after the baseline patch, with `alt` present, as `Picture` receives them. */
|
|
308
|
+
function pictureProperties(properties, options) {
|
|
309
|
+
const patch = hastImagePatch(properties, options);
|
|
310
|
+
const next = { ...properties };
|
|
311
|
+
if (patch.loading !== undefined)
|
|
312
|
+
next.loading = patch.loading;
|
|
313
|
+
if (patch.decoding !== undefined)
|
|
314
|
+
next.decoding = patch.decoding;
|
|
315
|
+
if (patch.classNames !== undefined)
|
|
316
|
+
next.className = patch.classNames;
|
|
317
|
+
if (next.alt === undefined || next.alt === null)
|
|
318
|
+
next.alt = '';
|
|
319
|
+
return next;
|
|
320
|
+
}
|
|
321
|
+
/** The `Picture` element an author would write by hand (D2), with the image's own attributes. */
|
|
322
|
+
function pictureComponent(properties, identifier, flavor) {
|
|
323
|
+
const attributes = [
|
|
324
|
+
{ name: 'src', identifier },
|
|
325
|
+
{ name: 'formats', list: [...PICTURE_FORMATS] },
|
|
326
|
+
{ name: 'fallbackFormat', text: PICTURE_FALLBACK_FORMAT },
|
|
327
|
+
];
|
|
328
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
329
|
+
if (key === 'src' || value === undefined || value === null || value === false)
|
|
330
|
+
continue;
|
|
331
|
+
const name = key === 'className' ? 'class' : key === 'htmlFor' ? 'for' : key;
|
|
332
|
+
attributes.push({ name, text: Array.isArray(value) ? value.map(String).join(' ') : String(value) });
|
|
333
|
+
}
|
|
334
|
+
return {
|
|
335
|
+
type: 'mdxJsxFlowElement',
|
|
336
|
+
name: PICTURE_COMPONENT,
|
|
337
|
+
attributes: attributes.map((attribute) => jsxAttributeNode(attribute, flavor)),
|
|
338
|
+
children: [],
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
/** The root of the document, which holds the ESM imports a `Picture` needs. */
|
|
342
|
+
function documentRoot(node, ctx) {
|
|
343
|
+
let current = node;
|
|
344
|
+
for (let parent = ctx.parent(current); parent; parent = ctx.parent(current))
|
|
345
|
+
current = parent;
|
|
346
|
+
return current;
|
|
347
|
+
}
|
|
348
|
+
function mdxScope(data) {
|
|
349
|
+
data.hagilightContentPicture ??= newMdxPictureScope();
|
|
350
|
+
return data.hagilightContentPicture;
|
|
351
|
+
}
|
|
352
|
+
/** Sätteri hast plugin: Astro's default Markdown processor, through `hastPlugins`. */
|
|
353
|
+
export function satteriContentImages(options = {}, picture = { enabled: true }) {
|
|
354
|
+
const resolved = resolveContentImageOptions(options);
|
|
355
|
+
let pictureCount = 0;
|
|
356
|
+
const mdxVisitor = {
|
|
357
|
+
filter: ['img'],
|
|
358
|
+
visit(node, ctx) {
|
|
359
|
+
if (isInsidePicture(node, ctx))
|
|
360
|
+
return;
|
|
361
|
+
const patch = mdxImagePatch(node.attributes ?? [], resolved);
|
|
362
|
+
if (patch.loading !== undefined)
|
|
363
|
+
ctx.setProperty(node, 'loading', patch.loading);
|
|
364
|
+
if (patch.decoding !== undefined)
|
|
365
|
+
ctx.setProperty(node, 'decoding', patch.decoding);
|
|
366
|
+
if (patch.className !== undefined)
|
|
367
|
+
ctx.setProperty(node, 'class', patch.className);
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
return {
|
|
371
|
+
name: 'hagilight:content-images',
|
|
372
|
+
element: {
|
|
373
|
+
filter: ['img'],
|
|
374
|
+
visit(node, ctx) {
|
|
375
|
+
if (isInsidePicture(node, ctx))
|
|
376
|
+
return;
|
|
377
|
+
const isDocument = ctx.sourceFormat === 'markdown' || ctx.sourceFormat === 'mdx';
|
|
378
|
+
const src = isDocument
|
|
379
|
+
? pictureSource(node.properties?.src, ctx.data.astro, picture, toFilePath(ctx.fileURL))
|
|
380
|
+
: undefined;
|
|
381
|
+
if (src !== undefined && ctx.sourceFormat === 'mdx') {
|
|
382
|
+
const root = documentRoot(node, ctx);
|
|
383
|
+
const scope = mdxScope(ctx.data);
|
|
384
|
+
const identifier = assetIdentifier(scope, src, 'source');
|
|
385
|
+
ctx.replaceNode(node, pictureComponent(pictureProperties(node.properties ?? {}, resolved), identifier, 'source'));
|
|
386
|
+
if (scope.pending.length > 0)
|
|
387
|
+
ctx.prependChild(root, scope.pending.splice(0));
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
const patch = hastImagePatch(node.properties ?? {}, resolved);
|
|
391
|
+
if (patch.loading !== undefined)
|
|
392
|
+
ctx.setProperty(node, 'loading', patch.loading);
|
|
393
|
+
if (patch.decoding !== undefined)
|
|
394
|
+
ctx.setProperty(node, 'decoding', patch.decoding);
|
|
395
|
+
if (patch.classNames !== undefined)
|
|
396
|
+
ctx.setProperty(node, 'className', patch.classNames);
|
|
397
|
+
if (src !== undefined && ctx.sourceFormat === 'markdown') {
|
|
398
|
+
ctx.replaceNode(node, pictureElement(node, src, ++pictureCount));
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
mdxJsxFlowElement: mdxVisitor,
|
|
403
|
+
mdxJsxTextElement: mdxVisitor,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
const RECORD_KEY = Symbol.for('hagilight.content-images');
|
|
407
|
+
function recordOf(processor) {
|
|
408
|
+
const holder = processor;
|
|
409
|
+
holder[RECORD_KEY] ??= { optedOut: false, warned: new Set() };
|
|
410
|
+
return holder[RECORD_KEY];
|
|
411
|
+
}
|
|
412
|
+
function pluginListOf(processor) {
|
|
413
|
+
const hastPlugins = processor.options?.hastPlugins;
|
|
414
|
+
const rehypePlugins = processor.options?.rehypePlugins;
|
|
415
|
+
if (processor.name === 'satteri' && Array.isArray(hastPlugins))
|
|
416
|
+
return hastPlugins;
|
|
417
|
+
if (processor.name === 'unified' && Array.isArray(rehypePlugins))
|
|
418
|
+
return rehypePlugins;
|
|
419
|
+
return undefined;
|
|
420
|
+
}
|
|
421
|
+
function warnOnce(record, key, logger, message) {
|
|
422
|
+
if (record.warned.has(key))
|
|
423
|
+
return;
|
|
424
|
+
record.warned.add(key);
|
|
425
|
+
logger.warn(message);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Register the content-image plugin on the active Markdown processor. The first enabled
|
|
429
|
+
* call appends one adapter; an `enabled: false` call opts the whole site out and removes
|
|
430
|
+
* only the adapter it did not append, so the result does not depend on hook order.
|
|
431
|
+
*/
|
|
432
|
+
export function registerContentImages({ config, logger, enabled }) {
|
|
433
|
+
const processor = config.markdown?.processor;
|
|
434
|
+
if (!processor) {
|
|
435
|
+
if (enabled) {
|
|
436
|
+
logger.warn('Hagilight content images need a Markdown processor, but the Astro config has none. Body images are left unchanged.');
|
|
437
|
+
}
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
const record = recordOf(processor);
|
|
441
|
+
if (!enabled) {
|
|
442
|
+
record.optedOut = true;
|
|
443
|
+
if (record.list && record.entry !== undefined) {
|
|
444
|
+
const index = record.list.indexOf(record.entry);
|
|
445
|
+
if (index !== -1)
|
|
446
|
+
record.list.splice(index, 1);
|
|
447
|
+
}
|
|
448
|
+
record.entry = undefined;
|
|
449
|
+
record.list = undefined;
|
|
450
|
+
record.picture = undefined;
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
if (record.optedOut || record.entry !== undefined)
|
|
454
|
+
return;
|
|
455
|
+
const list = pluginListOf(processor);
|
|
456
|
+
if (!list) {
|
|
457
|
+
warnOnce(record, 'unsupported', logger, `Hagilight content images cannot run on the "${String(processor.name)}" Markdown processor. Body images are left unchanged.`);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const picture = { enabled: true };
|
|
461
|
+
const publicDir = toFilePath(config.publicDir);
|
|
462
|
+
if (publicDir !== undefined)
|
|
463
|
+
picture.publicDir = publicDir;
|
|
464
|
+
const plugin = processor.name === 'satteri'
|
|
465
|
+
? satteriContentImages({}, picture)
|
|
466
|
+
: (options) => rehypeContentImages(options, picture);
|
|
467
|
+
list.push(plugin);
|
|
468
|
+
record.entry = plugin;
|
|
469
|
+
record.list = list;
|
|
470
|
+
record.picture = picture;
|
|
471
|
+
}
|
|
472
|
+
/** `astro:config:done` re-check: warns once if an enabled site's adapter is missing from the final processor. */
|
|
473
|
+
export function checkContentImageRegistration({ config, logger, enabled }) {
|
|
474
|
+
if (!enabled)
|
|
475
|
+
return;
|
|
476
|
+
const processor = config.markdown?.processor;
|
|
477
|
+
if (!processor)
|
|
478
|
+
return;
|
|
479
|
+
const record = recordOf(processor);
|
|
480
|
+
if (record.optedOut || record.warned.has('unsupported'))
|
|
481
|
+
return;
|
|
482
|
+
if (record.entry === undefined || !pluginListOf(processor)?.includes(record.entry)) {
|
|
483
|
+
warnOnce(record, 'lost', logger, `Hagilight content images were not found in the final "${String(processor.name)}" Markdown processor. Body images are left unchanged.`);
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
if (record.picture?.enabled && config.image?.service?.entrypoint === NOOP_IMAGE_SERVICE) {
|
|
487
|
+
record.picture.enabled = false;
|
|
488
|
+
warnOnce(record, 'picture', logger, 'Hagilight content images skip the <picture> wrapper because the Astro image service is the passthrough no-op, which cannot encode AVIF. Body images keep the baseline output. Use the default sharp service to get AVIF and WebP sources.');
|
|
489
|
+
}
|
|
490
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { HeadEntry } from './head.js';
|
|
2
|
+
export type { HeadEntry } from './head.js';
|
|
3
|
+
export interface FaviconLinkEntry extends HeadEntry {
|
|
4
|
+
tag: 'link';
|
|
5
|
+
attrs: {
|
|
6
|
+
rel: 'icon';
|
|
7
|
+
href: string;
|
|
8
|
+
type?: 'image/x-icon';
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface FaviconOptions {
|
|
12
|
+
/** Consumer-provided favicon URL used instead of the bundled HagiCode icon. */
|
|
13
|
+
href?: string;
|
|
14
|
+
}
|
|
15
|
+
/** Bundled HagiCode favicon as an inline data URI, read at most once per process. */
|
|
16
|
+
export declare function getHagilightFaviconDataUri(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve the favicon `<link>` head entry to inject, or `undefined` when the
|
|
19
|
+
* existing head already declares an icon.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveFaviconHeadEntry(head?: readonly HeadEntry[] | undefined, options?: FaviconOptions): FaviconLinkEntry | undefined;
|
package/dist/favicon.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
const faviconPath = fileURLToPath(new URL('../favicon.ico', import.meta.url));
|
|
4
|
+
let cachedDataUri;
|
|
5
|
+
/** Bundled HagiCode favicon as an inline data URI, read at most once per process. */
|
|
6
|
+
export function getHagilightFaviconDataUri() {
|
|
7
|
+
cachedDataUri ??= `data:image/x-icon;base64,${readFileSync(faviconPath).toString('base64')}`;
|
|
8
|
+
return cachedDataUri;
|
|
9
|
+
}
|
|
10
|
+
function isIconLink(entry) {
|
|
11
|
+
const rel = entry?.attrs?.rel;
|
|
12
|
+
return entry?.tag === 'link' && typeof rel === 'string' && /\bicon\b/u.test(rel);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolve the favicon `<link>` head entry to inject, or `undefined` when the
|
|
16
|
+
* existing head already declares an icon.
|
|
17
|
+
*/
|
|
18
|
+
export function resolveFaviconHeadEntry(head = [], options = {}) {
|
|
19
|
+
if ((head ?? []).some(isIconLink))
|
|
20
|
+
return undefined;
|
|
21
|
+
const overrideHref = typeof options.href === 'string' && options.href.trim()
|
|
22
|
+
? options.href.trim()
|
|
23
|
+
: undefined;
|
|
24
|
+
if (overrideHref !== undefined)
|
|
25
|
+
return { tag: 'link', attrs: { rel: 'icon', href: overrideHref } };
|
|
26
|
+
return { tag: 'link', attrs: { rel: 'icon', href: getHagilightFaviconDataUri(), type: 'image/x-icon' } };
|
|
27
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public contract for the shared footer avatar (`hagilight-footer-imagery`): option parsing and the decorative
|
|
3
|
+
* image attributes that the Astro and Docusaurus footers both render. Browser-safe: no `node:` import.
|
|
4
|
+
*/
|
|
5
|
+
export interface FooterAvatarOptions {
|
|
6
|
+
/** Show the avatar in the brand block. Defaults to `true`; `false` removes the element and its request. */
|
|
7
|
+
avatar?: boolean;
|
|
8
|
+
/** Swap the avatar for one random pool entry per page view. Defaults to `true`. */
|
|
9
|
+
randomAvatar?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface ResolvedFooterAvatarOptions {
|
|
12
|
+
avatar: boolean;
|
|
13
|
+
randomAvatar: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const FOOTER_AVATAR_DISPLAY_PX = 64;
|
|
16
|
+
export declare const FOOTER_AVATAR_SOURCE_PX = 128;
|
|
17
|
+
/** Below this container width the avatar is hidden, so a narrow footer keeps its text layout. */
|
|
18
|
+
export declare const FOOTER_AVATAR_MIN_CONTAINER_PX = 360;
|
|
19
|
+
export interface FooterAvatarImageAttributes {
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
alt: '';
|
|
23
|
+
'aria-hidden': 'true';
|
|
24
|
+
loading: 'lazy';
|
|
25
|
+
decoding: 'async';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Attributes of the decorative `<img>`: no alternative text and hidden from assistive technology. A fresh object on
|
|
29
|
+
* every call, because Astro adds its scoping class to spread attributes and would fail on a shared frozen object.
|
|
30
|
+
*/
|
|
31
|
+
export declare function footerAvatarImageAttributes(): FooterAvatarImageAttributes;
|
|
32
|
+
/**
|
|
33
|
+
* Resolves the footer avatar options. `undefined` gives the defaults; anything that is not an object or a boolean
|
|
34
|
+
* throws a `TypeError`, so bad configuration fails the build.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveFooterAvatarOptions(input?: {
|
|
37
|
+
avatar?: unknown;
|
|
38
|
+
randomAvatar?: unknown;
|
|
39
|
+
}): ResolvedFooterAvatarOptions;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public contract for the shared footer avatar (`hagilight-footer-imagery`): option parsing and the decorative
|
|
3
|
+
* image attributes that the Astro and Docusaurus footers both render. Browser-safe: no `node:` import.
|
|
4
|
+
*/
|
|
5
|
+
export const FOOTER_AVATAR_DISPLAY_PX = 64;
|
|
6
|
+
export const FOOTER_AVATAR_SOURCE_PX = 128;
|
|
7
|
+
/** Below this container width the avatar is hidden, so a narrow footer keeps its text layout. */
|
|
8
|
+
export const FOOTER_AVATAR_MIN_CONTAINER_PX = 360;
|
|
9
|
+
/**
|
|
10
|
+
* Attributes of the decorative `<img>`: no alternative text and hidden from assistive technology. A fresh object on
|
|
11
|
+
* every call, because Astro adds its scoping class to spread attributes and would fail on a shared frozen object.
|
|
12
|
+
*/
|
|
13
|
+
export function footerAvatarImageAttributes() {
|
|
14
|
+
return {
|
|
15
|
+
width: FOOTER_AVATAR_DISPLAY_PX,
|
|
16
|
+
height: FOOTER_AVATAR_DISPLAY_PX,
|
|
17
|
+
alt: '',
|
|
18
|
+
'aria-hidden': 'true',
|
|
19
|
+
loading: 'lazy',
|
|
20
|
+
decoding: 'async',
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function booleanOption(value, name) {
|
|
24
|
+
if (value === undefined)
|
|
25
|
+
return undefined;
|
|
26
|
+
if (typeof value !== 'boolean')
|
|
27
|
+
throw new TypeError(`Hagilight footer ${name} option must be a boolean.`);
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolves the footer avatar options. `undefined` gives the defaults; anything that is not an object or a boolean
|
|
32
|
+
* throws a `TypeError`, so bad configuration fails the build.
|
|
33
|
+
*/
|
|
34
|
+
export function resolveFooterAvatarOptions(input) {
|
|
35
|
+
if (input !== undefined && (typeof input !== 'object' || input === null || Array.isArray(input))) {
|
|
36
|
+
throw new TypeError('Hagilight footer avatar options must be an object.');
|
|
37
|
+
}
|
|
38
|
+
const avatar = booleanOption(input?.avatar, 'avatar') ?? true;
|
|
39
|
+
const randomAvatar = booleanOption(input?.randomAvatar, 'randomAvatar') ?? true;
|
|
40
|
+
// The random pool only exists when the avatar does, so a disabled avatar carries no pool list or picker.
|
|
41
|
+
return { avatar, randomAvatar: avatar && randomAvatar };
|
|
42
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { SiteLink } from './links.js';
|
|
2
|
+
export type FooterBrandPillarId = 'smart' | 'efficient' | 'fun';
|
|
3
|
+
export interface FooterBrandPillar {
|
|
4
|
+
id: FooterBrandPillarId;
|
|
5
|
+
label: string;
|
|
6
|
+
description: string;
|
|
7
|
+
}
|
|
8
|
+
export interface FooterBrandCopy {
|
|
9
|
+
name: string;
|
|
10
|
+
/** One display line: what HagiCode turns the reader's work into. */
|
|
11
|
+
headline: string;
|
|
12
|
+
/** What the product is, in the same words the article showcase uses. */
|
|
13
|
+
summary: string;
|
|
14
|
+
pillars: readonly FooterBrandPillar[];
|
|
15
|
+
}
|
|
16
|
+
export interface FooterBrandLinks {
|
|
17
|
+
primary?: SiteLink;
|
|
18
|
+
secondary?: SiteLink;
|
|
19
|
+
}
|
|
20
|
+
export declare const FOOTER_BRAND_LOCALES: readonly string[];
|
|
21
|
+
/** Resolves the footer's product statement. `locale` is the value `resolveSiteLinks` already normalized. */
|
|
22
|
+
export declare function resolveFooterBrand(locale?: string | null): FooterBrandCopy & {
|
|
23
|
+
locale: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Picks the two calls to action from the footer's already-resolved quick links, so consumer
|
|
27
|
+
* overrides and `removeLinks` apply and a removed link leaves no dead button behind.
|
|
28
|
+
*/
|
|
29
|
+
export declare function pickFooterBrandLinks(quick: readonly SiteLink[]): FooterBrandLinks;
|