@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
package/dist/seo.js ADDED
@@ -0,0 +1,270 @@
1
+ function normalizeBasePath(basePath = '/') {
2
+ const normalized = `/${String(basePath).replace(/^\/+|\/+$/gu, '')}`;
3
+ return normalized === '/' ? '' : normalized;
4
+ }
5
+ export function resolveAbsoluteHttpUrl(value, label = 'URL') {
6
+ let parsed;
7
+ try {
8
+ parsed = new URL(value);
9
+ }
10
+ catch {
11
+ throw new TypeError(`Hagilight SEO ${label} must be an absolute HTTP(S) URL.`);
12
+ }
13
+ if (!['http:', 'https:'].includes(parsed.protocol) || parsed.username || parsed.password) {
14
+ throw new TypeError(`Hagilight SEO ${label} must be an absolute HTTP(S) URL.`);
15
+ }
16
+ return parsed;
17
+ }
18
+ export function resolveCanonicalUrl(pageUrl, { site } = {}) {
19
+ const siteUrl = resolveAbsoluteHttpUrl(site, 'site');
20
+ const canonical = resolveAbsoluteHttpUrl(pageUrl, 'page URL');
21
+ if (canonical.origin !== siteUrl.origin) {
22
+ throw new TypeError('Hagilight SEO page URL must use the configured Astro site origin.');
23
+ }
24
+ canonical.search = '';
25
+ canonical.hash = '';
26
+ return canonical.href;
27
+ }
28
+ export function extractSeoDescription(body) {
29
+ if (typeof body !== 'string' || !body.trim())
30
+ return undefined;
31
+ const text = body
32
+ .replace(/^```[\s\S]*?^```/gmu, ' ')
33
+ // A table of contents is navigation, not a summary: drop the heading and its link list.
34
+ .replace(/^#{1,6}\s*(?:table of contents|contents|toc|目录|目錄)\s*$(?:\n\s*(?:[-*+]|\d+\.)\s.*$|\n\s*$)*/gimu, ' ')
35
+ .replace(/^import\s.+;?\s*$/gmu, ' ')
36
+ // Document furniture is not a summary: metadata lines (Last updated, Version, Status, ...),
37
+ // horizontal rules and table rows.
38
+ .replace(/^\s*(?:>\s*)*(?:[-*]\s+)?[_*]{0,2}(?:last updated|updated|version|status|date|audience|refs?|source of truth|owner|authors?)(?::[_*]{0,2}|[_*]{0,2}:)[^\n]*$/gimu, ' ')
39
+ .replace(/^\s*(?:-{3,}|\*{3,}|_{3,})\s*$/gmu, ' ')
40
+ .replace(/^\s*\|.*\|\s*$/gmu, ' ')
41
+ .replace(/!\[([^\]]*)\]\([^)]*\)/gu, '$1')
42
+ .replace(/\[([^\]]+)\]\([^)]*\)/gu, '$1')
43
+ .replace(/<[^>]*>/gu, ' ')
44
+ .replace(/`([^`]+)`/gu, '$1')
45
+ .replace(/^\s{0,3}(?:#{1,6}\s+|>\s*|[-*+]\s+|\d+\.\s+)/gmu, '')
46
+ .replace(/[*_~]/gu, '')
47
+ .replace(/\s+/gu, ' ')
48
+ .trim();
49
+ if (!text)
50
+ return undefined;
51
+ const characters = Array.from(text);
52
+ if (characters.length <= 160)
53
+ return text;
54
+ let end = 159;
55
+ const boundary = characters.slice(0, end).lastIndexOf(' ');
56
+ if (boundary > 120)
57
+ end = boundary;
58
+ return `${characters.slice(0, end).join('').trimEnd()}…`;
59
+ }
60
+ function metaKey(entry) {
61
+ if (entry?.tag !== 'meta')
62
+ return undefined;
63
+ const attrs = entry.attrs ?? {};
64
+ if (typeof attrs.property === 'string')
65
+ return `property:${attrs.property.toLowerCase()}`;
66
+ if (typeof attrs.name === 'string')
67
+ return `name:${attrs.name.toLowerCase()}`;
68
+ return undefined;
69
+ }
70
+ function flattenHeads(heads) {
71
+ return heads.flatMap((head) => (Array.isArray(head) ? head : []));
72
+ }
73
+ function explicitMetaKeys(heads) {
74
+ return new Set(flattenHeads(heads).map(metaKey).filter((key) => Boolean(key)));
75
+ }
76
+ function metaContent(entry) {
77
+ const content = entry?.attrs?.content;
78
+ return typeof content === 'string' ? content : undefined;
79
+ }
80
+ function explicitMetaValue(heads, key) {
81
+ return metaContent(flattenHeads(heads).find((entry) => metaKey(entry) === key));
82
+ }
83
+ function existingMetaValue(head, key) {
84
+ return metaContent(head.find((entry) => metaKey(entry) === key));
85
+ }
86
+ export function resolveSeoMetadata({ entry, head = [], pageSeo = {}, siteSeo = {}, site, basePath = '/', explicitHead = [], body, } = {}) {
87
+ const data = entry?.data ?? {};
88
+ const title = pageSeo.title
89
+ ?? siteSeo.title
90
+ ?? data.title
91
+ ?? existingMetaValue(head, 'property:og:title');
92
+ const description = pageSeo.description
93
+ ?? data.description
94
+ ?? explicitMetaValue(explicitHead, 'name:description')
95
+ ?? explicitMetaValue(explicitHead, 'property:og:description')
96
+ ?? extractSeoDescription(body)
97
+ ?? existingMetaValue(head, 'name:description')
98
+ ?? existingMetaValue(head, 'property:og:description')
99
+ ?? siteSeo.description;
100
+ const image = pageSeo.image ?? siteSeo.image;
101
+ return {
102
+ title,
103
+ description,
104
+ image: image === undefined ? undefined : resolveSeoImageUrl(image, { site, basePath }),
105
+ };
106
+ }
107
+ export function isValidSeoImageReference(value) {
108
+ if (typeof value !== 'string' || value.trim() !== value || value.length === 0)
109
+ return false;
110
+ if (value.startsWith('/'))
111
+ return !value.startsWith('//');
112
+ try {
113
+ const url = new URL(value);
114
+ return (url.protocol === 'https:' || url.protocol === 'http:') && !url.username && !url.password;
115
+ }
116
+ catch {
117
+ return false;
118
+ }
119
+ }
120
+ export function resolveSeoImageUrl(value, { site, basePath = '/' } = {}) {
121
+ if (!isValidSeoImageReference(value)) {
122
+ throw new TypeError('Hagilight SEO image must be an absolute HTTP(S) URL or a site-root path.');
123
+ }
124
+ if (/^https?:\/\//iu.test(value))
125
+ return new URL(value).href;
126
+ const siteUrl = resolveAbsoluteHttpUrl(site, 'site');
127
+ const base = `${normalizeBasePath(basePath)}/`;
128
+ return new URL(`${base}${value.replace(/^\/+/u, '')}`, siteUrl).href;
129
+ }
130
+ export function composeSeoHead(head, metadata, explicitHead = []) {
131
+ const explicit = explicitMetaKeys(explicitHead);
132
+ const values = [
133
+ // Starlight emits `<meta name="description">` from the site-wide description for pages without
134
+ // their own, while og/twitter carry the page excerpt. Keep all three in step.
135
+ ['name:description', metadata.description],
136
+ ['property:og:title', metadata.title],
137
+ ['property:og:description', metadata.description],
138
+ ['property:og:image', metadata.image],
139
+ ['name:twitter:title', metadata.title],
140
+ ['name:twitter:description', metadata.description],
141
+ ['name:twitter:image', metadata.image],
142
+ ];
143
+ const generatedKeys = new Set(values.map(([key]) => key));
144
+ const seen = new Set();
145
+ const result = head.filter((entry) => {
146
+ const key = metaKey(entry);
147
+ if (!key || !generatedKeys.has(key))
148
+ return true;
149
+ // Never drop an existing description when there is nothing to replace it with.
150
+ if (key === 'name:description' && metadata.description === undefined)
151
+ return true;
152
+ if (explicit.has(key)) {
153
+ if (seen.has(key))
154
+ return false;
155
+ seen.add(key);
156
+ return true;
157
+ }
158
+ return false;
159
+ });
160
+ const present = new Set(result.map(metaKey).filter(Boolean));
161
+ for (const [key, content] of values) {
162
+ if (content === undefined || explicit.has(key) || present.has(key))
163
+ continue;
164
+ const separator = key.indexOf(':');
165
+ const attribute = key.slice(0, separator);
166
+ const value = key.slice(separator + 1);
167
+ result.push({ tag: 'meta', attrs: { [attribute]: value, content } });
168
+ }
169
+ return result;
170
+ }
171
+ function isCanonicalLink(entry) {
172
+ return entry.tag === 'link' && entry.attrs?.rel === 'canonical';
173
+ }
174
+ function canonicalHref(entry) {
175
+ const href = entry?.attrs?.href;
176
+ return typeof href === 'string' ? href : undefined;
177
+ }
178
+ /**
179
+ * Compose Open Graph/Twitter metadata plus exactly one canonical link for a
180
+ * plain Astro page. An explicit canonical link wins over existing ones, which
181
+ * win over `canonicalUrl`.
182
+ */
183
+ export function composeCanonicalSeoHead(head, metadata, { canonicalUrl, explicitHead = [] } = {}) {
184
+ const canonicalSource = canonicalHref(flattenHeads(explicitHead).find(isCanonicalLink))
185
+ ?? canonicalHref(head.find(isCanonicalLink))
186
+ ?? canonicalUrl;
187
+ if (canonicalSource === undefined) {
188
+ throw new TypeError('Hagilight SEO page URL must be an absolute HTTP(S) URL.');
189
+ }
190
+ const canonical = resolveCanonicalUrl(canonicalSource, { site: metadata.site });
191
+ const output = composeSeoHead(head.filter((entry) => !isCanonicalLink(entry)), metadata, explicitHead);
192
+ const link = { tag: 'link', attrs: { rel: 'canonical', href: canonical } };
193
+ const insertionIndex = output.findIndex(({ tag }) => tag !== 'meta');
194
+ output.splice(insertionIndex < 0 ? output.length : insertionIndex, 0, link);
195
+ return output;
196
+ }
197
+ function dateValue(value, field) {
198
+ if (value === undefined || value === null)
199
+ return undefined;
200
+ const date = value instanceof Date ? value : new Date(value);
201
+ if (Number.isNaN(date.getTime())) {
202
+ throw new TypeError(`Hagilight SEO ${field} must be a valid date.`);
203
+ }
204
+ return date.toISOString();
205
+ }
206
+ export function buildArticleStructuredData({ url, title, description, author, publishedDate, modifiedDate, }) {
207
+ const canonicalUrl = resolveAbsoluteHttpUrl(url, 'article URL').href;
208
+ if (typeof title !== 'string' || !title.trim()) {
209
+ throw new TypeError('Hagilight SEO article title must be a non-empty string.');
210
+ }
211
+ const article = {
212
+ '@context': 'https://schema.org',
213
+ '@type': 'Article',
214
+ headline: title.trim(),
215
+ url: canonicalUrl,
216
+ mainEntityOfPage: { '@type': 'WebPage', '@id': canonicalUrl },
217
+ };
218
+ if (typeof description === 'string' && description.trim())
219
+ article.description = description.trim();
220
+ const published = dateValue(publishedDate, 'article publishedDate');
221
+ const modified = dateValue(modifiedDate, 'article modifiedDate');
222
+ if (published)
223
+ article.datePublished = published;
224
+ if (modified)
225
+ article.dateModified = modified;
226
+ if (typeof author === 'string' && author.trim()) {
227
+ article.author = { '@type': 'Person', name: author.trim() };
228
+ }
229
+ return article;
230
+ }
231
+ export function buildBreadcrumbStructuredData(items = []) {
232
+ if (!Array.isArray(items))
233
+ throw new TypeError('Hagilight SEO breadcrumb items must be an array.');
234
+ return {
235
+ '@context': 'https://schema.org',
236
+ '@type': 'BreadcrumbList',
237
+ itemListElement: items.map(({ name, url }, index) => {
238
+ if (typeof name !== 'string' || !name.trim()) {
239
+ throw new TypeError('Hagilight SEO breadcrumb names must be non-empty strings.');
240
+ }
241
+ return {
242
+ '@type': 'ListItem',
243
+ position: index + 1,
244
+ name: name.trim(),
245
+ item: resolveAbsoluteHttpUrl(url, 'breadcrumb URL').href,
246
+ };
247
+ }),
248
+ };
249
+ }
250
+ export function buildOrganizationStructuredData({ name, url, logo, alternateName, }) {
251
+ if (typeof name !== 'string' || !name.trim()) {
252
+ throw new TypeError('Hagilight SEO organization name must be a non-empty string.');
253
+ }
254
+ const organization = {
255
+ '@context': 'https://schema.org',
256
+ '@type': 'Organization',
257
+ name: name.trim(),
258
+ url: resolveAbsoluteHttpUrl(url, 'organization URL').href,
259
+ };
260
+ if (logo !== undefined)
261
+ organization.logo = resolveAbsoluteHttpUrl(logo, 'organization logo').href;
262
+ if (typeof alternateName === 'string' && alternateName.trim()) {
263
+ organization.alternateName = alternateName.trim();
264
+ }
265
+ return organization;
266
+ }
267
+ /** Serialize JSON-LD safely for inline `<script type="application/ld+json">`. */
268
+ export function serializeJsonLd(value) {
269
+ return JSON.stringify(value).replace(/</gu, '\\u003c');
270
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Decides which Hagilight integration writes `hagilight.metadata.json` when the
3
+ * plain-Astro integration and the Starlight plugin are both registered. Same
4
+ * `globalThis` pattern as `rss-ownership.ts`, so separately installed copies of
5
+ * this module still see each other.
6
+ *
7
+ * Ownership is decided by claims: the Starlight plugin claims at creation, and the
8
+ * plain-Astro integration asks at config setup. The write is coordinated at build
9
+ * time. The owner hands over its write closure. Each deferring peer reports when
10
+ * its own build hook has finished (for example after `llms.txt`), and the write runs
11
+ * once the owner and every pending peer are done, whichever hook finishes last.
12
+ * Output therefore does not depend on hook or registration order.
13
+ */
14
+ export type SiteMetadataOwnerPackage = 'astro' | 'starlight';
15
+ export interface SiteMetadataOwnerClaim {
16
+ readonly package: SiteMetadataOwnerPackage;
17
+ readonly enabled: boolean;
18
+ }
19
+ /**
20
+ * Record the Starlight claim as soon as the plugin is created, so a plain-Astro
21
+ * integration listed earlier can defer to it. Returns a callback that withdraws it.
22
+ */
23
+ export declare function registerStarlightSiteMetadataOwner(enabled: boolean): () => void;
24
+ /**
25
+ * Return `'starlight'` when an enabled Starlight claim is registered, else `'astro'`.
26
+ * Call it at plain-Astro config setup, after the Starlight plugin was created.
27
+ */
28
+ export declare function resolveSiteMetadataOwner(): SiteMetadataOwnerPackage;
29
+ /**
30
+ * Called by a deferring peer at config setup. The owner waits for this participant
31
+ * until it calls `reportSiteMetadataBuilt` with the returned token.
32
+ */
33
+ export declare function expectSiteMetadataReport(): symbol;
34
+ /** Called by a deferring peer when its build hook has finished. */
35
+ export declare function reportSiteMetadataBuilt(token: symbol): void;
36
+ /**
37
+ * Called by the owner in its build hook with the closure that writes the file.
38
+ * Runs now when no peer is pending, otherwise when the last pending peer reports.
39
+ */
40
+ export declare function completeSiteMetadataOwnerBuild(write: () => void): void;
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Decides which Hagilight integration writes `hagilight.metadata.json` when the
3
+ * plain-Astro integration and the Starlight plugin are both registered. Same
4
+ * `globalThis` pattern as `rss-ownership.ts`, so separately installed copies of
5
+ * this module still see each other.
6
+ *
7
+ * Ownership is decided by claims: the Starlight plugin claims at creation, and the
8
+ * plain-Astro integration asks at config setup. The write is coordinated at build
9
+ * time. The owner hands over its write closure. Each deferring peer reports when
10
+ * its own build hook has finished (for example after `llms.txt`), and the write runs
11
+ * once the owner and every pending peer are done, whichever hook finishes last.
12
+ * Output therefore does not depend on hook or registration order.
13
+ */
14
+ const REGISTRY_KEY = Symbol.for('@hagicode/hagilight-core/site-metadata-registry');
15
+ function registry() {
16
+ const host = globalThis;
17
+ host[REGISTRY_KEY] ??= { claims: new Map(), pending: new Set() };
18
+ return host[REGISTRY_KEY];
19
+ }
20
+ /**
21
+ * Record the Starlight claim as soon as the plugin is created, so a plain-Astro
22
+ * integration listed earlier can defer to it. Returns a callback that withdraws it.
23
+ */
24
+ export function registerStarlightSiteMetadataOwner(enabled) {
25
+ if (typeof enabled !== 'boolean') {
26
+ throw new TypeError('Hagilight site metadata owner enabled flag must be a boolean.');
27
+ }
28
+ const token = Symbol('starlight-site-metadata-owner');
29
+ registry().claims.set(token, { package: 'starlight', enabled });
30
+ return () => {
31
+ registry().claims.delete(token);
32
+ };
33
+ }
34
+ /**
35
+ * Return `'starlight'` when an enabled Starlight claim is registered, else `'astro'`.
36
+ * Call it at plain-Astro config setup, after the Starlight plugin was created.
37
+ */
38
+ export function resolveSiteMetadataOwner() {
39
+ const claims = [...registry().claims.values()];
40
+ return claims.some((claim) => claim.package === 'starlight' && claim.enabled) ? 'starlight' : 'astro';
41
+ }
42
+ /**
43
+ * Called by a deferring peer at config setup. The owner waits for this participant
44
+ * until it calls `reportSiteMetadataBuilt` with the returned token.
45
+ */
46
+ export function expectSiteMetadataReport() {
47
+ const token = Symbol('site-metadata-peer');
48
+ registry().pending.add(token);
49
+ return token;
50
+ }
51
+ /** Called by a deferring peer when its build hook has finished. */
52
+ export function reportSiteMetadataBuilt(token) {
53
+ const state = registry();
54
+ state.pending.delete(token);
55
+ flush(state);
56
+ }
57
+ /**
58
+ * Called by the owner in its build hook with the closure that writes the file.
59
+ * Runs now when no peer is pending, otherwise when the last pending peer reports.
60
+ */
61
+ export function completeSiteMetadataOwnerBuild(write) {
62
+ const state = registry();
63
+ state.ownerWrite = write;
64
+ flush(state);
65
+ }
66
+ function flush(state) {
67
+ if (!state.ownerWrite || state.pending.size > 0)
68
+ return;
69
+ const write = state.ownerWrite;
70
+ state.ownerWrite = undefined;
71
+ write();
72
+ }
@@ -0,0 +1,25 @@
1
+ import { type SiteMetadata, type SiteMetadataDiscovery } from './site-metadata.js';
2
+ export interface SiteMetadataLogger {
3
+ info(message: string): void;
4
+ warn(message: string): void;
5
+ }
6
+ /**
7
+ * Report which discovery artifacts exist in the finished build output. Paths are
8
+ * relative to the site base, so `sitemap-index.xml` is reported as `/sitemap-index.xml`.
9
+ */
10
+ export declare function findDiscoveryOutputs(outDir: string): SiteMetadataDiscovery;
11
+ export interface WriteSiteMetadataInput {
12
+ /** Build output directory. */
13
+ outDir: string;
14
+ metadata: SiteMetadata;
15
+ /** Site-owned copies, such as `public/` or `static/` files. A site-owned file is never overwritten. */
16
+ siteOwnedFiles?: readonly string[];
17
+ logger: SiteMetadataLogger;
18
+ }
19
+ export type WriteSiteMetadataResult = 'written' | 'kept';
20
+ /**
21
+ * Write the metadata file into the build output. An existing file, either in the
22
+ * output or among the site-owned files, is kept and reported. The write goes to a
23
+ * temporary file that is renamed into place, so readers never see a partial file.
24
+ */
25
+ export declare function writeSiteMetadata({ outDir, metadata, siteOwnedFiles, logger }: WriteSiteMetadataInput): WriteSiteMetadataResult;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Node-only writer for `.well-known/hagilight.metadata.json`. Kept separate from
3
+ * `site-metadata.ts` so the browser-safe contract never imports `node:` modules.
4
+ */
5
+ import { existsSync, mkdirSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
6
+ import { dirname, join } from 'node:path';
7
+ import { SITE_METADATA_PATH, serializeSiteMetadata, } from './site-metadata.js';
8
+ /** Candidate file names per discovery key, in preference order. */
9
+ const DISCOVERY_FILES = {
10
+ sitemap: ['sitemap-index.xml', 'sitemap.xml'],
11
+ robots: ['robots.txt'],
12
+ rss: ['rss.xml'],
13
+ llms: ['llms.txt'],
14
+ };
15
+ function isFile(path) {
16
+ return existsSync(path) && statSync(path).isFile();
17
+ }
18
+ /**
19
+ * Report which discovery artifacts exist in the finished build output. Paths are
20
+ * relative to the site base, so `sitemap-index.xml` is reported as `/sitemap-index.xml`.
21
+ */
22
+ export function findDiscoveryOutputs(outDir) {
23
+ const discovery = {};
24
+ for (const [key, names] of Object.entries(DISCOVERY_FILES)) {
25
+ const found = names.find((name) => isFile(join(outDir, name)));
26
+ if (found)
27
+ discovery[key] = `/${found}`;
28
+ }
29
+ return discovery;
30
+ }
31
+ /**
32
+ * Write the metadata file into the build output. An existing file, either in the
33
+ * output or among the site-owned files, is kept and reported. The write goes to a
34
+ * temporary file that is renamed into place, so readers never see a partial file.
35
+ */
36
+ export function writeSiteMetadata({ outDir, metadata, siteOwnedFiles = [], logger }) {
37
+ const target = join(outDir, SITE_METADATA_PATH);
38
+ const existing = [target, ...siteOwnedFiles].find(isFile);
39
+ if (existing) {
40
+ logger.info(`${SITE_METADATA_PATH} already exists (${existing}); leaving it untouched.`);
41
+ return 'kept';
42
+ }
43
+ mkdirSync(dirname(target), { recursive: true });
44
+ const temporary = `${target}.${process.pid}.${Date.now()}.tmp`;
45
+ try {
46
+ writeFileSync(temporary, serializeSiteMetadata(metadata), 'utf8');
47
+ renameSync(temporary, target);
48
+ }
49
+ catch (error) {
50
+ rmSync(temporary, { force: true });
51
+ throw error;
52
+ }
53
+ logger.info(`Generated ${SITE_METADATA_PATH}.`);
54
+ return 'written';
55
+ }
@@ -0,0 +1,113 @@
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 { type BuildInfo } from './build-info.js';
9
+ export declare const SITE_METADATA_SCHEMA_VERSION = 1;
10
+ /** Site-relative output path. This is the only place the path is spelled. */
11
+ export declare 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 declare const ANALYTICS_LOADER_MARKERS: {
18
+ readonly googleAnalytics: readonly ["https://www.googletagmanager.com/gtag/js"];
19
+ readonly fiftyOneLa: readonly ["id=\"LA_COLLECT\"", "https://sdk.51.la/js-sdk-pro.min.js"];
20
+ readonly posthog: readonly ["__hagilightPosthogInitialized"];
21
+ };
22
+ export interface SiteMetadataGenerator {
23
+ readonly name: string;
24
+ readonly version: string;
25
+ }
26
+ export interface SiteMetadataSite {
27
+ readonly name: string;
28
+ /** Absolute HTTP(S) site URL, as configured. */
29
+ readonly url: string;
30
+ /** Base path with a leading and trailing slash. */
31
+ readonly base: string;
32
+ readonly description?: string;
33
+ }
34
+ export interface SiteMetadataLocale {
35
+ /** The integration's locale key; the default locale uses its language tag. */
36
+ readonly code: string;
37
+ /** BCP 47 language tag. */
38
+ readonly lang: string;
39
+ /** Locale URL path, relative to `site.base`. */
40
+ readonly path: string;
41
+ }
42
+ export interface SiteMetadataLanguages {
43
+ readonly default: string;
44
+ readonly locales: readonly SiteMetadataLocale[];
45
+ }
46
+ /** Site-relative paths, relative to `site.base`. A key is present only when the build produced the file. */
47
+ export interface SiteMetadataDiscovery {
48
+ readonly sitemap?: string;
49
+ readonly robots?: string;
50
+ readonly rss?: string;
51
+ readonly llms?: string;
52
+ }
53
+ /** Whether each provider's loader is emitted in this build. */
54
+ export interface SiteMetadataAnalytics {
55
+ readonly googleAnalytics: boolean;
56
+ readonly fiftyOneLa: boolean;
57
+ readonly posthog: boolean;
58
+ }
59
+ export interface SiteMetadataFeatures {
60
+ readonly seo?: boolean;
61
+ readonly promoto?: boolean;
62
+ }
63
+ export interface SiteMetadata {
64
+ readonly schemaVersion: typeof SITE_METADATA_SCHEMA_VERSION;
65
+ readonly generator: SiteMetadataGenerator;
66
+ readonly site: SiteMetadataSite;
67
+ readonly languages: SiteMetadataLanguages;
68
+ readonly build: BuildInfo;
69
+ readonly discovery: SiteMetadataDiscovery;
70
+ readonly analytics: SiteMetadataAnalytics;
71
+ readonly features: SiteMetadataFeatures;
72
+ }
73
+ export interface BuildSiteMetadataInput {
74
+ generator: SiteMetadataGenerator;
75
+ site: {
76
+ /** Explicit name, the site's own title, or the home page name. Falls back to the URL hostname. */
77
+ name?: string | undefined;
78
+ url: string | URL;
79
+ base?: string | undefined;
80
+ description?: string | undefined;
81
+ };
82
+ /** Locales with paths relative to the base. An empty list yields one locale that is also the default. */
83
+ locales?: readonly SiteMetadataLocale[] | undefined;
84
+ defaultLocale?: string | undefined;
85
+ /** Language tag used for the single-locale fallback. Defaults to `en`. */
86
+ fallbackLang?: string | undefined;
87
+ build: unknown;
88
+ discovery?: SiteMetadataDiscovery | undefined;
89
+ analytics?: Partial<SiteMetadataAnalytics> | undefined;
90
+ features?: SiteMetadataFeatures | undefined;
91
+ }
92
+ export interface SiteMetadataOption {
93
+ readonly enabled: boolean;
94
+ readonly name?: string;
95
+ readonly description?: string;
96
+ }
97
+ /** Build a schema-valid object from typed inputs. Pure and deterministic. */
98
+ export declare function buildSiteMetadata(input: BuildSiteMetadataInput): SiteMetadata;
99
+ /** Problems found in an untrusted value. An empty list means the value follows schema version 1. */
100
+ export declare function validateSiteMetadata(value: unknown): readonly string[];
101
+ /** Canonical minified JSON: fixed key order, no indentation, trailing newline. Identical input gives identical bytes. */
102
+ export declare function serializeSiteMetadata(metadata: SiteMetadata): string;
103
+ /**
104
+ * Detect which analytics loaders the built pages contain. A provider is enabled
105
+ * when any page carries all of its markers. Only booleans leave this function.
106
+ */
107
+ export declare function detectAnalyticsLoaders(pages: Iterable<string>): SiteMetadataAnalytics;
108
+ /**
109
+ * Resolve the `metadata` option shared by the three packages. `undefined` and
110
+ * `true` enable the default output, `false` opts out, and an object may override
111
+ * `name` and `description`. Errors name the option.
112
+ */
113
+ export declare function resolveSiteMetadataOption(value: unknown): SiteMetadataOption;