@astrojs/starlight 0.21.3 → 0.21.4
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @astrojs/starlight
|
|
2
2
|
|
|
3
|
+
## 0.21.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1703](https://github.com/withastro/starlight/pull/1703) [`b26238f2`](https://github.com/withastro/starlight/commit/b26238f22990dcf8ba002bea6a50c66f20ad5786) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes aside custom titles rendering for nested asides.
|
|
8
|
+
|
|
9
|
+
- [#1708](https://github.com/withastro/starlight/pull/1708) [`a72cb966`](https://github.com/withastro/starlight/commit/a72cb96600798c1fbc7558f8fd24556ca442d312) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes translation issues with Expressive Code when using a default language other than English
|
|
10
|
+
|
|
3
11
|
## 0.21.3
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/integrations/asides.ts
CHANGED
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
import { toMarkdown } from 'mdast-util-to-markdown';
|
|
13
13
|
import remarkDirective from 'remark-directive';
|
|
14
14
|
import type { Plugin, Transformer } from 'unified';
|
|
15
|
-
import { remove } from 'unist-util-remove';
|
|
16
15
|
import { visit } from 'unist-util-visit';
|
|
17
16
|
import type { StarlightConfig } from '../types';
|
|
18
17
|
import type { createTranslationSystemFromFs } from '../utils/translations-fs';
|
|
@@ -153,23 +152,24 @@ function remarkAsides(options: AsidesOptions): Plugin<[], Root> {
|
|
|
153
152
|
const variant = node.name;
|
|
154
153
|
if (!isAsideVariant(variant)) return;
|
|
155
154
|
|
|
156
|
-
// remark-directive converts a container’s “label” to a paragraph
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
//
|
|
155
|
+
// remark-directive converts a container’s “label” to a paragraph added as the head of its
|
|
156
|
+
// children with the `directiveLabel` property set to true. We want to pass it as the title
|
|
157
|
+
// prop to <Aside>, so when we find a directive label, we store it for the title prop and
|
|
158
|
+
// remove the paragraph from the container’s children.
|
|
160
159
|
let title = t(`aside.${variant}`);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return true;
|
|
160
|
+
const firstChild = node.children[0];
|
|
161
|
+
if (
|
|
162
|
+
firstChild?.type === 'paragraph' &&
|
|
163
|
+
firstChild.data &&
|
|
164
|
+
'directiveLabel' in firstChild.data
|
|
165
|
+
) {
|
|
166
|
+
const firstGrandChild = firstChild.children[0];
|
|
167
|
+
if (firstGrandChild?.type === 'text') {
|
|
168
|
+
title = firstGrandChild.value;
|
|
171
169
|
}
|
|
172
|
-
|
|
170
|
+
// The first paragraph contains a directive label, we can safely remove it.
|
|
171
|
+
node.children.splice(0, 1);
|
|
172
|
+
}
|
|
173
173
|
|
|
174
174
|
const aside = h(
|
|
175
175
|
'aside',
|
|
@@ -77,7 +77,6 @@ export function getStarlightEcConfigPreprocessor({
|
|
|
77
77
|
return (input): AstroExpressiveCodeOptions => {
|
|
78
78
|
const astroConfig = input.astroConfig;
|
|
79
79
|
const ecConfig = input.ecConfig as StarlightExpressiveCodeOptions;
|
|
80
|
-
const { locales } = starlightConfig;
|
|
81
80
|
|
|
82
81
|
const {
|
|
83
82
|
themes: themesInput,
|
|
@@ -111,7 +110,7 @@ export function getStarlightEcConfigPreprocessor({
|
|
|
111
110
|
});
|
|
112
111
|
|
|
113
112
|
// Add Expressive Code UI translations (if any) for all defined locales
|
|
114
|
-
if (useTranslations) addTranslations(
|
|
113
|
+
if (useTranslations) addTranslations(starlightConfig, useTranslations);
|
|
115
114
|
|
|
116
115
|
return {
|
|
117
116
|
themes,
|
|
@@ -124,6 +123,7 @@ export function getStarlightEcConfigPreprocessor({
|
|
|
124
123
|
}
|
|
125
124
|
return theme;
|
|
126
125
|
},
|
|
126
|
+
defaultLocale: starlightConfig.defaultLocale?.lang ?? starlightConfig.defaultLocale?.locale,
|
|
127
127
|
themeCssSelector: (theme, { styleVariants }) => {
|
|
128
128
|
// If one dark and one light theme are available, and the user has not disabled it,
|
|
129
129
|
// generate theme CSS selectors compatible with Starlight's dark mode switch
|
|
@@ -1,26 +1,37 @@
|
|
|
1
1
|
import { pluginFramesTexts } from 'astro-expressive-code';
|
|
2
2
|
import type { StarlightConfig } from '../../types';
|
|
3
3
|
import type { createTranslationSystemFromFs } from '../../utils/translations-fs';
|
|
4
|
+
import { localeToLang } from '../shared/localeToLang';
|
|
4
5
|
|
|
5
6
|
export function addTranslations(
|
|
6
|
-
|
|
7
|
+
config: StarlightConfig,
|
|
7
8
|
useTranslations: ReturnType<typeof createTranslationSystemFromFs>
|
|
8
9
|
) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
'expressiveCode.copyButtonCopied',
|
|
16
|
-
'expressiveCode.copyButtonTooltip',
|
|
17
|
-
'expressiveCode.terminalWindowFallbackTitle',
|
|
18
|
-
] as const;
|
|
19
|
-
translationKeys.forEach((key) => {
|
|
20
|
-
const translation = t(key);
|
|
21
|
-
if (!translation) return;
|
|
22
|
-
const ecId = key.replace(/^expressiveCode\./, '');
|
|
23
|
-
pluginFramesTexts.overrideTexts(lang, { [ecId]: translation });
|
|
24
|
-
});
|
|
10
|
+
addTranslationsForLocale(config.defaultLocale.locale, config, useTranslations);
|
|
11
|
+
if (config.isMultilingual) {
|
|
12
|
+
for (const locale in config.locales) {
|
|
13
|
+
if (locale === config.defaultLocale.locale || locale === 'root') continue;
|
|
14
|
+
addTranslationsForLocale(locale, config, useTranslations);
|
|
15
|
+
}
|
|
25
16
|
}
|
|
26
17
|
}
|
|
18
|
+
|
|
19
|
+
function addTranslationsForLocale(
|
|
20
|
+
locale: string | undefined,
|
|
21
|
+
config: StarlightConfig,
|
|
22
|
+
useTranslations: ReturnType<typeof createTranslationSystemFromFs>
|
|
23
|
+
) {
|
|
24
|
+
const lang = localeToLang(config, locale);
|
|
25
|
+
const t = useTranslations(locale);
|
|
26
|
+
const translationKeys = [
|
|
27
|
+
'expressiveCode.copyButtonCopied',
|
|
28
|
+
'expressiveCode.copyButtonTooltip',
|
|
29
|
+
'expressiveCode.terminalWindowFallbackTitle',
|
|
30
|
+
] as const;
|
|
31
|
+
translationKeys.forEach((key) => {
|
|
32
|
+
const translation = t(key);
|
|
33
|
+
if (!translation) return;
|
|
34
|
+
const ecId = key.replace(/^expressiveCode\./, '');
|
|
35
|
+
pluginFramesTexts.overrideTexts(lang, { [ecId]: translation });
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { StarlightConfig } from '../../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get the BCP-47 language tag for the given locale.
|
|
5
|
+
* @param locale Locale string or `undefined` for the root locale.
|
|
6
|
+
*/
|
|
7
|
+
export function localeToLang(config: StarlightConfig, locale: string | undefined): string {
|
|
8
|
+
const lang = locale ? config.locales?.[locale]?.lang : config.locales?.root?.lang;
|
|
9
|
+
const defaultLang = config.defaultLocale?.lang || config.defaultLocale?.locale;
|
|
10
|
+
return lang || defaultLang || 'en';
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/starlight",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.4",
|
|
4
4
|
"description": "Build beautiful, high-performance documentation websites with Astro",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -194,7 +194,6 @@
|
|
|
194
194
|
"rehype": "^13.0.1",
|
|
195
195
|
"remark-directive": "^3.0.0",
|
|
196
196
|
"unified": "^11.0.4",
|
|
197
|
-
"unist-util-remove": "^4.0.0",
|
|
198
197
|
"unist-util-visit": "^5.0.0",
|
|
199
198
|
"vfile": "^6.0.1"
|
|
200
199
|
},
|