@hagicode/hagilight-starlight 0.2.5 → 0.3.1
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/index.mjs +11 -0
- package/package.json +2 -2
- package/rss-utils.mjs +1 -31
package/index.mjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
3
|
import { resolveFaviconHeadEntry } from '@hagicode/hagilight/favicon';
|
|
4
|
+
import {
|
|
5
|
+
HAGILIGHT_RSS_OWNER,
|
|
6
|
+
registerStarlightRssOwner,
|
|
7
|
+
} from '@hagicode/hagilight/integration';
|
|
4
8
|
import { resolveRssLocales, resolveRssOptions } from './rss-utils.mjs';
|
|
5
9
|
import {
|
|
6
10
|
isValidSeoImageReference,
|
|
@@ -193,6 +197,7 @@ function createConfiguredIntegration(
|
|
|
193
197
|
componentIds,
|
|
194
198
|
getConfiguredRssFeed,
|
|
195
199
|
generateRss,
|
|
200
|
+
unregisterRssOwner,
|
|
196
201
|
) {
|
|
197
202
|
const optionsId = `virtual:hagilight-starlight/${instanceId}/options`;
|
|
198
203
|
const rssConfigId = 'virtual:hagilight-starlight/rss-config';
|
|
@@ -296,6 +301,7 @@ const isNotFound = /(?:^|\\/)404(?:\\.html)?\\/?$/u.test(Astro.url.pathname);
|
|
|
296
301
|
|
|
297
302
|
return {
|
|
298
303
|
name: `@hagicode/hagilight-starlight:${instanceId}`,
|
|
304
|
+
[HAGILIGHT_RSS_OWNER]: { package: 'starlight', enabled: generateRss },
|
|
299
305
|
hooks: {
|
|
300
306
|
'astro:config:setup'({ injectRoute, updateConfig }) {
|
|
301
307
|
if (generateRss) {
|
|
@@ -312,6 +318,9 @@ const isNotFound = /(?:^|\\/)404(?:\\.html)?\\/?$/u.test(Astro.url.pathname);
|
|
|
312
318
|
}
|
|
313
319
|
updateConfig({ vite: { plugins: [vitePlugin] } });
|
|
314
320
|
},
|
|
321
|
+
'astro:config:done'() {
|
|
322
|
+
unregisterRssOwner();
|
|
323
|
+
},
|
|
315
324
|
},
|
|
316
325
|
};
|
|
317
326
|
}
|
|
@@ -402,6 +411,7 @@ export default function hagilight(options = {}) {
|
|
|
402
411
|
seoEnabled: seo.enabled,
|
|
403
412
|
seo,
|
|
404
413
|
};
|
|
414
|
+
const unregisterRssOwner = registerStarlightRssOwner(options.rss?.enabled !== false);
|
|
405
415
|
|
|
406
416
|
return {
|
|
407
417
|
name: '@hagicode/hagilight-starlight',
|
|
@@ -489,6 +499,7 @@ export default function hagilight(options = {}) {
|
|
|
489
499
|
componentIds,
|
|
490
500
|
() => getRssFeedUrl(config) ?? rssFeedUrl,
|
|
491
501
|
generateRss,
|
|
502
|
+
unregisterRssOwner,
|
|
492
503
|
));
|
|
493
504
|
updateConfig({
|
|
494
505
|
...(config.logo === undefined ? { logo: { src: defaultLogo, alt: 'HagiCode' } } : {}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hagicode/hagilight-starlight",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Starlight customizations for HagiCode documentation",
|
|
6
6
|
"repository": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"assets/*.png"
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@hagicode/hagilight": "0.
|
|
60
|
+
"@hagicode/hagilight": "0.3.1"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"@astrojs/starlight": "^0.42.4",
|
package/rss-utils.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export { resolveRssLocales } from '@hagicode/hagilight/rss-locales';
|
|
2
2
|
|
|
3
3
|
export function resolveRssOptions(options = {}) {
|
|
4
4
|
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
|
@@ -15,36 +15,6 @@ export function resolveRssOptions(options = {}) {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export function resolveRssLocales(locales) {
|
|
19
|
-
const configuredLocales = locales === undefined
|
|
20
|
-
? [['root', { lang: 'en' }]]
|
|
21
|
-
: Object.entries(locales);
|
|
22
|
-
if (configuredLocales.length === 0) configuredLocales.push(['root', { lang: 'en' }]);
|
|
23
|
-
|
|
24
|
-
const usedFilenames = new Set();
|
|
25
|
-
const resolved = configuredLocales.map(([route, config]) => {
|
|
26
|
-
const lang = typeof config === 'string' ? config : config?.lang ?? (route === 'root' ? undefined : route);
|
|
27
|
-
if (typeof lang !== 'string' || !LANGUAGE_TAG_PATTERN.test(lang)) {
|
|
28
|
-
throw new TypeError(`Hagilight RSS locale "${route}" must have a valid language tag.`);
|
|
29
|
-
}
|
|
30
|
-
let normalizedLang;
|
|
31
|
-
try {
|
|
32
|
-
[normalizedLang] = Intl.getCanonicalLocales(lang);
|
|
33
|
-
} catch {
|
|
34
|
-
throw new TypeError(`Hagilight RSS locale "${route}" has an invalid language tag "${lang}".`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const filename = /^en(?:-us)?$/iu.test(normalizedLang) ? 'en' : normalizedLang;
|
|
38
|
-
const collisionKey = filename.toLowerCase();
|
|
39
|
-
if (usedFilenames.has(collisionKey)) {
|
|
40
|
-
throw new Error(`Hagilight RSS locales collide on the "${filename}" feed filename.`);
|
|
41
|
-
}
|
|
42
|
-
usedFilenames.add(collisionKey);
|
|
43
|
-
return { route, lang: normalizedLang, filename };
|
|
44
|
-
});
|
|
45
|
-
return resolved;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
18
|
function getLocaleForEntry(id, locales) {
|
|
49
19
|
const localized = locales
|
|
50
20
|
.filter(({ route }) => route !== 'root')
|