@hagicode/hagilight 0.2.3 → 0.2.4-dev.36.1.9b5c546
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/favicon.ico +0 -0
- package/favicon.mjs +76 -0
- package/package.json +5 -1
- package/site-links.ts +25 -3
package/favicon.ico
ADDED
|
Binary file
|
package/favicon.mjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
|
|
4
|
+
const faviconPath = fileURLToPath(new URL('./favicon.ico', import.meta.url));
|
|
5
|
+
let cachedDataUri;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Resolve the bundled HagiCode favicon as an inline data URI.
|
|
9
|
+
* Memoized so the binary is read at most once per process.
|
|
10
|
+
*/
|
|
11
|
+
export function getHagilightFaviconDataUri() {
|
|
12
|
+
if (cachedDataUri === undefined) {
|
|
13
|
+
const bytes = readFileSync(faviconPath);
|
|
14
|
+
cachedDataUri = `data:image/x-icon;base64,${bytes.toString('base64')}`;
|
|
15
|
+
}
|
|
16
|
+
return cachedDataUri;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isIconLink(entry) {
|
|
20
|
+
return entry?.tag === 'link'
|
|
21
|
+
&& typeof entry.attrs?.rel === 'string'
|
|
22
|
+
&& /\bicon\b/u.test(entry.attrs.rel);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function headHasIconLink(head) {
|
|
26
|
+
return (head ?? []).some(isIconLink);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Resolve the favicon `<link>` head entry to inject, or `undefined` to skip.
|
|
31
|
+
*
|
|
32
|
+
* Shared by both the `hagilightFavicon` integration and the Starlight plugin so the
|
|
33
|
+
* favicon behavior has a single source of truth.
|
|
34
|
+
*
|
|
35
|
+
* Override options:
|
|
36
|
+
* - Pass `{ href: '/your-favicon.ico' }` to use a consumer-provided favicon instead.
|
|
37
|
+
* - If `head` already contains an icon link, injection is skipped (so manual favicons
|
|
38
|
+
* are never duplicated).
|
|
39
|
+
*
|
|
40
|
+
* @param {Array<{tag:string, attrs?:Record<string,string>}>} head existing head entries
|
|
41
|
+
* @param {{href?:string}} [options] optional override href
|
|
42
|
+
*/
|
|
43
|
+
export function resolveFaviconHeadEntry(head = [], options = {}) {
|
|
44
|
+
if (headHasIconLink(head)) return undefined;
|
|
45
|
+
const overrideHref = typeof options.href === 'string' && options.href.trim()
|
|
46
|
+
? options.href.trim()
|
|
47
|
+
: undefined;
|
|
48
|
+
const href = overrideHref ?? getHagilightFaviconDataUri();
|
|
49
|
+
const attrs = { rel: 'icon', href };
|
|
50
|
+
if (overrideHref === undefined) attrs.type = 'image/x-icon';
|
|
51
|
+
return { tag: 'link', attrs };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Astro integration that auto-applies the bundled HagiCode favicon.
|
|
56
|
+
*
|
|
57
|
+
* Any site referencing `@hagicode/hagilight` can add `integrations: [hagilightFavicon()]`
|
|
58
|
+
* to get the shared favicon with no further configuration.
|
|
59
|
+
*/
|
|
60
|
+
export function hagilightFavicon(options = {}) {
|
|
61
|
+
if (options !== undefined && (!options || typeof options !== 'object' || Array.isArray(options))) {
|
|
62
|
+
throw new TypeError('Hagilight favicon options must be an object.');
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
name: '@hagicode/hagilight:favicon',
|
|
66
|
+
hooks: {
|
|
67
|
+
'astro:config:setup'({ config, updateConfig }) {
|
|
68
|
+
const entry = resolveFaviconHeadEntry(config.head, options);
|
|
69
|
+
if (!entry) return;
|
|
70
|
+
updateConfig({
|
|
71
|
+
head: [...(config.head ?? []), entry],
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hagicode/hagilight",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4-dev.36.1.9b5c546",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Shared Astro components for HagiCode sites",
|
|
6
6
|
"repository": {
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
"./Copyright": "./Copyright.astro",
|
|
18
18
|
"./PromotoBanner": "./PromotoBanner.astro",
|
|
19
19
|
"./logo.png": "./logo.png",
|
|
20
|
+
"./favicon.ico": "./favicon.ico",
|
|
21
|
+
"./favicon": "./favicon.mjs",
|
|
20
22
|
"./site-links": "./site-links.ts",
|
|
21
23
|
"./GoogleAnalytics": "./GoogleAnalytics.astro",
|
|
22
24
|
"./Analytics51LA": "./Analytics51LA.astro"
|
|
@@ -24,6 +26,8 @@
|
|
|
24
26
|
"files": [
|
|
25
27
|
"*.astro",
|
|
26
28
|
"*.png",
|
|
29
|
+
"*.ico",
|
|
30
|
+
"*.mjs",
|
|
27
31
|
"*.ts",
|
|
28
32
|
"*.json"
|
|
29
33
|
],
|
package/site-links.ts
CHANGED
|
@@ -175,8 +175,30 @@ const translations = {
|
|
|
175
175
|
'fr-FR': 'Télécharger Hagicode pour Windows', 'es-ES': 'Descargar Hagicode para Windows',
|
|
176
176
|
'pt-BR': 'Baixar Hagicode para Windows', 'ru-RU': 'Скачать Hagicode для Windows',
|
|
177
177
|
},
|
|
178
|
-
icpFiling:
|
|
179
|
-
|
|
178
|
+
icpFiling: {
|
|
179
|
+
'zh-CN': '闽ICP备2026004153号-1',
|
|
180
|
+
'zh-Hant': '闽ICP备2026004153号-1',
|
|
181
|
+
'en-US': 'ICP Filing 闽ICP备2026004153号-1',
|
|
182
|
+
'ja-JP': 'ICP届出 闽ICP备2026004153号-1',
|
|
183
|
+
'ko-KR': 'ICP 신고 闽ICP备2026004153号-1',
|
|
184
|
+
'de-DE': 'ICP-Registrierung 闽ICP备2026004153号-1',
|
|
185
|
+
'fr-FR': 'Dépôt ICP 闽ICP备2026004153号-1',
|
|
186
|
+
'es-ES': 'Registro ICP 闽ICP备2026004153号-1',
|
|
187
|
+
'pt-BR': 'Registro ICP 闽ICP备2026004153号-1',
|
|
188
|
+
'ru-RU': 'ICP регистрация 闽ICP备2026004153号-1',
|
|
189
|
+
},
|
|
190
|
+
publicSecurityFiling: {
|
|
191
|
+
'zh-CN': '闽公网安备35011102351148号',
|
|
192
|
+
'zh-Hant': '闽公网安备35011102351148号',
|
|
193
|
+
'en-US': 'Public Security Filing 闽公网安备35011102351148号',
|
|
194
|
+
'ja-JP': '公安届出 闽公网安备35011102351148号',
|
|
195
|
+
'ko-KR': '공안 신고 闽公网安备35011102351148号',
|
|
196
|
+
'de-DE': 'Sicherheitsregistrierung 闽公网安备35011102351148号',
|
|
197
|
+
'fr-FR': 'Dépôt de sécurité publique 闽公网安备35011102351148号',
|
|
198
|
+
'es-ES': 'Registro de seguridad pública 闽公网安备35011102351148号',
|
|
199
|
+
'pt-BR': 'Registro de segurança pública 闽公网安备35011102351148号',
|
|
200
|
+
'ru-RU': 'Регистрация в органах общественной безопасности 闽公网安备35011102351148号',
|
|
201
|
+
},
|
|
180
202
|
} satisfies Record<SiteLinkKey, LocalizedText>;
|
|
181
203
|
|
|
182
204
|
const defaultLinks: Record<SiteLinkKey, LinkDefinition> = {
|
|
@@ -462,4 +484,4 @@ export function resolveSiteLinks(localeInput?: string | null, options: SiteLinks
|
|
|
462
484
|
filings: resolvedGroups.filings,
|
|
463
485
|
relatedSites,
|
|
464
486
|
};
|
|
465
|
-
}
|
|
487
|
+
}
|