@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.
Files changed (205) hide show
  1. package/Analytics51LA.astro +17 -0
  2. package/Copyright.astro +9 -0
  3. package/Footer.astro +208 -0
  4. package/FooterAvatarPicker.astro +9 -0
  5. package/FooterBrand.astro +339 -0
  6. package/GoogleAnalytics.astro +30 -0
  7. package/PostHog.astro +11 -0
  8. package/PromotoBanner.astro +582 -0
  9. package/README.md +485 -0
  10. package/RootTransit.astro +599 -0
  11. package/assets/footer/avatar.avif +0 -0
  12. package/assets/footer/avatar.webp +0 -0
  13. package/assets/footer/manifest.json +237 -0
  14. package/data/comparison-articles/de-DE/claude-vs-hagicode.json +294 -0
  15. package/data/comparison-articles/de-DE/codebuddy-vs-hagicode.json +266 -0
  16. package/data/comparison-articles/de-DE/codex-vs-hagicode.json +266 -0
  17. package/data/comparison-articles/de-DE/copilot-vs-hagicode.json +266 -0
  18. package/data/comparison-articles/de-DE/deepagents-vs-hagicode.json +266 -0
  19. package/data/comparison-articles/de-DE/gemini-vs-hagicode.json +266 -0
  20. package/data/comparison-articles/de-DE/hermes-vs-hagicode.json +266 -0
  21. package/data/comparison-articles/de-DE/kimi-vs-hagicode.json +266 -0
  22. package/data/comparison-articles/de-DE/kiro-vs-hagicode.json +266 -0
  23. package/data/comparison-articles/de-DE/opencode-vs-hagicode.json +266 -0
  24. package/data/comparison-articles/de-DE/pi-vs-hagicode.json +282 -0
  25. package/data/comparison-articles/de-DE/qoder-vs-hagicode.json +266 -0
  26. package/data/comparison-articles/de-DE/reasonix-vs-hagicode.json +281 -0
  27. package/data/comparison-articles/en-US/claude-vs-hagicode.json +346 -0
  28. package/data/comparison-articles/en-US/codebuddy-vs-hagicode.json +322 -0
  29. package/data/comparison-articles/en-US/codex-vs-hagicode.json +321 -0
  30. package/data/comparison-articles/en-US/copilot-vs-hagicode.json +320 -0
  31. package/data/comparison-articles/en-US/deepagents-vs-hagicode.json +323 -0
  32. package/data/comparison-articles/en-US/dsh-vs-hagicode.json +323 -0
  33. package/data/comparison-articles/en-US/gemini-vs-hagicode.json +320 -0
  34. package/data/comparison-articles/en-US/hermes-vs-hagicode.json +323 -0
  35. package/data/comparison-articles/en-US/junie-vs-hagicode.json +323 -0
  36. package/data/comparison-articles/en-US/kimi-vs-hagicode.json +319 -0
  37. package/data/comparison-articles/en-US/kiro-vs-hagicode.json +319 -0
  38. package/data/comparison-articles/en-US/omp-vs-hagicode.json +345 -0
  39. package/data/comparison-articles/en-US/opencode-vs-hagicode.json +333 -0
  40. package/data/comparison-articles/en-US/pi-vs-hagicode.json +345 -0
  41. package/data/comparison-articles/en-US/qoder-vs-hagicode.json +323 -0
  42. package/data/comparison-articles/en-US/reasonix-vs-hagicode.json +344 -0
  43. package/data/comparison-articles/es-ES/claude-vs-hagicode.json +294 -0
  44. package/data/comparison-articles/es-ES/codebuddy-vs-hagicode.json +266 -0
  45. package/data/comparison-articles/es-ES/codex-vs-hagicode.json +266 -0
  46. package/data/comparison-articles/es-ES/copilot-vs-hagicode.json +266 -0
  47. package/data/comparison-articles/es-ES/deepagents-vs-hagicode.json +266 -0
  48. package/data/comparison-articles/es-ES/gemini-vs-hagicode.json +266 -0
  49. package/data/comparison-articles/es-ES/hermes-vs-hagicode.json +266 -0
  50. package/data/comparison-articles/es-ES/kimi-vs-hagicode.json +266 -0
  51. package/data/comparison-articles/es-ES/kiro-vs-hagicode.json +266 -0
  52. package/data/comparison-articles/es-ES/opencode-vs-hagicode.json +266 -0
  53. package/data/comparison-articles/es-ES/pi-vs-hagicode.json +281 -0
  54. package/data/comparison-articles/es-ES/qoder-vs-hagicode.json +266 -0
  55. package/data/comparison-articles/es-ES/reasonix-vs-hagicode.json +281 -0
  56. package/data/comparison-articles/fr-FR/claude-vs-hagicode.json +294 -0
  57. package/data/comparison-articles/fr-FR/codebuddy-vs-hagicode.json +266 -0
  58. package/data/comparison-articles/fr-FR/codex-vs-hagicode.json +266 -0
  59. package/data/comparison-articles/fr-FR/copilot-vs-hagicode.json +266 -0
  60. package/data/comparison-articles/fr-FR/deepagents-vs-hagicode.json +266 -0
  61. package/data/comparison-articles/fr-FR/gemini-vs-hagicode.json +266 -0
  62. package/data/comparison-articles/fr-FR/hermes-vs-hagicode.json +266 -0
  63. package/data/comparison-articles/fr-FR/kimi-vs-hagicode.json +266 -0
  64. package/data/comparison-articles/fr-FR/kiro-vs-hagicode.json +266 -0
  65. package/data/comparison-articles/fr-FR/opencode-vs-hagicode.json +266 -0
  66. package/data/comparison-articles/fr-FR/pi-vs-hagicode.json +281 -0
  67. package/data/comparison-articles/fr-FR/qoder-vs-hagicode.json +266 -0
  68. package/data/comparison-articles/fr-FR/reasonix-vs-hagicode.json +281 -0
  69. package/data/comparison-articles/ja-JP/claude-vs-hagicode.json +294 -0
  70. package/data/comparison-articles/ja-JP/codebuddy-vs-hagicode.json +266 -0
  71. package/data/comparison-articles/ja-JP/codex-vs-hagicode.json +266 -0
  72. package/data/comparison-articles/ja-JP/copilot-vs-hagicode.json +266 -0
  73. package/data/comparison-articles/ja-JP/deepagents-vs-hagicode.json +266 -0
  74. package/data/comparison-articles/ja-JP/gemini-vs-hagicode.json +266 -0
  75. package/data/comparison-articles/ja-JP/hermes-vs-hagicode.json +266 -0
  76. package/data/comparison-articles/ja-JP/kimi-vs-hagicode.json +266 -0
  77. package/data/comparison-articles/ja-JP/kiro-vs-hagicode.json +266 -0
  78. package/data/comparison-articles/ja-JP/opencode-vs-hagicode.json +266 -0
  79. package/data/comparison-articles/ja-JP/pi-vs-hagicode.json +281 -0
  80. package/data/comparison-articles/ja-JP/qoder-vs-hagicode.json +266 -0
  81. package/data/comparison-articles/ja-JP/reasonix-vs-hagicode.json +281 -0
  82. package/data/comparison-articles/ko-KR/claude-vs-hagicode.json +294 -0
  83. package/data/comparison-articles/ko-KR/codebuddy-vs-hagicode.json +266 -0
  84. package/data/comparison-articles/ko-KR/codex-vs-hagicode.json +266 -0
  85. package/data/comparison-articles/ko-KR/copilot-vs-hagicode.json +266 -0
  86. package/data/comparison-articles/ko-KR/deepagents-vs-hagicode.json +266 -0
  87. package/data/comparison-articles/ko-KR/gemini-vs-hagicode.json +266 -0
  88. package/data/comparison-articles/ko-KR/hermes-vs-hagicode.json +266 -0
  89. package/data/comparison-articles/ko-KR/kimi-vs-hagicode.json +266 -0
  90. package/data/comparison-articles/ko-KR/kiro-vs-hagicode.json +266 -0
  91. package/data/comparison-articles/ko-KR/opencode-vs-hagicode.json +266 -0
  92. package/data/comparison-articles/ko-KR/pi-vs-hagicode.json +281 -0
  93. package/data/comparison-articles/ko-KR/qoder-vs-hagicode.json +266 -0
  94. package/data/comparison-articles/ko-KR/reasonix-vs-hagicode.json +281 -0
  95. package/data/comparison-articles/pt-BR/claude-vs-hagicode.json +294 -0
  96. package/data/comparison-articles/pt-BR/codebuddy-vs-hagicode.json +266 -0
  97. package/data/comparison-articles/pt-BR/codex-vs-hagicode.json +266 -0
  98. package/data/comparison-articles/pt-BR/copilot-vs-hagicode.json +266 -0
  99. package/data/comparison-articles/pt-BR/deepagents-vs-hagicode.json +266 -0
  100. package/data/comparison-articles/pt-BR/gemini-vs-hagicode.json +266 -0
  101. package/data/comparison-articles/pt-BR/hermes-vs-hagicode.json +266 -0
  102. package/data/comparison-articles/pt-BR/kimi-vs-hagicode.json +266 -0
  103. package/data/comparison-articles/pt-BR/kiro-vs-hagicode.json +266 -0
  104. package/data/comparison-articles/pt-BR/opencode-vs-hagicode.json +266 -0
  105. package/data/comparison-articles/pt-BR/pi-vs-hagicode.json +281 -0
  106. package/data/comparison-articles/pt-BR/qoder-vs-hagicode.json +266 -0
  107. package/data/comparison-articles/pt-BR/reasonix-vs-hagicode.json +281 -0
  108. package/data/comparison-articles/ru-RU/claude-vs-hagicode.json +294 -0
  109. package/data/comparison-articles/ru-RU/codebuddy-vs-hagicode.json +266 -0
  110. package/data/comparison-articles/ru-RU/codex-vs-hagicode.json +266 -0
  111. package/data/comparison-articles/ru-RU/copilot-vs-hagicode.json +266 -0
  112. package/data/comparison-articles/ru-RU/deepagents-vs-hagicode.json +266 -0
  113. package/data/comparison-articles/ru-RU/gemini-vs-hagicode.json +266 -0
  114. package/data/comparison-articles/ru-RU/hermes-vs-hagicode.json +266 -0
  115. package/data/comparison-articles/ru-RU/kimi-vs-hagicode.json +266 -0
  116. package/data/comparison-articles/ru-RU/kiro-vs-hagicode.json +266 -0
  117. package/data/comparison-articles/ru-RU/opencode-vs-hagicode.json +266 -0
  118. package/data/comparison-articles/ru-RU/pi-vs-hagicode.json +281 -0
  119. package/data/comparison-articles/ru-RU/qoder-vs-hagicode.json +323 -0
  120. package/data/comparison-articles/ru-RU/reasonix-vs-hagicode.json +281 -0
  121. package/data/comparison-articles/zh-CN/claude-vs-hagicode.json +346 -0
  122. package/data/comparison-articles/zh-CN/codebuddy-vs-hagicode.json +322 -0
  123. package/data/comparison-articles/zh-CN/codex-vs-hagicode.json +321 -0
  124. package/data/comparison-articles/zh-CN/copilot-vs-hagicode.json +320 -0
  125. package/data/comparison-articles/zh-CN/deepagents-vs-hagicode.json +323 -0
  126. package/data/comparison-articles/zh-CN/dsh-vs-hagicode.json +323 -0
  127. package/data/comparison-articles/zh-CN/gemini-vs-hagicode.json +320 -0
  128. package/data/comparison-articles/zh-CN/hermes-vs-hagicode.json +323 -0
  129. package/data/comparison-articles/zh-CN/junie-vs-hagicode.json +323 -0
  130. package/data/comparison-articles/zh-CN/kimi-vs-hagicode.json +319 -0
  131. package/data/comparison-articles/zh-CN/kiro-vs-hagicode.json +319 -0
  132. package/data/comparison-articles/zh-CN/omp-vs-hagicode.json +345 -0
  133. package/data/comparison-articles/zh-CN/opencode-vs-hagicode.json +333 -0
  134. package/data/comparison-articles/zh-CN/pi-vs-hagicode.json +345 -0
  135. package/data/comparison-articles/zh-CN/qoder-vs-hagicode.json +323 -0
  136. package/data/comparison-articles/zh-CN/reasonix-vs-hagicode.json +344 -0
  137. package/data/comparison-articles/zh-Hant/claude-vs-hagicode.json +294 -0
  138. package/data/comparison-articles/zh-Hant/codebuddy-vs-hagicode.json +266 -0
  139. package/data/comparison-articles/zh-Hant/codex-vs-hagicode.json +266 -0
  140. package/data/comparison-articles/zh-Hant/copilot-vs-hagicode.json +266 -0
  141. package/data/comparison-articles/zh-Hant/deepagents-vs-hagicode.json +266 -0
  142. package/data/comparison-articles/zh-Hant/gemini-vs-hagicode.json +266 -0
  143. package/data/comparison-articles/zh-Hant/hermes-vs-hagicode.json +266 -0
  144. package/data/comparison-articles/zh-Hant/kimi-vs-hagicode.json +266 -0
  145. package/data/comparison-articles/zh-Hant/kiro-vs-hagicode.json +266 -0
  146. package/data/comparison-articles/zh-Hant/opencode-vs-hagicode.json +266 -0
  147. package/data/comparison-articles/zh-Hant/pi-vs-hagicode.json +281 -0
  148. package/data/comparison-articles/zh-Hant/qoder-vs-hagicode.json +266 -0
  149. package/data/comparison-articles/zh-Hant/reasonix-vs-hagicode.json +281 -0
  150. package/dist/analytics-events.d.ts +49 -0
  151. package/dist/analytics-events.js +113 -0
  152. package/dist/build-info-resolver.d.ts +8 -0
  153. package/dist/build-info-resolver.js +29 -0
  154. package/dist/build-info.d.ts +19 -0
  155. package/dist/build-info.js +60 -0
  156. package/dist/comparison-articles-source.d.ts +13 -0
  157. package/dist/comparison-articles-source.js +58 -0
  158. package/dist/comparison-articles.d.ts +127 -0
  159. package/dist/comparison-articles.js +260 -0
  160. package/dist/content-images.d.ts +126 -0
  161. package/dist/content-images.js +490 -0
  162. package/dist/favicon.d.ts +21 -0
  163. package/dist/favicon.js +27 -0
  164. package/dist/footer-avatar.d.ts +39 -0
  165. package/dist/footer-avatar.js +42 -0
  166. package/dist/footer-brand.d.ts +29 -0
  167. package/dist/footer-brand.js +86 -0
  168. package/dist/head.d.ts +7 -0
  169. package/dist/head.js +1 -0
  170. package/dist/link-policy.d.ts +33 -0
  171. package/dist/link-policy.js +93 -0
  172. package/dist/links.d.ts +70 -0
  173. package/dist/links.js +425 -0
  174. package/dist/posthog.d.ts +6 -0
  175. package/dist/posthog.js +17 -0
  176. package/dist/promotions.d.ts +50 -0
  177. package/dist/promotions.js +243 -0
  178. package/dist/promoto-banner.d.ts +14 -0
  179. package/dist/promoto-banner.js +499 -0
  180. package/dist/random-image.d.ts +69 -0
  181. package/dist/random-image.js +133 -0
  182. package/dist/related-sites.json +378 -0
  183. package/dist/root-transit.d.ts +12 -0
  184. package/dist/root-transit.js +221 -0
  185. package/dist/rss-footer-context.d.ts +6 -0
  186. package/dist/rss-footer-context.js +54 -0
  187. package/dist/rss-ownership.d.ts +26 -0
  188. package/dist/rss-ownership.js +63 -0
  189. package/dist/rss.d.ts +34 -0
  190. package/dist/rss.js +145 -0
  191. package/dist/seo-schema.d.ts +12 -0
  192. package/dist/seo-schema.js +20 -0
  193. package/dist/seo.d.ts +78 -0
  194. package/dist/seo.js +270 -0
  195. package/dist/site-metadata-ownership.d.ts +40 -0
  196. package/dist/site-metadata-ownership.js +72 -0
  197. package/dist/site-metadata-writer.d.ts +25 -0
  198. package/dist/site-metadata-writer.js +55 -0
  199. package/dist/site-metadata.d.ts +113 -0
  200. package/dist/site-metadata.js +256 -0
  201. package/dist/splash-images.d.ts +75 -0
  202. package/dist/splash-images.js +186 -0
  203. package/favicon.ico +0 -0
  204. package/logo.png +0 -0
  205. package/package.json +172 -0
