@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,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract for the `.well-known/hagilight.metadata.json` file. Browser-safe and
|
|
3
|
+
* pure: no Node modules. The Node-only writer lives in `site-metadata-writer.ts`.
|
|
4
|
+
*
|
|
5
|
+
* Values are copied field by field from typed inputs, so new input fields can
|
|
6
|
+
* never leak into the output. Analytics appears only as on/off booleans.
|
|
7
|
+
*/
|
|
8
|
+
import { normalizeBuildInfo, UNKNOWN } from './build-info.js';
|
|
9
|
+
export const SITE_METADATA_SCHEMA_VERSION = 1;
|
|
10
|
+
/** Site-relative output path. This is the only place the path is spelled. */
|
|
11
|
+
export const SITE_METADATA_PATH = '.well-known/hagilight.metadata.json';
|
|
12
|
+
/**
|
|
13
|
+
* Substrings that a provider's loader leaves in built HTML. Each provider needs
|
|
14
|
+
* every marker in one page. A core test pins these to the shipped loaders, so a
|
|
15
|
+
* loader change fails loudly here.
|
|
16
|
+
*/
|
|
17
|
+
export const ANALYTICS_LOADER_MARKERS = {
|
|
18
|
+
googleAnalytics: ['https://www.googletagmanager.com/gtag/js'],
|
|
19
|
+
fiftyOneLa: ['id="LA_COLLECT"', 'https://sdk.51.la/js-sdk-pro.min.js'],
|
|
20
|
+
posthog: ['__hagilightPosthogInitialized'],
|
|
21
|
+
};
|
|
22
|
+
const DISCOVERY_KEYS = ['sitemap', 'robots', 'rss', 'llms'];
|
|
23
|
+
const ANALYTICS_KEYS = ['googleAnalytics', 'fiftyOneLa', 'posthog'];
|
|
24
|
+
const FEATURE_KEYS = ['seo', 'promoto'];
|
|
25
|
+
const TOP_LEVEL_KEYS = ['schemaVersion', 'generator', 'site', 'languages', 'build', 'discovery', 'analytics', 'features'];
|
|
26
|
+
function isRecord(value) {
|
|
27
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
28
|
+
}
|
|
29
|
+
function trimmed(value) {
|
|
30
|
+
if (typeof value !== 'string')
|
|
31
|
+
return undefined;
|
|
32
|
+
const text = value.trim();
|
|
33
|
+
return text || undefined;
|
|
34
|
+
}
|
|
35
|
+
/** Leading and trailing slash, `/` for the root. */
|
|
36
|
+
function normalizeBase(value) {
|
|
37
|
+
const inner = (trimmed(value) ?? '').replace(/^\/+|\/+$/gu, '');
|
|
38
|
+
return inner ? `/${inner}/` : '/';
|
|
39
|
+
}
|
|
40
|
+
function hostnameOf(url) {
|
|
41
|
+
try {
|
|
42
|
+
return new URL(url).hostname;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return UNKNOWN;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function canonicalLang(value) {
|
|
49
|
+
try {
|
|
50
|
+
return Intl.getCanonicalLocales(value)[0];
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function pickBooleans(input, keys) {
|
|
57
|
+
const record = isRecord(input) ? input : {};
|
|
58
|
+
return Object.fromEntries(keys.map((key) => [key, record[key] === true]));
|
|
59
|
+
}
|
|
60
|
+
/** Build a schema-valid object from typed inputs. Pure and deterministic. */
|
|
61
|
+
export function buildSiteMetadata(input) {
|
|
62
|
+
const url = new URL(input.site.url).href;
|
|
63
|
+
const base = normalizeBase(input.site.base);
|
|
64
|
+
const description = trimmed(input.site.description);
|
|
65
|
+
const fallbackLang = canonicalLang(input.fallbackLang ?? 'en') ?? 'en';
|
|
66
|
+
const rawLocales = (input.locales ?? []).map((locale) => ({
|
|
67
|
+
code: trimmed(locale.code) ?? fallbackLang,
|
|
68
|
+
lang: canonicalLang(locale.lang) ?? fallbackLang,
|
|
69
|
+
path: normalizeBase(locale.path),
|
|
70
|
+
}));
|
|
71
|
+
const locales = rawLocales.length > 0
|
|
72
|
+
? rawLocales
|
|
73
|
+
: [{ code: fallbackLang, lang: fallbackLang, path: '/' }];
|
|
74
|
+
const defaultLocale = trimmed(input.defaultLocale);
|
|
75
|
+
const defaultCode = defaultLocale !== undefined && locales.some((locale) => locale.code === defaultLocale)
|
|
76
|
+
? defaultLocale
|
|
77
|
+
: locales[0].code;
|
|
78
|
+
const discovery = {};
|
|
79
|
+
for (const key of DISCOVERY_KEYS) {
|
|
80
|
+
const value = input.discovery?.[key];
|
|
81
|
+
if (typeof value === 'string' && value.startsWith('/'))
|
|
82
|
+
discovery[key] = value;
|
|
83
|
+
}
|
|
84
|
+
const features = {
|
|
85
|
+
...(typeof input.features?.seo === 'boolean' ? { seo: input.features.seo } : {}),
|
|
86
|
+
...(typeof input.features?.promoto === 'boolean' ? { promoto: input.features.promoto } : {}),
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
schemaVersion: SITE_METADATA_SCHEMA_VERSION,
|
|
90
|
+
generator: {
|
|
91
|
+
name: trimmed(input.generator.name) ?? UNKNOWN,
|
|
92
|
+
version: trimmed(input.generator.version) ?? UNKNOWN,
|
|
93
|
+
},
|
|
94
|
+
site: {
|
|
95
|
+
name: trimmed(input.site.name) ?? hostnameOf(url),
|
|
96
|
+
url,
|
|
97
|
+
base,
|
|
98
|
+
...(description === undefined ? {} : { description }),
|
|
99
|
+
},
|
|
100
|
+
languages: {
|
|
101
|
+
default: defaultCode,
|
|
102
|
+
locales,
|
|
103
|
+
},
|
|
104
|
+
build: normalizeBuildInfo(input.build),
|
|
105
|
+
discovery,
|
|
106
|
+
analytics: pickBooleans(input.analytics, ANALYTICS_KEYS),
|
|
107
|
+
features,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** Problems found in an untrusted value. An empty list means the value follows schema version 1. */
|
|
111
|
+
export function validateSiteMetadata(value) {
|
|
112
|
+
const problems = [];
|
|
113
|
+
if (!isRecord(value))
|
|
114
|
+
return ['metadata must be an object'];
|
|
115
|
+
for (const key of Object.keys(value)) {
|
|
116
|
+
if (!TOP_LEVEL_KEYS.includes(key))
|
|
117
|
+
problems.push(`unexpected top-level field "${key}"`);
|
|
118
|
+
}
|
|
119
|
+
if (value.schemaVersion !== SITE_METADATA_SCHEMA_VERSION)
|
|
120
|
+
problems.push('schemaVersion must be 1');
|
|
121
|
+
const generator = isRecord(value.generator) ? value.generator : {};
|
|
122
|
+
for (const key of ['name', 'version']) {
|
|
123
|
+
if (!trimmed(generator[key]))
|
|
124
|
+
problems.push(`generator.${key} must be a non-empty string`);
|
|
125
|
+
}
|
|
126
|
+
const site = isRecord(value.site) ? value.site : {};
|
|
127
|
+
if (!trimmed(site.name))
|
|
128
|
+
problems.push('site.name must be a non-empty string');
|
|
129
|
+
if (typeof site.url !== 'string' || !/^https?:\/\//u.test(site.url))
|
|
130
|
+
problems.push('site.url must be an absolute HTTP(S) URL');
|
|
131
|
+
if (typeof site.base !== 'string' || !/^\/(?:.*\/)?$/u.test(site.base))
|
|
132
|
+
problems.push('site.base must start and end with "/"');
|
|
133
|
+
if (site.description !== undefined && !trimmed(site.description))
|
|
134
|
+
problems.push('site.description must be a non-empty string when present');
|
|
135
|
+
const languages = isRecord(value.languages) ? value.languages : {};
|
|
136
|
+
const locales = Array.isArray(languages.locales) ? languages.locales : [];
|
|
137
|
+
if (locales.length === 0)
|
|
138
|
+
problems.push('languages.locales must be a non-empty array');
|
|
139
|
+
const codes = new Set();
|
|
140
|
+
for (const locale of locales) {
|
|
141
|
+
const entry = isRecord(locale) ? locale : {};
|
|
142
|
+
if (!trimmed(entry.code))
|
|
143
|
+
problems.push('languages.locales[].code must be a non-empty string');
|
|
144
|
+
else
|
|
145
|
+
codes.add(entry.code);
|
|
146
|
+
if (typeof entry.lang !== 'string' || canonicalLang(entry.lang) === undefined)
|
|
147
|
+
problems.push('languages.locales[].lang must be a BCP 47 tag');
|
|
148
|
+
if (typeof entry.path !== 'string' || !/^\/(?:.*\/)?$/u.test(entry.path))
|
|
149
|
+
problems.push('languages.locales[].path must start and end with "/"');
|
|
150
|
+
}
|
|
151
|
+
if (typeof languages.default !== 'string' || (locales.length > 0 && !codes.has(languages.default))) {
|
|
152
|
+
problems.push('languages.default must match one of languages.locales[].code');
|
|
153
|
+
}
|
|
154
|
+
const build = isRecord(value.build) ? value.build : {};
|
|
155
|
+
for (const key of ['branch', 'commit', 'builtAt']) {
|
|
156
|
+
if (!trimmed(build[key]))
|
|
157
|
+
problems.push(`build.${key} must be a non-empty string`);
|
|
158
|
+
}
|
|
159
|
+
const discovery = isRecord(value.discovery) ? value.discovery : {};
|
|
160
|
+
for (const key of Object.keys(discovery)) {
|
|
161
|
+
if (!DISCOVERY_KEYS.includes(key))
|
|
162
|
+
problems.push(`unexpected discovery field "${key}"`);
|
|
163
|
+
else if (typeof discovery[key] !== 'string' || !discovery[key].startsWith('/'))
|
|
164
|
+
problems.push(`discovery.${key} must be a site-relative path`);
|
|
165
|
+
}
|
|
166
|
+
const analytics = isRecord(value.analytics) ? value.analytics : {};
|
|
167
|
+
for (const key of ANALYTICS_KEYS) {
|
|
168
|
+
if (typeof analytics[key] !== 'boolean')
|
|
169
|
+
problems.push(`analytics.${key} must be a boolean`);
|
|
170
|
+
}
|
|
171
|
+
const features = isRecord(value.features) ? value.features : {};
|
|
172
|
+
for (const key of FEATURE_KEYS) {
|
|
173
|
+
if (features[key] !== undefined && typeof features[key] !== 'boolean')
|
|
174
|
+
problems.push(`features.${key} must be a boolean`);
|
|
175
|
+
}
|
|
176
|
+
return problems;
|
|
177
|
+
}
|
|
178
|
+
/** Canonical minified JSON: fixed key order, no indentation, trailing newline. Identical input gives identical bytes. */
|
|
179
|
+
export function serializeSiteMetadata(metadata) {
|
|
180
|
+
const canonical = {
|
|
181
|
+
schemaVersion: metadata.schemaVersion,
|
|
182
|
+
generator: { name: metadata.generator.name, version: metadata.generator.version },
|
|
183
|
+
site: {
|
|
184
|
+
name: metadata.site.name,
|
|
185
|
+
url: metadata.site.url,
|
|
186
|
+
base: metadata.site.base,
|
|
187
|
+
...(metadata.site.description === undefined ? {} : { description: metadata.site.description }),
|
|
188
|
+
},
|
|
189
|
+
languages: {
|
|
190
|
+
default: metadata.languages.default,
|
|
191
|
+
locales: metadata.languages.locales.map(({ code, lang, path }) => ({ code, lang, path })),
|
|
192
|
+
},
|
|
193
|
+
build: { branch: metadata.build.branch, commit: metadata.build.commit, builtAt: metadata.build.builtAt },
|
|
194
|
+
discovery: Object.fromEntries(DISCOVERY_KEYS
|
|
195
|
+
.filter((key) => metadata.discovery[key] !== undefined)
|
|
196
|
+
.map((key) => [key, metadata.discovery[key]])),
|
|
197
|
+
analytics: {
|
|
198
|
+
googleAnalytics: metadata.analytics.googleAnalytics,
|
|
199
|
+
fiftyOneLa: metadata.analytics.fiftyOneLa,
|
|
200
|
+
posthog: metadata.analytics.posthog,
|
|
201
|
+
},
|
|
202
|
+
features: Object.fromEntries(FEATURE_KEYS
|
|
203
|
+
.filter((key) => metadata.features[key] !== undefined)
|
|
204
|
+
.map((key) => [key, metadata.features[key]])),
|
|
205
|
+
};
|
|
206
|
+
return `${JSON.stringify(canonical)}\n`;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Detect which analytics loaders the built pages contain. A provider is enabled
|
|
210
|
+
* when any page carries all of its markers. Only booleans leave this function.
|
|
211
|
+
*/
|
|
212
|
+
export function detectAnalyticsLoaders(pages) {
|
|
213
|
+
const found = { googleAnalytics: false, fiftyOneLa: false, posthog: false };
|
|
214
|
+
for (const html of pages) {
|
|
215
|
+
for (const provider of ANALYTICS_KEYS) {
|
|
216
|
+
if (!found[provider] && ANALYTICS_LOADER_MARKERS[provider].every((marker) => html.includes(marker))) {
|
|
217
|
+
found[provider] = true;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return found;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Resolve the `metadata` option shared by the three packages. `undefined` and
|
|
225
|
+
* `true` enable the default output, `false` opts out, and an object may override
|
|
226
|
+
* `name` and `description`. Errors name the option.
|
|
227
|
+
*/
|
|
228
|
+
export function resolveSiteMetadataOption(value) {
|
|
229
|
+
if (value === undefined || value === true)
|
|
230
|
+
return { enabled: true };
|
|
231
|
+
if (value === false)
|
|
232
|
+
return { enabled: false };
|
|
233
|
+
if (!isRecord(value)) {
|
|
234
|
+
throw new TypeError('Hagilight metadata option must be a boolean or an options object.');
|
|
235
|
+
}
|
|
236
|
+
for (const key of Object.keys(value)) {
|
|
237
|
+
if (!['enabled', 'name', 'description'].includes(key)) {
|
|
238
|
+
throw new TypeError(`Hagilight metadata option has an unknown key "${key}".`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (value.enabled !== undefined && typeof value.enabled !== 'boolean') {
|
|
242
|
+
throw new TypeError('Hagilight metadata enabled option must be a boolean.');
|
|
243
|
+
}
|
|
244
|
+
for (const key of ['name', 'description']) {
|
|
245
|
+
if (value[key] !== undefined && !trimmed(value[key])) {
|
|
246
|
+
throw new TypeError(`Hagilight metadata ${key} must be a non-empty string.`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const name = trimmed(value.name);
|
|
250
|
+
const description = trimmed(value.description);
|
|
251
|
+
return {
|
|
252
|
+
enabled: value.enabled !== false,
|
|
253
|
+
...(name === undefined ? {} : { name }),
|
|
254
|
+
...(description === undefined ? {} : { description }),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public image contract for the img-gen `startup-splash` collection.
|
|
3
|
+
*
|
|
4
|
+
* Browser-safe: no `node:` import and no file system access. The cache storage, fetch and random source are
|
|
5
|
+
* parameters so tests can replace them. The loaders never reject: any failure reads as a miss.
|
|
6
|
+
*/
|
|
7
|
+
export interface SplashConfig {
|
|
8
|
+
readonly baseUrl: string;
|
|
9
|
+
readonly prefix: string;
|
|
10
|
+
readonly count: number;
|
|
11
|
+
readonly cacheName: string;
|
|
12
|
+
}
|
|
13
|
+
/** The overridable keys. `readBudgetMs` and `maxEntries` are fixed defaults, not consumer options. */
|
|
14
|
+
export interface SplashOverrides {
|
|
15
|
+
readonly baseUrl?: string;
|
|
16
|
+
readonly prefix?: string;
|
|
17
|
+
readonly count?: number;
|
|
18
|
+
readonly cacheName?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare const SPLASH_IMAGE_DEFAULTS: Readonly<{
|
|
21
|
+
baseUrl: "https://img-gen.hagicode.com";
|
|
22
|
+
prefix: "startup-splash";
|
|
23
|
+
count: 600;
|
|
24
|
+
cacheName: "hagilight.rootTransit.splash";
|
|
25
|
+
readBudgetMs: 100;
|
|
26
|
+
maxEntries: 30;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Resolves the `splash` option. `false` disables the splash (returns null); `undefined` gives the defaults; an
|
|
30
|
+
* object overrides the listed keys. Throws a `TypeError` for any invalid value, so bad config fails the build.
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveSplashConfig(input?: false | SplashOverrides): SplashConfig | null;
|
|
33
|
+
/** Maps an index from 1 to `count` to its key, for example 7 to `hagicode-splash-007`. */
|
|
34
|
+
export declare function splashKey(index: number, count?: number): string;
|
|
35
|
+
/**
|
|
36
|
+
* The path below the base URL, `<prefix>/<key>.avif`, for a key or an index. A string must be a key of the
|
|
37
|
+
* collection: `hagicode-splash-` followed by its number, padded to three digits, within the count.
|
|
38
|
+
*/
|
|
39
|
+
export declare function splashImagePath(keyOrIndex: number | string, config?: SplashConfig): string;
|
|
40
|
+
/** The full image URL: the base URL joined with `splashImagePath`. */
|
|
41
|
+
export declare function splashImageUrl(keyOrIndex: number | string, config?: SplashConfig): string;
|
|
42
|
+
/**
|
|
43
|
+
* A 1-based index from `random`, which returns a value in [0, 1). Out-of-range or non-finite results are clamped,
|
|
44
|
+
* so the result is always within 1 to `count`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function pickSplashIndex(random?: () => number, count?: number): number;
|
|
47
|
+
export interface SplashStorageOptions {
|
|
48
|
+
/** `undefined` uses the global `caches`; `null` means no cache (every read is a miss). */
|
|
49
|
+
readonly storage?: CacheStorage | null;
|
|
50
|
+
readonly cacheName?: string;
|
|
51
|
+
readonly budgetMs?: number;
|
|
52
|
+
readonly maxEntries?: number;
|
|
53
|
+
}
|
|
54
|
+
export type SplashLoad = {
|
|
55
|
+
readonly source: 'cache';
|
|
56
|
+
readonly blob: Blob;
|
|
57
|
+
} | {
|
|
58
|
+
readonly source: 'miss';
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Reads `url` from the Cache API within the read budget. A hit gives the cached blob; anything else (no cache, no
|
|
62
|
+
* entry, a read error or a read that is not done within the budget) gives `miss`, and the caller loads the URL
|
|
63
|
+
* from the network. Keyed by the full URL, so a changed host or prefix never reads an old entry. Never rejects.
|
|
64
|
+
*/
|
|
65
|
+
export declare function loadSplashImage(url: string, options?: SplashStorageOptions): Promise<SplashLoad>;
|
|
66
|
+
export interface SplashStoreOptions extends SplashStorageOptions {
|
|
67
|
+
/** Defaults to a CORS `fetch` with no credentials. */
|
|
68
|
+
readonly fetchImage?: (url: string) => Promise<Response>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Downloads `url` and stores the image under that URL, then trims the cache to `maxEntries`, oldest first. A
|
|
72
|
+
* response that is not OK, or has an empty body, stores nothing. Returns whether an entry was written. Never
|
|
73
|
+
* rejects, so a missing CORS header or an unavailable cache is a `false`, not an error.
|
|
74
|
+
*/
|
|
75
|
+
export declare function storeSplashImage(url: string, options?: SplashStoreOptions): Promise<boolean>;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public image contract for the img-gen `startup-splash` collection.
|
|
3
|
+
*
|
|
4
|
+
* Browser-safe: no `node:` import and no file system access. The cache storage, fetch and random source are
|
|
5
|
+
* parameters so tests can replace them. The loaders never reject: any failure reads as a miss.
|
|
6
|
+
*/
|
|
7
|
+
export const SPLASH_IMAGE_DEFAULTS = Object.freeze({
|
|
8
|
+
baseUrl: 'https://img-gen.hagicode.com',
|
|
9
|
+
prefix: 'startup-splash',
|
|
10
|
+
count: 600,
|
|
11
|
+
cacheName: 'hagilight.rootTransit.splash',
|
|
12
|
+
readBudgetMs: 100,
|
|
13
|
+
maxEntries: 30,
|
|
14
|
+
});
|
|
15
|
+
const KEY_PREFIX = 'hagicode-splash-';
|
|
16
|
+
const KEY_PATTERN = /^hagicode-splash-(\d{3,4})$/u;
|
|
17
|
+
const PREFIX_PATTERN = /^[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/u;
|
|
18
|
+
const MAX_COUNT = 9999;
|
|
19
|
+
const fail = (reason) => {
|
|
20
|
+
throw new TypeError(`Hagilight RootTransit: ${reason}`);
|
|
21
|
+
};
|
|
22
|
+
const DEFAULT_CONFIG = Object.freeze({
|
|
23
|
+
baseUrl: SPLASH_IMAGE_DEFAULTS.baseUrl,
|
|
24
|
+
prefix: SPLASH_IMAGE_DEFAULTS.prefix,
|
|
25
|
+
count: SPLASH_IMAGE_DEFAULTS.count,
|
|
26
|
+
cacheName: SPLASH_IMAGE_DEFAULTS.cacheName,
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Resolves the `splash` option. `false` disables the splash (returns null); `undefined` gives the defaults; an
|
|
30
|
+
* object overrides the listed keys. Throws a `TypeError` for any invalid value, so bad config fails the build.
|
|
31
|
+
*/
|
|
32
|
+
export function resolveSplashConfig(input) {
|
|
33
|
+
if (input === false)
|
|
34
|
+
return null;
|
|
35
|
+
if (input === undefined)
|
|
36
|
+
return DEFAULT_CONFIG;
|
|
37
|
+
if (typeof input !== 'object' || input === null)
|
|
38
|
+
fail('splash must be false or an options object.');
|
|
39
|
+
const allowed = new Set(['baseUrl', 'prefix', 'count', 'cacheName']);
|
|
40
|
+
for (const key of Object.keys(input)) {
|
|
41
|
+
if (!allowed.has(key))
|
|
42
|
+
fail(`splash has an unknown option "${key}".`);
|
|
43
|
+
}
|
|
44
|
+
const baseUrl = input.baseUrl ?? DEFAULT_CONFIG.baseUrl;
|
|
45
|
+
let url;
|
|
46
|
+
try {
|
|
47
|
+
url = new URL(baseUrl);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return fail('splash baseUrl must be an absolute URL.');
|
|
51
|
+
}
|
|
52
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash) {
|
|
53
|
+
fail('splash baseUrl must be HTTPS without credentials, query or fragment.');
|
|
54
|
+
}
|
|
55
|
+
const prefix = input.prefix ?? DEFAULT_CONFIG.prefix;
|
|
56
|
+
if (!PREFIX_PATTERN.test(prefix) || prefix.split('/').some((segment) => segment === '.' || segment === '..')) {
|
|
57
|
+
fail('splash prefix must be letters, digits, dots, underscores and hyphens joined by slashes.');
|
|
58
|
+
}
|
|
59
|
+
const count = input.count ?? DEFAULT_CONFIG.count;
|
|
60
|
+
if (!Number.isInteger(count) || count < 1 || count > MAX_COUNT) {
|
|
61
|
+
fail(`splash count must be an integer from 1 to ${MAX_COUNT}.`);
|
|
62
|
+
}
|
|
63
|
+
const cacheName = input.cacheName ?? DEFAULT_CONFIG.cacheName;
|
|
64
|
+
if (typeof cacheName !== 'string' || !cacheName.trim())
|
|
65
|
+
fail('splash cacheName must be a non-empty string.');
|
|
66
|
+
return Object.freeze({
|
|
67
|
+
baseUrl: `${url.origin}${url.pathname.replace(/\/+$/u, '')}`,
|
|
68
|
+
prefix,
|
|
69
|
+
count,
|
|
70
|
+
cacheName,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/** Maps an index from 1 to `count` to its key, for example 7 to `hagicode-splash-007`. */
|
|
74
|
+
export function splashKey(index, count = SPLASH_IMAGE_DEFAULTS.count) {
|
|
75
|
+
if (!Number.isInteger(index) || index < 1 || index > count) {
|
|
76
|
+
fail(`splash index must be an integer from 1 to ${count}.`);
|
|
77
|
+
}
|
|
78
|
+
return `${KEY_PREFIX}${String(index).padStart(3, '0')}`;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The path below the base URL, `<prefix>/<key>.avif`, for a key or an index. A string must be a key of the
|
|
82
|
+
* collection: `hagicode-splash-` followed by its number, padded to three digits, within the count.
|
|
83
|
+
*/
|
|
84
|
+
export function splashImagePath(keyOrIndex, config = DEFAULT_CONFIG) {
|
|
85
|
+
const key = typeof keyOrIndex === 'number' ? splashKey(keyOrIndex, config.count) : canonicalKey(keyOrIndex, config.count);
|
|
86
|
+
return `${config.prefix}/${key}.avif`;
|
|
87
|
+
}
|
|
88
|
+
/** The full image URL: the base URL joined with `splashImagePath`. */
|
|
89
|
+
export function splashImageUrl(keyOrIndex, config = DEFAULT_CONFIG) {
|
|
90
|
+
return `${config.baseUrl}/${splashImagePath(keyOrIndex, config)}`;
|
|
91
|
+
}
|
|
92
|
+
function canonicalKey(key, count) {
|
|
93
|
+
const match = KEY_PATTERN.exec(key);
|
|
94
|
+
if (!match || splashKey(Number(match[1]), count) !== key) {
|
|
95
|
+
fail(`splash key must be ${KEY_PREFIX}NNN within 1 to ${count}.`);
|
|
96
|
+
}
|
|
97
|
+
return key;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A 1-based index from `random`, which returns a value in [0, 1). Out-of-range or non-finite results are clamped,
|
|
101
|
+
* so the result is always within 1 to `count`.
|
|
102
|
+
*/
|
|
103
|
+
export function pickSplashIndex(random = Math.random, count = SPLASH_IMAGE_DEFAULTS.count) {
|
|
104
|
+
const value = random();
|
|
105
|
+
const fraction = Number.isFinite(value) ? Math.min(Math.max(value, 0), 1 - Number.EPSILON) : 0;
|
|
106
|
+
return 1 + Math.floor(fraction * count);
|
|
107
|
+
}
|
|
108
|
+
const MISS = Object.freeze({ source: 'miss' });
|
|
109
|
+
function resolveStorage(storage) {
|
|
110
|
+
if (storage !== undefined)
|
|
111
|
+
return storage;
|
|
112
|
+
try {
|
|
113
|
+
return typeof caches === 'undefined' ? null : caches;
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Reads `url` from the Cache API within the read budget. A hit gives the cached blob; anything else (no cache, no
|
|
121
|
+
* entry, a read error or a read that is not done within the budget) gives `miss`, and the caller loads the URL
|
|
122
|
+
* from the network. Keyed by the full URL, so a changed host or prefix never reads an old entry. Never rejects.
|
|
123
|
+
*/
|
|
124
|
+
export async function loadSplashImage(url, options = {}) {
|
|
125
|
+
const storage = resolveStorage(options.storage);
|
|
126
|
+
if (!storage)
|
|
127
|
+
return MISS;
|
|
128
|
+
const cacheName = options.cacheName ?? SPLASH_IMAGE_DEFAULTS.cacheName;
|
|
129
|
+
const lookup = (async () => {
|
|
130
|
+
try {
|
|
131
|
+
const cache = await storage.open(cacheName);
|
|
132
|
+
const response = await cache.match(url);
|
|
133
|
+
if (!response?.ok)
|
|
134
|
+
return MISS;
|
|
135
|
+
const blob = await response.blob();
|
|
136
|
+
return blob.size > 0 ? { source: 'cache', blob } : MISS;
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return MISS;
|
|
140
|
+
}
|
|
141
|
+
})();
|
|
142
|
+
let timer;
|
|
143
|
+
const budget = new Promise((resolve) => {
|
|
144
|
+
timer = setTimeout(() => resolve(MISS), options.budgetMs ?? SPLASH_IMAGE_DEFAULTS.readBudgetMs);
|
|
145
|
+
});
|
|
146
|
+
try {
|
|
147
|
+
return await Promise.race([lookup, budget]);
|
|
148
|
+
}
|
|
149
|
+
finally {
|
|
150
|
+
clearTimeout(timer);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Downloads `url` and stores the image under that URL, then trims the cache to `maxEntries`, oldest first. A
|
|
155
|
+
* response that is not OK, or has an empty body, stores nothing. Returns whether an entry was written. Never
|
|
156
|
+
* rejects, so a missing CORS header or an unavailable cache is a `false`, not an error.
|
|
157
|
+
*/
|
|
158
|
+
export async function storeSplashImage(url, options = {}) {
|
|
159
|
+
const storage = resolveStorage(options.storage);
|
|
160
|
+
if (!storage)
|
|
161
|
+
return false;
|
|
162
|
+
try {
|
|
163
|
+
const fetchImage = options.fetchImage ?? ((target) => fetch(target, { mode: 'cors', credentials: 'omit' }));
|
|
164
|
+
const response = await fetchImage(url);
|
|
165
|
+
if (!response.ok)
|
|
166
|
+
return false;
|
|
167
|
+
const blob = await response.blob();
|
|
168
|
+
if (blob.size === 0)
|
|
169
|
+
return false;
|
|
170
|
+
const cache = await storage.open(options.cacheName ?? SPLASH_IMAGE_DEFAULTS.cacheName);
|
|
171
|
+
// Delete first so a re-stored entry moves to the end of the insertion order that trimming relies on.
|
|
172
|
+
await cache.delete(url);
|
|
173
|
+
await cache.put(url, new Response(blob));
|
|
174
|
+
await trimCache(cache, options.maxEntries ?? SPLASH_IMAGE_DEFAULTS.maxEntries);
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async function trimCache(cache, maxEntries) {
|
|
182
|
+
const keys = await cache.keys();
|
|
183
|
+
for (const oldest of keys.slice(0, Math.max(0, keys.length - maxEntries))) {
|
|
184
|
+
await cache.delete(oldest);
|
|
185
|
+
}
|
|
186
|
+
}
|
package/favicon.ico
ADDED
|
Binary file
|
package/logo.png
ADDED
|
Binary file
|