@astrojs/starlight 0.21.3 → 0.21.5
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 +20 -0
- package/components/Icons.ts +1 -0
- package/integrations/asides.ts +16 -16
- package/integrations/expressive-code/index.ts +2 -2
- package/integrations/expressive-code/translations.ts +28 -17
- package/integrations/shared/localeToLang.ts +11 -0
- package/integrations/shared/pathToLocale.ts +2 -1
- package/package.json +1 -2
- package/user-components/Tabs.astro +4 -4
- package/user-components/file-tree-icons.ts +1 -0
- package/user-components/rehype-file-tree.ts +1 -1
- package/utils/user-config.ts +12 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @astrojs/starlight
|
|
2
2
|
|
|
3
|
+
## 0.21.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1728](https://github.com/withastro/starlight/pull/1728) [`0a75680d`](https://github.com/withastro/starlight/commit/0a75680ddd2f3325ab9ad7ac910f7c884b89a9ed) Thanks [@delucis](https://github.com/delucis)! - Adds 1 new icon: `pkl`
|
|
8
|
+
|
|
9
|
+
- [#1709](https://github.com/withastro/starlight/pull/1709) [`c5cd1811`](https://github.com/withastro/starlight/commit/c5cd181186b42422f3e47052bf8182cb490bda6b) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes a UI strings translation issue for sites configured with a single non-root language different from English.
|
|
10
|
+
|
|
11
|
+
- [#1723](https://github.com/withastro/starlight/pull/1723) [`3b29b3ab`](https://github.com/withastro/starlight/commit/3b29b3ab824f538f27e20310cb08786a92c7bd65) Thanks [@OliverSpeir](https://github.com/OliverSpeir)! - Fixes accessibility by using `aria-selected="false"` for inactive tabs instead of removing `aria-selected="true"` in the tablist of Starlight’s `<Tabs>` component
|
|
12
|
+
|
|
13
|
+
- [#1706](https://github.com/withastro/starlight/pull/1706) [`f171ac4d`](https://github.com/withastro/starlight/commit/f171ac4d6396eb2538598d85957670df50938b6a) Thanks [@jorenbroekema](https://github.com/jorenbroekema)! - Fixes some minor type errors
|
|
14
|
+
|
|
15
|
+
## 0.21.4
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#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.
|
|
20
|
+
|
|
21
|
+
- [#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
|
|
22
|
+
|
|
3
23
|
## 0.21.3
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/components/Icons.ts
CHANGED
|
@@ -125,6 +125,7 @@ export const BuiltInIcons = {
|
|
|
125
125
|
nix: '<path d="M7.4 1.6H6l-.7 1.1L7 5.5H3.7L2.4 7.8h11.7l-1.3-2.3H9.6l-2.2-4zm6.1 0h-2.7l5.9 10.1L18 9.4l-1.6-2.8 2.3-3.8-.7-1.2h-1.3L15 4.3l-1.6-2.7zm7 4.2-6 10.1h2.8l1.6-2.8h4.4L24 12l-.7-1.2h-3.1l1.6-2.7-1.4-2.3zM9.4 8H6.6L5 10.8H.7L0 12l.7 1.2h3.1l-1.6 2.7 1.4 2.3zm-2.2 4.2L6 14.6l1.6 2.8-2.3 3.8.7 1.2h1.3L9 19.7l1.6 2.7h2.7zm2.6 3.9 1.3 2.3h3.2l2.2 3.9H18l.7-1.2-1.6-2.7h3.2l1.3-2.3z"/>',
|
|
126
126
|
starlight:
|
|
127
127
|
'<path fill-rule="evenodd" d="M15.19 6.75 12 0 8.81 6.75l-.19.38-1.68-1.88a1.2 1.2 0 1 0-1.69 1.69L7.13 8.8h-.38L0 12l6.75 3.19h.38l-1.88 1.87a1.2 1.2 0 1 0 1.69 1.69l1.68-1.88.2.38L12 24l3.19-6.75v-.38l1.69 1.88a1.2 1.2 0 1 0 1.68-1.69l-1.68-1.68.37-.2L24 12l-6.75-3.19-.38-.19 1.7-1.68a1.2 1.2 0 1 0-1.7-1.69L15.2 7.13v-.38ZM12 7.13l-.38.93a8.18 8.18 0 0 1-3.56 3.56l-.94.38.94.38a8.18 8.18 0 0 1 3.56 3.56l.38.94.38-.94a8.18 8.18 0 0 1 3.56-3.56l.94-.38-.94-.38a8.18 8.18 0 0 1-3.56-3.56L12 7.12Z"/><path d="M22.12 3.56a1.2 1.2 0 1 0-1.68-1.69l-.57.57a1.2 1.2 0 0 0 1.7 1.68l.55-.56Zm-18 .75c-.37.38-1.12.38-1.68 0l-.57-.56a1.2 1.2 0 0 1 1.7-1.69l.55.56c.57.38.57 1.13 0 1.7Zm0 15.38c-.37-.38-1.12-.38-1.68 0l-.57.56a1.2 1.2 0 1 0 1.7 1.69l.55-.57c.57-.37.57-1.12 0-1.68Zm18 .75a1.2 1.2 0 1 1-1.68 1.68l-.57-.56a1.2 1.2 0 0 1 1.7-1.69l.55.57Z"/>',
|
|
128
|
+
pkl: '<path fill-rule="evenodd" d="M18.7 1.8 18 5a9 9 0 0 1 2 2.4l3.2.2c.4 1 .6 2 .7 3.1L21 12.2a9 9 0 0 1-.7 3l1.9 2.7c-.6 1-1.2 1.7-2 2.5l-3-1.3c-.9.6-1.9 1-2.9 1.4l-.9 3c-1 .2-2.1.2-3.2 0l-.8-3c-1-.4-2-.8-2.9-1.5l-3 1.3a12 12 0 0 1-2-2.5l2-2.6a9 9 0 0 1-.8-3L0 10.5c.1-1.1.3-2.1.7-3.1L4 7.3A9 9 0 0 1 6 5l-.6-3.2c1-.6 2-1 3-1.3l2 2.4c1.1-.2 2.2-.2 3.2 0L15.8.4c1 .3 2 .8 2.9 1.4Zm1 9.8c0 4.2-3.3 7.5-7.5 7.5a7.5 7.5 0 0 1-7.6-7.5c0-4.1 3.4-7.5 7.6-7.5 4.2 0 7.6 3.4 7.6 7.5Z"></path><path fill-opacity=".5" d="M11.4 10.8c-6.6-2.7-3.6-5.5.4-5.5 4.3 0 7.8 2.5 1.2 5.5a2 2 0 0 1-1.6 0Zm.4 1.9c1 7-3 5.8-5 2.5-2.1-3.7-1.7-8 4.2-3.9a2 2 0 0 1 .8 1.4Zm6.2 1.7c2-3.3 1-7.3-4.7-3a2 2 0 0 0-.8 1.4c-.7 7.1 3.3 5.4 5.5 1.7Z"/>',
|
|
128
129
|
};
|
|
129
130
|
|
|
130
131
|
export const Icons = {
|
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
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AstroConfig } from 'astro';
|
|
1
2
|
import type { StarlightConfig } from '../../types';
|
|
2
3
|
|
|
3
4
|
function slugToLocale(
|
|
@@ -17,7 +18,7 @@ export function pathToLocale(
|
|
|
17
18
|
astroConfig,
|
|
18
19
|
}: {
|
|
19
20
|
starlightConfig: { locales: StarlightConfig['locales'] };
|
|
20
|
-
astroConfig: { root:
|
|
21
|
+
astroConfig: { root: AstroConfig['root']; srcDir: AstroConfig['srcDir'] };
|
|
21
22
|
}
|
|
22
23
|
): string | undefined {
|
|
23
24
|
const srcDir = new URL(astroConfig.srcDir, astroConfig.root);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/starlight",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.5",
|
|
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
|
},
|
|
@@ -17,7 +17,7 @@ const { html, panels } = processPanels(panelHtml);
|
|
|
17
17
|
role="tab"
|
|
18
18
|
href={'#' + panelId}
|
|
19
19
|
id={tabId}
|
|
20
|
-
aria-selected={idx === 0
|
|
20
|
+
aria-selected={idx === 0 ? 'true' : 'false'}
|
|
21
21
|
tabindex={idx !== 0 ? -1 : 0}
|
|
22
22
|
>
|
|
23
23
|
{icon && <Icon name={icon} />}
|
|
@@ -61,7 +61,7 @@ const { html, panels } = processPanels(panelHtml);
|
|
|
61
61
|
color: var(--sl-color-gray-3);
|
|
62
62
|
outline-offset: var(--sl-outline-offset-inside);
|
|
63
63
|
}
|
|
64
|
-
.tab [role='tab'][aria-selected] {
|
|
64
|
+
.tab [role='tab'][aria-selected='true'] {
|
|
65
65
|
color: var(--sl-color-white);
|
|
66
66
|
border-color: var(--sl-color-text-accent);
|
|
67
67
|
font-weight: 600;
|
|
@@ -87,7 +87,7 @@ const { html, panels } = processPanels(panelHtml);
|
|
|
87
87
|
// Handle clicks for mouse users
|
|
88
88
|
tab.addEventListener('click', (e) => {
|
|
89
89
|
e.preventDefault();
|
|
90
|
-
const currentTab = tablist.querySelector('[aria-selected]');
|
|
90
|
+
const currentTab = tablist.querySelector('[aria-selected="true"]');
|
|
91
91
|
if (e.currentTarget !== currentTab) {
|
|
92
92
|
this.switchTab(e.currentTarget as HTMLAnchorElement, i);
|
|
93
93
|
}
|
|
@@ -122,7 +122,7 @@ const { html, panels } = processPanels(panelHtml);
|
|
|
122
122
|
|
|
123
123
|
// Mark all tabs as unselected and hide all tab panels.
|
|
124
124
|
this.tabs.forEach((tab) => {
|
|
125
|
-
tab.
|
|
125
|
+
tab.setAttribute('aria-selected', 'false');
|
|
126
126
|
tab.setAttribute('tabindex', '-1');
|
|
127
127
|
});
|
|
128
128
|
this.panels.forEach((oldPanel) => {
|
|
@@ -168,7 +168,7 @@ function getFileIcon(fileName: string) {
|
|
|
168
168
|
|
|
169
169
|
/** Return the icon name for a file based on its file name. */
|
|
170
170
|
function getFileIconName(fileName: string) {
|
|
171
|
-
let icon = definitions.files[fileName];
|
|
171
|
+
let icon: string | undefined = definitions.files[fileName];
|
|
172
172
|
if (icon) return icon;
|
|
173
173
|
icon = getFileIconTypeFromExtension(fileName);
|
|
174
174
|
if (icon) return icon;
|
package/utils/user-config.ts
CHANGED
|
@@ -212,16 +212,20 @@ const UserConfigSchema = z.object({
|
|
|
212
212
|
|
|
213
213
|
export const StarlightConfigSchema = UserConfigSchema.strict().transform(
|
|
214
214
|
({ locales, defaultLocale, ...config }, ctx) => {
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
const configuredLocales = Object.keys(locales ?? {});
|
|
216
|
+
|
|
217
|
+
// This is a multilingual site (more than one locale configured) or a monolingual site with
|
|
218
|
+
// only one locale configured (not a root locale).
|
|
219
|
+
// Monolingual sites with only one non-root locale needs their configuration to be defined in
|
|
220
|
+
// `config.locales` so that slugs can be correctly generated by taking into consideration the
|
|
221
|
+
// base path at which a language is served which is the key of the `config.locales` object.
|
|
222
|
+
if (locales !== undefined && configuredLocales.length >= 1) {
|
|
217
223
|
// Make sure we can find the default locale and if not, help the user set it.
|
|
218
224
|
// We treat the root locale as the default if present and no explicit default is set.
|
|
219
225
|
const defaultLocaleConfig = locales[defaultLocale || 'root'];
|
|
220
226
|
|
|
221
227
|
if (!defaultLocaleConfig) {
|
|
222
|
-
const availableLocales =
|
|
223
|
-
.map((l) => `"${l}"`)
|
|
224
|
-
.join(', ');
|
|
228
|
+
const availableLocales = configuredLocales.map((l) => `"${l}"`).join(', ');
|
|
225
229
|
ctx.addIssue({
|
|
226
230
|
code: 'custom',
|
|
227
231
|
message:
|
|
@@ -235,14 +239,15 @@ export const StarlightConfigSchema = UserConfigSchema.strict().transform(
|
|
|
235
239
|
return {
|
|
236
240
|
...config,
|
|
237
241
|
/** Flag indicating if this site has multiple locales set up. */
|
|
238
|
-
isMultilingual:
|
|
242
|
+
isMultilingual: configuredLocales.length > 1,
|
|
239
243
|
/** Full locale object for this site’s default language. */
|
|
240
244
|
defaultLocale: { ...defaultLocaleConfig, locale: defaultLocale },
|
|
241
245
|
locales,
|
|
242
246
|
} as const;
|
|
243
247
|
}
|
|
244
248
|
|
|
245
|
-
// This is a monolingual site, so things are
|
|
249
|
+
// This is a monolingual site with no locales configured or only a root locale, so things are
|
|
250
|
+
// pretty simple.
|
|
246
251
|
return {
|
|
247
252
|
...config,
|
|
248
253
|
/** Flag indicating if this site has multiple locales set up. */
|