@hagicode/hagilight-starlight 0.2.1 → 0.2.2-dev.18.1.2db1ab2
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/Footer.astro +6 -2
- package/index.mjs +35 -6
- package/language-routing.mjs +7 -12
- package/locales.mjs +14 -0
- package/package.json +3 -2
package/Footer.astro
CHANGED
|
@@ -6,10 +6,14 @@ import { resolveSiteLinks, type SiteLinksOptions } from '@hagicode/hagilight/sit
|
|
|
6
6
|
interface Props {
|
|
7
7
|
locale?: string;
|
|
8
8
|
links?: SiteLinksOptions;
|
|
9
|
+
rssFeedUrl?: string;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
const { locale = Astro.locals?.starlightRoute?.locale, links } = Astro.props;
|
|
12
|
-
const resolvedLinks = resolveSiteLinks(locale,
|
|
12
|
+
const { locale = Astro.locals?.starlightRoute?.locale, links, rssFeedUrl } = Astro.props;
|
|
13
|
+
const resolvedLinks = resolveSiteLinks(locale, {
|
|
14
|
+
...links,
|
|
15
|
+
...(rssFeedUrl === undefined ? {} : { rssFeedUrl }),
|
|
16
|
+
});
|
|
13
17
|
---
|
|
14
18
|
|
|
15
19
|
<DefaultFooter />
|
package/index.mjs
CHANGED
|
@@ -74,7 +74,20 @@ function resolveHagicodePromotion(config) {
|
|
|
74
74
|
return config.enabled ?? true;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
function
|
|
77
|
+
function getRssFeedUrl(config) {
|
|
78
|
+
if (!Array.isArray(config.head)) return undefined;
|
|
79
|
+
const rssLink = config.head.find((entry) => {
|
|
80
|
+
const attrs = entry?.attrs;
|
|
81
|
+
return entry?.tag === 'link'
|
|
82
|
+
&& attrs?.rel === 'alternate'
|
|
83
|
+
&& typeof attrs.type === 'string'
|
|
84
|
+
&& attrs.type.toLowerCase() === 'application/rss+xml'
|
|
85
|
+
&& typeof attrs.href === 'string';
|
|
86
|
+
});
|
|
87
|
+
return rssLink?.attrs.href;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function createConfiguredIntegration(instanceId, serializedOptions, componentIds, getConfiguredRssFeed) {
|
|
78
91
|
const optionsId = `virtual:hagilight-starlight/${instanceId}/options`;
|
|
79
92
|
const headerPath = componentIds.header
|
|
80
93
|
? fileURLToPath(new URL('./Header.astro', import.meta.url))
|
|
@@ -108,7 +121,11 @@ ${analyticsImport}
|
|
|
108
121
|
import options from '${optionsId}';
|
|
109
122
|
---
|
|
110
123
|
|
|
111
|
-
<Footer
|
|
124
|
+
<Footer
|
|
125
|
+
locale={Astro.locals?.starlightRoute?.locale}
|
|
126
|
+
links={options.links}
|
|
127
|
+
rssFeedUrl={options.rssFeedUrl}
|
|
128
|
+
/>
|
|
112
129
|
${promotionRender}
|
|
113
130
|
${analyticsRender}
|
|
114
131
|
`;
|
|
@@ -146,15 +163,22 @@ const isNotFound = /(?:^|\\/)404(?:\\.html)?\\/?$/u.test(Astro.url.pathname);
|
|
|
146
163
|
...(componentIds.pageTitle ? [[componentIds.pageTitle, pageTitleSource]] : []),
|
|
147
164
|
...(componentIds.markdownContent ? [[componentIds.markdownContent, markdownContentSource]] : []),
|
|
148
165
|
...(componentIds.head ? [[componentIds.head, headSource]] : []),
|
|
149
|
-
[optionsId, `export default ${JSON.stringify(serializedOptions)};`],
|
|
150
166
|
]);
|
|
151
167
|
const vitePlugin = {
|
|
152
168
|
name: `@hagicode/hagilight-starlight:${instanceId}`,
|
|
153
169
|
resolveId(id) {
|
|
154
|
-
return modules.has(id) ? `\0${id}` : null;
|
|
170
|
+
return modules.has(id) || id === optionsId ? `\0${id}` : null;
|
|
155
171
|
},
|
|
156
172
|
load(id) {
|
|
157
|
-
|
|
173
|
+
if (!id.startsWith('\0')) return null;
|
|
174
|
+
const moduleId = id.slice(1);
|
|
175
|
+
if (moduleId === optionsId) {
|
|
176
|
+
return `export default ${JSON.stringify({
|
|
177
|
+
...serializedOptions,
|
|
178
|
+
rssFeedUrl: getConfiguredRssFeed(),
|
|
179
|
+
})};`;
|
|
180
|
+
}
|
|
181
|
+
return modules.get(moduleId) ?? null;
|
|
158
182
|
},
|
|
159
183
|
};
|
|
160
184
|
|
|
@@ -267,7 +291,12 @@ export default function hagilight(options = {}) {
|
|
|
267
291
|
throw new Error('Hagilight Google Analytics cannot replace an existing Starlight Head override. Compose @hagicode/hagilight/GoogleAnalytics in your Head instead.');
|
|
268
292
|
}
|
|
269
293
|
|
|
270
|
-
addIntegration(createConfiguredIntegration(
|
|
294
|
+
addIntegration(createConfiguredIntegration(
|
|
295
|
+
instanceId,
|
|
296
|
+
serializedOptions,
|
|
297
|
+
componentIds,
|
|
298
|
+
() => getRssFeedUrl(config),
|
|
299
|
+
));
|
|
271
300
|
updateConfig({
|
|
272
301
|
...(config.logo === undefined ? { logo: { src: defaultLogo, alt: 'HagiCode' } } : {}),
|
|
273
302
|
customCss: [...(config.customCss ?? []), contentWidthCssPath],
|
package/language-routing.mjs
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
{ code: 'ja-JP', label: '日本語', lang: 'ja-JP' },
|
|
9
|
-
{ code: 'ko-KR', label: '한국어', lang: 'ko-KR' },
|
|
10
|
-
{ code: 'pt-BR', label: 'Português (Brasil)', lang: 'pt-BR' },
|
|
11
|
-
{ code: 'ru-RU', label: 'Русский', lang: 'ru-RU' },
|
|
12
|
-
];
|
|
1
|
+
import { locales } from './locales.mjs';
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_LANGUAGE_OPTIONS = Object.entries(locales).map(([code, locale]) => ({
|
|
4
|
+
code,
|
|
5
|
+
label: locale.label,
|
|
6
|
+
lang: locale.lang,
|
|
7
|
+
}));
|
|
13
8
|
|
|
14
9
|
const normalizeLang = (lang) => lang?.replaceAll('_', '-').toLowerCase();
|
|
15
10
|
|
package/locales.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const locales = {
|
|
2
|
+
root: { label: '简体中文', lang: 'zh-CN' },
|
|
3
|
+
'en-us': { label: 'English', lang: 'en-US' },
|
|
4
|
+
'zh-Hant': { label: '繁體中文', lang: 'zh-Hant' },
|
|
5
|
+
'fr-FR': { label: 'Français', lang: 'fr-FR' },
|
|
6
|
+
'de-DE': { label: 'Deutsch', lang: 'de-DE' },
|
|
7
|
+
'es-ES': { label: 'Español (España)', lang: 'es-ES' },
|
|
8
|
+
'ja-JP': { label: '日本語', lang: 'ja-JP' },
|
|
9
|
+
'ko-KR': { label: '한국어', lang: 'ko-KR' },
|
|
10
|
+
'pt-BR': { label: 'Português (Brasil)', lang: 'pt-BR' },
|
|
11
|
+
'ru-RU': { label: 'Русский', lang: 'ru-RU' },
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default locales;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hagicode/hagilight-starlight",
|
|
3
|
-
"version": "0.2.1",
|
|
3
|
+
"version": "0.2.2-dev.18.1.2db1ab2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Starlight customizations for HagiCode documentation",
|
|
6
6
|
"repository": {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"exports": {
|
|
16
16
|
".": "./index.mjs",
|
|
17
|
+
"./locales": "./locales.mjs",
|
|
17
18
|
"./article-promotion-schema": "./article-promotion-schema.mjs",
|
|
18
19
|
"./ai-disclosure-schema": "./ai-disclosure-schema.mjs",
|
|
19
20
|
"./ContentLayoutToggle": "./ContentLayoutToggle.astro",
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
"assets/*.png"
|
|
34
35
|
],
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@hagicode/hagilight": "0.2.1"
|
|
37
|
+
"@hagicode/hagilight": "0.2.2-dev.18.1.2db1ab2"
|
|
37
38
|
},
|
|
38
39
|
"peerDependencies": {
|
|
39
40
|
"@astrojs/starlight": "^0.42.4",
|