@@ -0,0 +1,221 @@
1
+ import { SPLASH_IMAGE_DEFAULTS, loadSplashImage, pickSplashIndex, splashImageUrl, storeSplashImage, } from './splash-images.js';
2
+ /** The reference route sweep (1,250 ms) and finished-state hold (320 ms). */
3
+ export const ROOT_TRANSIT_DELAY_MS = 1570;
4
+ /** Idle-time limit for storing a loaded splash image, so the store never waits on the page. */
5
+ const SPLASH_STORE_IDLE_TIMEOUT_MS = 1000;
6
+ /** Resolve a configured local route, applying the deployment base at most once. */
7
+ export function resolveTransitDestination(destination, { site, base = '/' }) {
8
+ const fail = (reason) => { throw new TypeError(`Hagilight RootTransit: ${reason}`); };
9
+ if (typeof destination !== 'string' || !destination.trim())
10
+ fail('destination is required.');
11
+ const input = destination.trim();
12
+ if (/[\u0000-\u0020\\]/u.test(input))
13
+ fail('destination must not contain whitespace, control characters or backslashes.');
14
+ const origin = new URL(site);
15
+ if (!['http:', 'https:'].includes(origin.protocol))
16
+ fail('site must use HTTP(S).');
17
+ if (!/^\/(?!\/)/u.test(base) || /[?#\\\u0000-\u0020]/u.test(base))
18
+ fail('base must be an absolute local pathname.');
19
+ const baseUrl = new URL(`${base.replace(/\/+$/u, '')}/`, origin.origin);
20
+ const absolute = /^[a-z][a-z\d+.-]*:|^\/\//iu.test(input);
21
+ const alreadyBased = input === baseUrl.pathname.slice(0, -1) || input.startsWith(baseUrl.pathname);
22
+ let target;
23
+ try {
24
+ target = new URL(absolute || alreadyBased ? input : input.replace(/^\//u, ''), absolute || alreadyBased ? origin.origin : baseUrl);
25
+ }
26
+ catch {
27
+ return fail('destination must be a valid local URL.');
28
+ }
29
+ if (!['http:', 'https:'].includes(target.protocol) || target.origin !== origin.origin || target.username || target.password) {
30
+ fail('destination must be an HTTP(S) URL on the configured site origin.');
31
+ }
32
+ target.pathname = target.pathname.replace(/\/{2,}/gu, '/');
33
+ if (/%(?:2f|5c)/iu.test(target.pathname))
34
+ fail('destination must not contain encoded path separators.');
35
+ let decoded;
36
+ try {
37
+ decoded = decodeURIComponent(target.pathname);
38
+ }
39
+ catch {
40
+ return fail('destination contains invalid path encoding.');
41
+ }
42
+ const root = decodeURIComponent(baseUrl.pathname).replace(/\/$/u, '');
43
+ if (decoded.replace(/\/(?:index\.html?)?\/?$/iu, '') === root)
44
+ fail('destination must not resolve to the transit root.');
45
+ if (!target.pathname.startsWith(baseUrl.pathname))
46
+ fail('destination must stay inside the deployment base.');
47
+ return `${target.pathname}${target.search}${target.hash}`;
48
+ }
49
+ /** Browser-only search/fragment replace configured values when present. */
50
+ export function resolveTransitNavigation(destination, current, base = '/') {
51
+ const target = new URL(resolveTransitDestination(destination, { site: current, base }), current);
52
+ if (current.search)
53
+ target.search = current.search;
54
+ if (current.hash)
55
+ target.hash = current.hash;
56
+ return `${target.pathname}${target.search}${target.hash}`;
57
+ }
58
+ const mounted = new WeakMap();
59
+ /**
60
+ * The decorative splash: one random image, started from a macrotask after the page is mounted. Nothing awaits it.
61
+ * A failed first image is retried once with another key; a second failure removes the figure. Every path ends in
62
+ * `release`, which drops the handlers, revokes any object URL and detaches the image.
63
+ */
64
+ function mountSplash(win, doc) {
65
+ const figure = doc.querySelector('[data-splash]');
66
+ const img = figure?.querySelector('img');
67
+ if (!figure || !img)
68
+ return () => { };
69
+ const config = {
70
+ baseUrl: figure.dataset.splashBase ?? '',
71
+ prefix: figure.dataset.splashPrefix ?? '',
72
+ count: Number(figure.dataset.splashCount),
73
+ cacheName: figure.dataset.splashCache ?? '',
74
+ };
75
+ const storage = win.caches ?? null;
76
+ const fetchImage = (target) => win.fetch(target, { mode: 'cors', credentials: 'omit' });
77
+ let active = true;
78
+ let index = 0;
79
+ let retried = false;
80
+ let networkUrl;
81
+ let objectUrl;
82
+ let startTimer;
83
+ const forgetObjectUrl = () => {
84
+ if (objectUrl)
85
+ URL.revokeObjectURL(objectUrl);
86
+ objectUrl = undefined;
87
+ };
88
+ const release = () => {
89
+ if (!active)
90
+ return;
91
+ active = false;
92
+ win.clearTimeout(startTimer);
93
+ img.removeEventListener('load', onLoad);
94
+ img.removeEventListener('error', onError);
95
+ forgetObjectUrl();
96
+ img.removeAttribute('src');
97
+ };
98
+ const attempt = (step) => {
99
+ try {
100
+ step();
101
+ }
102
+ catch {
103
+ figure.remove();
104
+ release();
105
+ }
106
+ };
107
+ const whenIdle = (task) => {
108
+ if (typeof win.requestIdleCallback === 'function')
109
+ win.requestIdleCallback(task, { timeout: SPLASH_STORE_IDLE_TIMEOUT_MS });
110
+ else
111
+ win.setTimeout(task, 0);
112
+ };
113
+ const onLoad = () => attempt(() => {
114
+ if (!active)
115
+ return;
116
+ figure.dataset.state = 'shown';
117
+ const url = networkUrl;
118
+ if (url)
119
+ whenIdle(() => { if (active)
120
+ void storeSplashImage(url, { storage, fetchImage, cacheName: config.cacheName }); });
121
+ });
122
+ const onError = () => attempt(() => {
123
+ if (!active)
124
+ return;
125
+ if (!retried && config.count > 1) {
126
+ retried = true;
127
+ const next = pickSplashIndex(Math.random, config.count - 1);
128
+ index = next >= index ? next + 1 : next;
129
+ forgetObjectUrl();
130
+ networkUrl = splashImageUrl(index, config);
131
+ img.src = networkUrl;
132
+ return;
133
+ }
134
+ figure.remove();
135
+ release();
136
+ });
137
+ const load = async (picked) => {
138
+ index = picked;
139
+ const url = splashImageUrl(picked, config);
140
+ const loaded = await loadSplashImage(url, { storage, cacheName: config.cacheName, budgetMs: SPLASH_IMAGE_DEFAULTS.readBudgetMs });
141
+ if (!active)
142
+ return;
143
+ if (loaded.source === 'cache') {
144
+ objectUrl = URL.createObjectURL(loaded.blob);
145
+ img.src = objectUrl;
146
+ }
147
+ else {
148
+ networkUrl = url;
149
+ img.src = url;
150
+ }
151
+ };
152
+ img.addEventListener('load', onLoad);
153
+ img.addEventListener('error', onError);
154
+ startTimer = win.setTimeout(() => {
155
+ startTimer = undefined;
156
+ try {
157
+ load(pickSplashIndex(Math.random, config.count)).catch(release);
158
+ }
159
+ catch {
160
+ release();
161
+ }
162
+ }, 0);
163
+ return release;
164
+ }
165
+ /** Mount once per rendered root; decoration never controls the navigation clock. */
166
+ export function mountRootTransit(win = window) {
167
+ const doc = win.document;
168
+ const page = doc.querySelector('[data-root-transit]');
169
+ if (!page)
170
+ return () => { };
171
+ const existing = mounted.get(page);
172
+ if (existing)
173
+ return existing;
174
+ const anchor = page.querySelector('[data-transit-continue]');
175
+ if (!anchor)
176
+ return () => { };
177
+ const target = resolveTransitNavigation(anchor.getAttribute('href') ?? '', new URL(win.location.href), page.dataset.base);
178
+ anchor.href = target;
179
+ const links = [anchor, ...page.querySelectorAll('[data-transit-alternative]')];
180
+ for (const link of links.slice(1)) {
181
+ link.href = resolveTransitNavigation(link.getAttribute('href') ?? '', new URL(win.location.href), page.dataset.base);
182
+ }
183
+ let finished = false;
184
+ let timer;
185
+ let releaseSplash = () => { };
186
+ const cleanup = () => {
187
+ finished = true;
188
+ win.clearTimeout(timer);
189
+ releaseSplash();
190
+ win.removeEventListener('pagehide', cleanup);
191
+ doc.removeEventListener('astro:before-swap', cleanup);
192
+ for (const link of links)
193
+ link.removeEventListener('click', continueNow);
194
+ };
195
+ const forward = (destination = target) => {
196
+ if (finished)
197
+ return;
198
+ cleanup();
199
+ win.location.replace(destination);
200
+ };
201
+ const continueNow = (event) => {
202
+ if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
203
+ return;
204
+ event.preventDefault();
205
+ forward(event.currentTarget.getAttribute('href') ?? target);
206
+ };
207
+ timer = win.setTimeout(() => forward(), ROOT_TRANSIT_DELAY_MS);
208
+ mounted.set(page, cleanup);
209
+ for (const link of links)
210
+ link.addEventListener('click', continueNow);
211
+ win.addEventListener('pagehide', cleanup);
212
+ doc.addEventListener('astro:before-swap', cleanup);
213
+ try {
214
+ releaseSplash = mountSplash(win, doc);
215
+ }
216
+ catch {
217
+ releaseSplash = () => { };
218
+ }
219
+ doc.documentElement.dataset.transitReady = 'true';
220
+ return cleanup;
221
+ }
@@ -0,0 +1,6 @@
1
+ import type { SiteLinksOptions } from './links.js';
2
+ /**
3
+ * Merge generated `hagilightRss()` feed URLs from request locals into Footer
4
+ * link options. Explicit `rssFeedUrl`/`rssLocaleFeedUrl` values win.
5
+ */
6
+ export declare function resolveRssFooterLinks(locals: unknown, locale: string | undefined, links?: SiteLinksOptions): SiteLinksOptions;
@@ -0,0 +1,54 @@
1
+ function isRecord(value) {
2
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
3
+ }
4
+ function normalizeLanguageTag(value) {
5
+ if (typeof value !== 'string' || !value.trim())
6
+ return undefined;
7
+ const input = value.trim().replaceAll('_', '-');
8
+ const alias = input.toLowerCase();
9
+ if (['zh', 'zh-cn', 'zh-hans', 'root'].includes(alias))
10
+ return 'zh-CN';
11
+ if (['zh-hant', 'zh-tw', 'zh-hk'].includes(alias))
12
+ return 'zh-Hant';
13
+ try {
14
+ return Intl.getCanonicalLocales(input)[0];
15
+ }
16
+ catch {
17
+ return undefined;
18
+ }
19
+ }
20
+ function isFooterContext(value) {
21
+ return isRecord(value)
22
+ && typeof value.defaultFeedUrl === 'string'
23
+ && value.defaultFeedUrl !== ''
24
+ && isRecord(value.localeFeedUrls)
25
+ && Array.isArray(value.locales)
26
+ && value.locales.every((entry) => isRecord(entry)
27
+ && typeof entry.lang === 'string'
28
+ && typeof entry.filename === 'string');
29
+ }
30
+ /**
31
+ * Merge generated `hagilightRss()` feed URLs from request locals into Footer
32
+ * link options. Explicit `rssFeedUrl`/`rssLocaleFeedUrl` values win.
33
+ */
34
+ export function resolveRssFooterLinks(locals, locale, links = {}) {
35
+ if (!isRecord(locals) || !Object.hasOwn(locals, 'hagilightRss'))
36
+ return links;
37
+ const rss = locals.hagilightRss;
38
+ if (!isFooterContext(rss)) {
39
+ throw new TypeError('Hagilight RSS Footer context is malformed.');
40
+ }
41
+ const normalizedLocale = normalizeLanguageTag(locale);
42
+ const configuredLocale = rss.locales.find((entry) => entry.filename !== 'en' && normalizeLanguageTag(entry.lang) === normalizedLocale);
43
+ const localeFeedUrl = configuredLocale ? rss.localeFeedUrls[configuredLocale.lang] : undefined;
44
+ if (configuredLocale && (typeof localeFeedUrl !== 'string' || !localeFeedUrl)) {
45
+ throw new TypeError(`Hagilight RSS Footer context has no URL for "${configuredLocale.lang}".`);
46
+ }
47
+ return {
48
+ ...links,
49
+ rssFeedUrl: links.rssFeedUrl ?? rss.defaultFeedUrl,
50
+ ...(typeof localeFeedUrl === 'string' && localeFeedUrl
51
+ ? { rssLocaleFeedUrl: links.rssLocaleFeedUrl ?? localeFeedUrl }
52
+ : {}),
53
+ };
54
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Coordinates which Hagilight integration owns the generated RSS routes when the
3
+ * plain-Astro and Starlight packages are both registered in one Astro project.
4
+ * The registry lives on `globalThis` so that separately installed copies of
5
+ * this module still observe each other.
6
+ */
7
+ export type RssOwnerPackage = 'astro' | 'starlight';
8
+ export interface RssOwnerClaim {
9
+ readonly package: RssOwnerPackage;
10
+ readonly enabled: boolean;
11
+ }
12
+ /** Property key an integration object uses to advertise its RSS ownership claim. */
13
+ export declare const RSS_OWNER: unique symbol;
14
+ /**
15
+ * Record a Starlight RSS claim as soon as the Starlight plugin is created, so a
16
+ * plain-Astro RSS integration earlier in the integration list can defer to it.
17
+ * Returns a callback that withdraws the claim.
18
+ */
19
+ export declare function registerStarlightRssOwner(enabled: boolean): () => void;
20
+ /**
21
+ * Decide whether the plain-Astro RSS integration should generate routes.
22
+ * Consumes pending Starlight claims. Returns `'starlight'` when an enabled
23
+ * Starlight RSS integration owns the routes, otherwise `'astro'`. A disabled or
24
+ * absent Starlight claim lets the plain-Astro integration own the routes.
25
+ */
26
+ export declare function resolvePlainAstroRssOwner(integrations?: readonly unknown[]): RssOwnerPackage;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Coordinates which Hagilight integration owns the generated RSS routes when the
3
+ * plain-Astro and Starlight packages are both registered in one Astro project.
4
+ * The registry lives on `globalThis` so that separately installed copies of
5
+ * this module still observe each other.
6
+ */
7
+ /** Property key an integration object uses to advertise its RSS ownership claim. */
8
+ export const RSS_OWNER = Symbol.for('@hagicode/hagilight-core/rss-owner');
9
+ const RSS_OWNER_REGISTRY = Symbol.for('@hagicode/hagilight-core/rss-owner-registry');
10
+ function registry() {
11
+ const host = globalThis;
12
+ host[RSS_OWNER_REGISTRY] ??= new Map();
13
+ return host[RSS_OWNER_REGISTRY];
14
+ }
15
+ /**
16
+ * Record a Starlight RSS claim as soon as the Starlight plugin is created, so a
17
+ * plain-Astro RSS integration earlier in the integration list can defer to it.
18
+ * Returns a callback that withdraws the claim.
19
+ */
20
+ export function registerStarlightRssOwner(enabled) {
21
+ if (typeof enabled !== 'boolean') {
22
+ throw new TypeError('Hagilight RSS owner enabled flag must be a boolean.');
23
+ }
24
+ const token = Symbol('starlight-rss-owner');
25
+ const owners = registry();
26
+ owners.set(token, { package: 'starlight', enabled });
27
+ return () => {
28
+ owners.delete(token);
29
+ };
30
+ }
31
+ function isOwnerClaim(value) {
32
+ if (!value || typeof value !== 'object')
33
+ return false;
34
+ const claim = value;
35
+ return (claim.package === 'astro' || claim.package === 'starlight') && typeof claim.enabled === 'boolean';
36
+ }
37
+ function claimOf(integration) {
38
+ if (!integration || typeof integration !== 'object')
39
+ return undefined;
40
+ const claim = integration[RSS_OWNER];
41
+ return isOwnerClaim(claim) ? claim : undefined;
42
+ }
43
+ /**
44
+ * Decide whether the plain-Astro RSS integration should generate routes.
45
+ * Consumes pending Starlight claims. Returns `'starlight'` when an enabled
46
+ * Starlight RSS integration owns the routes, otherwise `'astro'`. A disabled or
47
+ * absent Starlight claim lets the plain-Astro integration own the routes.
48
+ */
49
+ export function resolvePlainAstroRssOwner(integrations = []) {
50
+ const owners = registry();
51
+ const registered = [...owners.values()];
52
+ const starlightOwners = registered.length > 0
53
+ ? registered
54
+ : integrations.map(claimOf).filter((claim) => claim?.package === 'starlight');
55
+ owners.clear();
56
+ const active = starlightOwners.filter((owner) => owner.enabled);
57
+ if (active.length > 1) {
58
+ throw new Error('Hagilight RSS cannot determine a sole route owner because multiple Starlight RSS integrations are enabled.');
59
+ }
60
+ if (active.length === 1)
61
+ return 'starlight';
62
+ return 'astro';
63
+ }
package/dist/rss.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ export type RssPublicationDate = Date | string | number | null;
2
+ export interface RssFeedItem {
3
+ title: string;
4
+ link: string;
5
+ description?: string;
6
+ date?: RssPublicationDate;
7
+ pubDate?: RssPublicationDate;
8
+ }
9
+ export interface RssFeedOptions {
10
+ site: string | URL;
11
+ baseUrl?: string | URL;
12
+ language?: string;
13
+ title: string;
14
+ description: string;
15
+ items: readonly RssFeedItem[];
16
+ }
17
+ export type RssLocaleConfig = string | {
18
+ lang?: string;
19
+ label?: string;
20
+ };
21
+ export type RssLocalesInput = Readonly<Record<string, RssLocaleConfig | undefined>>;
22
+ export interface RssLocale {
23
+ /** Starlight-style locale route key, `root` for the default locale. */
24
+ route: string;
25
+ /** Canonical BCP 47 language tag. */
26
+ lang: string;
27
+ /** Feed filename segment: `en` for English, otherwise the canonical language tag. */
28
+ filename: string;
29
+ }
30
+ export interface ResolveRssLocalesOptions {
31
+ requireNonEmpty?: boolean;
32
+ }
33
+ export declare function resolveRssLocales(locales?: RssLocalesInput, { requireNonEmpty }?: ResolveRssLocalesOptions): RssLocale[];
34
+ export declare function generateRssFeed(options: RssFeedOptions): Promise<Response>;
package/dist/rss.js ADDED
@@ -0,0 +1,145 @@
1
+ import rss from '@astrojs/rss';
2
+ const LANGUAGE_TAG_PATTERN = /^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/u;
3
+ function isRecord(value) {
4
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
5
+ }
6
+ export function resolveRssLocales(locales, { requireNonEmpty = false } = {}) {
7
+ if (locales !== undefined && !isRecord(locales)) {
8
+ throw new TypeError('Hagilight RSS locales must be an object.');
9
+ }
10
+ if (requireNonEmpty && (locales === undefined || Object.keys(locales).length === 0)) {
11
+ throw new TypeError('Hagilight RSS locales must contain at least one locale.');
12
+ }
13
+ const configuredLocales = locales === undefined
14
+ ? [['root', { lang: 'en' }]]
15
+ : Object.entries(locales);
16
+ if (configuredLocales.length === 0)
17
+ configuredLocales.push(['root', { lang: 'en' }]);
18
+ const usedFilenames = new Set();
19
+ return configuredLocales.map(([route, config]) => {
20
+ const lang = typeof config === 'string' ? config : config?.lang ?? (route === 'root' ? undefined : route);
21
+ if (typeof lang !== 'string' || !LANGUAGE_TAG_PATTERN.test(lang)) {
22
+ throw new TypeError(`Hagilight RSS locale "${route}" must have a valid language tag.`);
23
+ }
24
+ let normalizedLang;
25
+ try {
26
+ [normalizedLang] = Intl.getCanonicalLocales(lang);
27
+ }
28
+ catch {
29
+ throw new TypeError(`Hagilight RSS locale "${route}" has an invalid language tag "${lang}".`);
30
+ }
31
+ const filename = /^en(?:-us)?$/iu.test(normalizedLang) ? 'en' : normalizedLang;
32
+ const collisionKey = filename.toLowerCase();
33
+ if (usedFilenames.has(collisionKey)) {
34
+ throw new Error(`Hagilight RSS locales collide on the "${filename}" feed filename.`);
35
+ }
36
+ usedFilenames.add(collisionKey);
37
+ return { route, lang: normalizedLang, filename };
38
+ });
39
+ }
40
+ function resolveSite(value) {
41
+ try {
42
+ const site = new URL(value);
43
+ if (!['http:', 'https:'].includes(site.protocol) || site.username || site.password) {
44
+ throw new Error();
45
+ }
46
+ return site;
47
+ }
48
+ catch {
49
+ throw new TypeError('Hagilight RSS requires an absolute Astro site URL; configure `site` in astro.config.mjs.');
50
+ }
51
+ }
52
+ function resolveLanguage(value) {
53
+ if (typeof value !== 'string' || !value.trim()) {
54
+ throw new TypeError('Hagilight RSS language must be a valid language tag.');
55
+ }
56
+ try {
57
+ return Intl.getCanonicalLocales(value)[0];
58
+ }
59
+ catch {
60
+ throw new TypeError(`Hagilight RSS language "${value}" must be a valid language tag.`);
61
+ }
62
+ }
63
+ function resolveBaseUrl(site, baseUrl = '/') {
64
+ let base;
65
+ try {
66
+ base = new URL(baseUrl, site);
67
+ }
68
+ catch {
69
+ throw new TypeError('Hagilight RSS base URL must be a valid path or absolute URL on the configured site.');
70
+ }
71
+ if (base.origin !== site.origin) {
72
+ throw new TypeError('Hagilight RSS base URL must use the configured Astro site origin.');
73
+ }
74
+ base.pathname = `${base.pathname.replace(/\/+$/u, '')}/`;
75
+ base.search = '';
76
+ base.hash = '';
77
+ return base;
78
+ }
79
+ function resolveItemUrl(value, base) {
80
+ if (typeof value !== 'string' || !value.trim()) {
81
+ throw new TypeError('Hagilight RSS items require a non-empty link.');
82
+ }
83
+ let url;
84
+ try {
85
+ url = new URL(value);
86
+ }
87
+ catch {
88
+ url = new URL(value.replace(/^\/+/u, ''), base);
89
+ }
90
+ if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password) {
91
+ throw new TypeError(`Hagilight RSS item link "${value}" must resolve to an absolute HTTP(S) URL.`);
92
+ }
93
+ return url.href;
94
+ }
95
+ function resolvePublicationDate(item, index) {
96
+ const value = item.pubDate ?? item.date;
97
+ if (value === undefined || value === null)
98
+ return undefined;
99
+ const date = value instanceof Date ? value : new Date(value);
100
+ if (Number.isNaN(date.getTime())) {
101
+ throw new TypeError(`Hagilight RSS item ${index + 1} has an invalid publication date.`);
102
+ }
103
+ return date;
104
+ }
105
+ export function generateRssFeed(options) {
106
+ const { site: siteInput, baseUrl = '/', language = 'en', title, description, items, } = (options ?? {});
107
+ const site = resolveSite(siteInput);
108
+ const base = resolveBaseUrl(site, baseUrl);
109
+ const lang = resolveLanguage(language);
110
+ if (typeof title !== 'string' || !title.trim()) {
111
+ throw new TypeError('Hagilight RSS requires a non-empty feed title.');
112
+ }
113
+ if (typeof description !== 'string' || !description.trim()) {
114
+ throw new TypeError('Hagilight RSS requires a non-empty feed description.');
115
+ }
116
+ if (!Array.isArray(items)) {
117
+ throw new TypeError('Hagilight RSS items must be an array supplied by the consumer.');
118
+ }
119
+ const feedItems = items.map((item, index) => {
120
+ if (!isRecord(item)) {
121
+ throw new TypeError(`Hagilight RSS item ${index + 1} must be an object.`);
122
+ }
123
+ const entry = item;
124
+ if (typeof entry.title !== 'string' || !entry.title.trim()) {
125
+ throw new TypeError(`Hagilight RSS item ${index + 1} requires a non-empty title.`);
126
+ }
127
+ if (entry.description !== undefined && typeof entry.description !== 'string') {
128
+ throw new TypeError(`Hagilight RSS item ${index + 1} description must be a string.`);
129
+ }
130
+ const pubDate = resolvePublicationDate(entry, index);
131
+ return {
132
+ title: entry.title,
133
+ ...(entry.description === undefined ? {} : { description: entry.description }),
134
+ link: resolveItemUrl(entry.link, base),
135
+ ...(pubDate === undefined ? {} : { pubDate }),
136
+ };
137
+ });
138
+ return rss({
139
+ title,
140
+ description,
141
+ site: base,
142
+ customData: `<language>${lang}</language>`,
143
+ items: feedItems,
144
+ });
145
+ }
@@ -0,0 +1,12 @@
1
+ import { z } from 'astro/zod';
2
+ /** Frontmatter schema for the optional `seo` object consumed by Hagilight SEO helpers. */
3
+ export declare const seoSchema: z.ZodObject<{
4
+ seo: z.ZodOptional<z.ZodObject<{
5
+ title: z.ZodOptional<z.ZodString>;
6
+ description: z.ZodOptional<z.ZodString>;
7
+ image: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
8
+ author: z.ZodOptional<z.ZodString>;
9
+ publishedDate: z.ZodOptional<z.ZodCoercedDate<unknown>>;
10
+ }, z.core.$strip>>;
11
+ }, z.core.$strip>;
12
+ export type SeoFrontmatter = z.infer<typeof seoSchema>;
@@ -0,0 +1,20 @@
1
+ import { z } from 'astro/zod';
2
+ import { isValidSeoImageReference } from './seo.js';
3
+ const optionalText = z.string().trim().min(1).optional();
4
+ const optionalImage = z.string()
5
+ .trim()
6
+ .min(1)
7
+ .refine(isValidSeoImageReference, {
8
+ message: 'Use an absolute HTTP(S) URL or a site-root path beginning with "/".',
9
+ })
10
+ .optional();
11
+ /** Frontmatter schema for the optional `seo` object consumed by Hagilight SEO helpers. */
12
+ export const seoSchema = z.object({
13
+ seo: z.object({
14
+ title: optionalText,
15
+ description: optionalText,
16
+ image: optionalImage,
17
+ author: optionalText,
18
+ publishedDate: z.coerce.date().optional(),
19
+ }).optional(),
20
+ });
package/dist/seo.d.ts ADDED
@@ -0,0 +1,78 @@
1
+ import type { HeadEntry } from './head.js';
2
+ export type { HeadAttributeValue, HeadEntry } from './head.js';
3
+ export interface SeoFields {
4
+ title?: string;
5
+ description?: string;
6
+ image?: string;
7
+ }
8
+ export interface PageSeo extends SeoFields {
9
+ author?: string;
10
+ publishedDate?: Date | string | number;
11
+ }
12
+ export interface SeoMetadata {
13
+ title?: string;
14
+ description?: string;
15
+ image?: string;
16
+ }
17
+ export interface SeoSiteOptions {
18
+ site?: string | URL;
19
+ basePath?: string;
20
+ }
21
+ export interface ResolveSeoMetadataOptions extends SeoSiteOptions {
22
+ entry?: {
23
+ data?: {
24
+ title?: string;
25
+ description?: string;
26
+ };
27
+ };
28
+ head?: readonly HeadEntry[];
29
+ pageSeo?: SeoFields;
30
+ siteSeo?: SeoFields;
31
+ explicitHead?: readonly (readonly HeadEntry[] | undefined)[];
32
+ body?: string;
33
+ }
34
+ export interface ComposeCanonicalSeoHeadOptions {
35
+ canonicalUrl?: string | URL;
36
+ explicitHead?: readonly (readonly HeadEntry[] | undefined)[];
37
+ }
38
+ export interface ArticleStructuredDataInput {
39
+ url: string | URL;
40
+ title: string;
41
+ description?: string;
42
+ author?: string;
43
+ publishedDate?: Date | string | number;
44
+ modifiedDate?: Date | string | number;
45
+ }
46
+ export interface BreadcrumbItem {
47
+ name: string;
48
+ url: string | URL;
49
+ }
50
+ export interface OrganizationStructuredDataInput {
51
+ name: string;
52
+ url: string | URL;
53
+ logo?: string | URL;
54
+ alternateName?: string;
55
+ }
56
+ export type StructuredData = Record<string, unknown>;
57
+ export declare function resolveAbsoluteHttpUrl(value: unknown, label?: string): URL;
58
+ export declare function resolveCanonicalUrl(pageUrl: string | URL, { site }?: {
59
+ site?: string | URL;
60
+ }): string;
61
+ export declare function extractSeoDescription(body: unknown): string | undefined;
62
+ export declare function resolveSeoMetadata({ entry, head, pageSeo, siteSeo, site, basePath, explicitHead, body, }?: ResolveSeoMetadataOptions): SeoMetadata;
63
+ export declare function isValidSeoImageReference(value: unknown): value is string;
64
+ export declare function resolveSeoImageUrl(value: string, { site, basePath }?: SeoSiteOptions): string;
65
+ export declare function composeSeoHead(head: readonly HeadEntry[], metadata: SeoMetadata, explicitHead?: readonly (readonly HeadEntry[] | undefined)[]): HeadEntry[];
66
+ /**
67
+ * Compose Open Graph/Twitter metadata plus exactly one canonical link for a
68
+ * plain Astro page. An explicit canonical link wins over existing ones, which
69
+ * win over `canonicalUrl`.
70
+ */
71
+ export declare function composeCanonicalSeoHead(head: readonly HeadEntry[], metadata: SeoMetadata & {
72
+ site?: string | URL;
73
+ }, { canonicalUrl, explicitHead }?: ComposeCanonicalSeoHeadOptions): HeadEntry[];
74
+ export declare function buildArticleStructuredData({ url, title, description, author, publishedDate, modifiedDate, }: ArticleStructuredDataInput): StructuredData;
75
+ export declare function buildBreadcrumbStructuredData(items?: readonly BreadcrumbItem[]): StructuredData;
76
+ export declare function buildOrganizationStructuredData({ name, url, logo, alternateName, }: OrganizationStructuredDataInput): StructuredData;
77
+ /** Serialize JSON-LD safely for inline `<script type="application/ld+json">`. */
78
+ export declare function serializeJsonLd(value: unknown): string;