@astrojs/starlight 0.0.12 → 0.0.14
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 +26 -0
- package/components/PrevNextLinks.astro +1 -1
- package/components/Search.astro +6 -2
- package/components/ThemeProvider.astro +0 -8
- package/global.d.ts +5 -0
- package/package.json +3 -3
- package/translations/index.ts +2 -1
- package/translations/ja.json +20 -0
- package/utils/i18n.ts +16 -0
- package/utils/navigation.ts +15 -5
- package/utils/routing.ts +4 -1
- package/utils/slugs.ts +1 -0
- package/utils/user-config.ts +30 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @astrojs/starlight
|
|
2
2
|
|
|
3
|
+
## 0.0.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#95](https://github.com/withastro/starlight/pull/95) [`de24b54`](https://github.com/withastro/starlight/commit/de24b54971577912979a3fb67570f4c95efe27a6) Thanks [@delucis](https://github.com/delucis)! - Support translations in sidebar config
|
|
8
|
+
|
|
9
|
+
- [#97](https://github.com/withastro/starlight/pull/97) [`2d51762`](https://github.com/withastro/starlight/commit/2d517623fb8670d4e7f2656eacff0d5beb27d95a) Thanks [@morinokami](https://github.com/morinokami)! - Add Japanese language support
|
|
10
|
+
|
|
11
|
+
## 0.0.13
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`8688778`](https://github.com/withastro/starlight/commit/86887786d158e4cdb9e4bd021b2232eb6dba284c) Thanks [@delucis](https://github.com/delucis)! - Fix small CSS compatibility issue
|
|
16
|
+
|
|
17
|
+
- [#93](https://github.com/withastro/starlight/pull/93) [`c6d7960`](https://github.com/withastro/starlight/commit/c6d7960c8673886eb2b17843e78a897133c05fe2) Thanks [@delucis](https://github.com/delucis)! - Fix default locale routing bug when not using root locale
|
|
18
|
+
|
|
19
|
+
- [`d8a171b`](https://github.com/withastro/starlight/commit/d8a171b6b45c73151485fe8f08630fb6a1cc12a6) Thanks [@delucis](https://github.com/delucis)! - Fix autogenerated sidebar bug with index routes in subdirectories
|
|
20
|
+
|
|
21
|
+
- [`d8b9f32`](https://github.com/withastro/starlight/commit/d8b9f3260daaceed8a31eedcc44bd00733f96254) Thanks [@delucis](https://github.com/delucis)! - Fix false positive in sidebar autogeneration logic
|
|
22
|
+
|
|
23
|
+
- [#92](https://github.com/withastro/starlight/pull/92) [`02821d2`](https://github.com/withastro/starlight/commit/02821d2c8a58c485697cb8f0770c6ba63e709b2a) Thanks [@delucis](https://github.com/delucis)! - Update Pagefind to latest v1 alpha
|
|
24
|
+
|
|
25
|
+
- [`51fe914`](https://github.com/withastro/starlight/commit/51fe91468fea125ec33cb6d6b1b66f147302fdc0) Thanks [@delucis](https://github.com/delucis)! - Guarantee route and autogenerated sidebar sort order
|
|
26
|
+
|
|
27
|
+
- [`116c4f5`](https://github.com/withastro/starlight/commit/116c4f5eb0ddf4dddbd10005bc72a7e6cb880a67) Thanks [@delucis](https://github.com/delucis)! - Fix minor dev layout bug in Search modal for RTL languages
|
|
28
|
+
|
|
3
29
|
## 0.0.12
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/components/Search.astro
CHANGED
|
@@ -34,7 +34,7 @@ const t = useTranslations(Astro.props.locale);
|
|
|
34
34
|
</button>
|
|
35
35
|
{
|
|
36
36
|
import.meta.env.DEV ? (
|
|
37
|
-
<div style="margin: auto; text-align: center;">
|
|
37
|
+
<div style="margin: auto; text-align: center;" dir="ltr">
|
|
38
38
|
<p>Search is only available in production builds.</p>
|
|
39
39
|
<p>Try building and previewing the site to test it out locally.</p>
|
|
40
40
|
</div>
|
|
@@ -63,7 +63,11 @@ const t = useTranslations(Astro.props.locale);
|
|
|
63
63
|
|
|
64
64
|
/** Close the modal if a user clicks outside of the modal. */
|
|
65
65
|
const onWindowClick = (event: MouseEvent) => {
|
|
66
|
-
if (
|
|
66
|
+
if (
|
|
67
|
+
document.body.contains(event.target as Node) &&
|
|
68
|
+
!dialogFrame.contains(event.target as Node)
|
|
69
|
+
)
|
|
70
|
+
closeModal();
|
|
67
71
|
};
|
|
68
72
|
|
|
69
73
|
const openModal = (event?: MouseEvent) => {
|
|
@@ -2,14 +2,6 @@
|
|
|
2
2
|
import Icon from './Icon.astro';
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
<script>
|
|
6
|
-
declare global {
|
|
7
|
-
var StarlightThemeProvider: {
|
|
8
|
-
updatePickers(theme?: string): void;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
</script>
|
|
12
|
-
|
|
13
5
|
{/* This is intentionally inlined to avoid FOUC. */}
|
|
14
6
|
<script is:inline>
|
|
15
7
|
window.StarlightThemeProvider = (() => {
|
package/global.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/starlight",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "Build beautiful, high-performance documentation websites with Astro",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@astrojs/mdx": "^0.19.1",
|
|
38
38
|
"@astrojs/sitemap": "^1.3.1",
|
|
39
|
-
"@pagefind/default-ui": "^0.
|
|
39
|
+
"@pagefind/default-ui": "^1.0.0-alpha.5",
|
|
40
40
|
"@types/mdast": "^3.0.11",
|
|
41
41
|
"bcp-47": "^2.1.0",
|
|
42
42
|
"execa": "^7.1.1",
|
|
43
43
|
"hastscript": "^7.2.0",
|
|
44
|
-
"pagefind": "^0.
|
|
44
|
+
"pagefind": "^1.0.0-alpha.5",
|
|
45
45
|
"rehype": "^12.0.1",
|
|
46
46
|
"remark-directive": "^2.0.1",
|
|
47
47
|
"unified": "^10.1.2",
|
package/translations/index.ts
CHANGED
|
@@ -2,9 +2,10 @@ import { i18nSchema } from '../schemas/i18n';
|
|
|
2
2
|
import en from './en.json';
|
|
3
3
|
import es from './es.json';
|
|
4
4
|
import de from './de.json';
|
|
5
|
+
import ja from './ja.json';
|
|
5
6
|
|
|
6
7
|
const parse = i18nSchema().required().strict().parse;
|
|
7
8
|
|
|
8
9
|
export default Object.fromEntries(
|
|
9
|
-
Object.entries({ en, es, de }).map(([key, dict]) => [key, parse(dict)])
|
|
10
|
+
Object.entries({ en, es, de, ja }).map(([key, dict]) => [key, parse(dict)])
|
|
10
11
|
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"skipLink.label": "コンテンツにスキップ",
|
|
3
|
+
"search.label": "検索",
|
|
4
|
+
"search.shortcutLabel": "(/を押して検索)",
|
|
5
|
+
"search.cancelLabel": "キャンセル",
|
|
6
|
+
"themeSelect.accessibleLabel": "テーマの選択",
|
|
7
|
+
"themeSelect.dark": "ダーク",
|
|
8
|
+
"themeSelect.light": "ライト",
|
|
9
|
+
"themeSelect.auto": "自動",
|
|
10
|
+
"languageSelect.accessibleLabel": "言語の選択",
|
|
11
|
+
"menuButton.accessibleLabel": "メニュー",
|
|
12
|
+
"sidebarNav.accessibleLabel": "メイン",
|
|
13
|
+
"tableOfContents.onThisPage": "目次",
|
|
14
|
+
"tableOfContents.overview": "概要",
|
|
15
|
+
"i18n.untranslatedContent": "このコンテンツはまだ日本語訳がありません。",
|
|
16
|
+
"page.editLink": "ページを編集",
|
|
17
|
+
"page.lastUpdated": "最終更新日:",
|
|
18
|
+
"page.previousLink": "前へ",
|
|
19
|
+
"page.nextLink": "次へ"
|
|
20
|
+
}
|
package/utils/i18n.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the string for the passed language from a dictionary object.
|
|
3
|
+
*
|
|
4
|
+
* TODO: Make this clever. Currently a simple key look-up, but should use
|
|
5
|
+
* BCP-47 mapping so that e.g. `en-US` returns `en` strings, and use the
|
|
6
|
+
* site’s default locale as a last resort.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* pickLang({ en: 'Hello', fr: 'Bonjour' }, 'en'); // => 'Hello'
|
|
10
|
+
*/
|
|
11
|
+
export function pickLang<T extends Record<string, string>>(
|
|
12
|
+
dictionary: T,
|
|
13
|
+
lang: keyof T
|
|
14
|
+
): string | undefined {
|
|
15
|
+
return dictionary[lang];
|
|
16
|
+
}
|
package/utils/navigation.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { basename, dirname } from 'node:path';
|
|
2
2
|
import config from 'virtual:starlight/user-config';
|
|
3
3
|
import { withBase } from './base';
|
|
4
|
+
import { pickLang } from './i18n';
|
|
4
5
|
import { Route, getLocaleRoutes, routes } from './routing';
|
|
5
|
-
import { slugToPathname } from './slugs';
|
|
6
|
+
import { localeToLang, slugToPathname } from './slugs';
|
|
6
7
|
import type {
|
|
7
8
|
AutoSidebarGroup,
|
|
8
9
|
SidebarItem,
|
|
@@ -48,7 +49,7 @@ function configItemToEntry(
|
|
|
48
49
|
} else {
|
|
49
50
|
return {
|
|
50
51
|
type: 'group',
|
|
51
|
-
label: item.label,
|
|
52
|
+
label: pickLang(item.translations, localeToLang(locale)) || item.label,
|
|
52
53
|
entries: item.items.map((i) =>
|
|
53
54
|
configItemToEntry(i, currentPathname, locale, routes)
|
|
54
55
|
),
|
|
@@ -65,11 +66,17 @@ function groupFromAutogenerateConfig(
|
|
|
65
66
|
): Group {
|
|
66
67
|
const { directory } = item.autogenerate;
|
|
67
68
|
const localeDir = locale ? locale + '/' + directory : directory;
|
|
68
|
-
const dirDocs = routes.filter(
|
|
69
|
+
const dirDocs = routes.filter(
|
|
70
|
+
(doc) =>
|
|
71
|
+
// Match against `foo.md` or `foo/index.md`.
|
|
72
|
+
doc.slug === localeDir ||
|
|
73
|
+
// Match against `foo/anything/else.md`.
|
|
74
|
+
doc.slug.startsWith(localeDir + '/')
|
|
75
|
+
);
|
|
69
76
|
const tree = treeify(dirDocs, localeDir);
|
|
70
77
|
return {
|
|
71
78
|
type: 'group',
|
|
72
|
-
label: item.label,
|
|
79
|
+
label: pickLang(item.translations, localeToLang(locale)) || item.label,
|
|
73
80
|
entries: sidebarFromDir(tree, currentPathname, locale),
|
|
74
81
|
};
|
|
75
82
|
}
|
|
@@ -96,7 +103,8 @@ function linkFromConfig(
|
|
|
96
103
|
// Inject current locale into link.
|
|
97
104
|
if (locale) href = '/' + locale + href;
|
|
98
105
|
}
|
|
99
|
-
|
|
106
|
+
const label = pickLang(item.translations, localeToLang(locale)) || item.label;
|
|
107
|
+
return makeLink(href, label, currentPathname);
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
/** Create a link entry. */
|
|
@@ -108,6 +116,8 @@ function makeLink(href: string, label: string, currentPathname: string): Link {
|
|
|
108
116
|
|
|
109
117
|
/** Get the segments leading to a page. */
|
|
110
118
|
function getBreadcrumbs(slug: string, baseDir: string): string[] {
|
|
119
|
+
// Index slugs will match `baseDir` and don’t include breadcrumbs.
|
|
120
|
+
if (slug === baseDir) return [];
|
|
111
121
|
// Ensure base directory ends in a trailing slash.
|
|
112
122
|
if (!baseDir.endsWith('/')) baseDir += '/';
|
|
113
123
|
// Strip base directory from slug if present.
|
package/utils/routing.ts
CHANGED
|
@@ -76,7 +76,10 @@ function getRoutes(): Route[] {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
// Sort alphabetically by page slug to guarantee order regardless of platform.
|
|
80
|
+
return routes.sort((a, b) =>
|
|
81
|
+
a.slug < b.slug ? -1 : a.slug > b.slug ? 1 : 0
|
|
82
|
+
);
|
|
80
83
|
}
|
|
81
84
|
export const routes = getRoutes();
|
|
82
85
|
|
package/utils/slugs.ts
CHANGED
|
@@ -82,6 +82,7 @@ export function localizedSlug(
|
|
|
82
82
|
const slugLocale = slugToLocale(slug);
|
|
83
83
|
if (slugLocale === locale) return slug;
|
|
84
84
|
locale = locale || '';
|
|
85
|
+
if (slugLocale === slug) return locale;
|
|
85
86
|
if (slugLocale) {
|
|
86
87
|
return slug
|
|
87
88
|
.replace(slugLocale + '/', locale ? locale + '/' : '')
|
package/utils/user-config.ts
CHANGED
|
@@ -27,17 +27,20 @@ const LocaleSchema = z.object({
|
|
|
27
27
|
),
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const SidebarBaseSchema = z.object({
|
|
31
31
|
/** The visible label for this item in the sidebar. */
|
|
32
32
|
label: z.string(),
|
|
33
|
+
/** Translations of the `label` for each supported language. */
|
|
34
|
+
translations: z.record(z.string()).default({}),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const SidebarLinkItemSchema = SidebarBaseSchema.extend({
|
|
33
38
|
/** The link to this item’s content. Can be a relative link to local files or the full URL of an external page. */
|
|
34
39
|
link: z.string(),
|
|
35
40
|
});
|
|
36
41
|
export type SidebarLinkItem = z.infer<typeof SidebarLinkItemSchema>;
|
|
37
42
|
|
|
38
|
-
const AutoSidebarGroupSchema =
|
|
39
|
-
/** The visible label for this item in the sidebar. */
|
|
40
|
-
label: z.string(),
|
|
43
|
+
const AutoSidebarGroupSchema = SidebarBaseSchema.extend({
|
|
41
44
|
/** Enable autogenerating a sidebar category from a specific docs directory. */
|
|
42
45
|
autogenerate: z.object({
|
|
43
46
|
/** The directory to generate sidebar items for. */
|
|
@@ -49,20 +52,29 @@ const AutoSidebarGroupSchema = z.object({
|
|
|
49
52
|
});
|
|
50
53
|
export type AutoSidebarGroup = z.infer<typeof AutoSidebarGroupSchema>;
|
|
51
54
|
|
|
52
|
-
type
|
|
53
|
-
/** The visible label for this item in the sidebar. */
|
|
54
|
-
label: string;
|
|
55
|
+
type ManualSidebarGroupInput = z.input<typeof SidebarBaseSchema> & {
|
|
55
56
|
/** Array of links and subcategories to display in this category. */
|
|
56
57
|
items: Array<
|
|
57
|
-
|
|
|
58
|
-
| z.
|
|
59
|
-
|
|
|
58
|
+
| z.input<typeof SidebarLinkItemSchema>
|
|
59
|
+
| z.input<typeof AutoSidebarGroupSchema>
|
|
60
|
+
| ManualSidebarGroupInput
|
|
60
61
|
>;
|
|
61
62
|
};
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
|
|
64
|
+
type ManualSidebarGroupOutput = z.output<typeof SidebarBaseSchema> & {
|
|
65
|
+
/** Array of links and subcategories to display in this category. */
|
|
66
|
+
items: Array<
|
|
67
|
+
| z.output<typeof SidebarLinkItemSchema>
|
|
68
|
+
| z.output<typeof AutoSidebarGroupSchema>
|
|
69
|
+
| ManualSidebarGroupOutput
|
|
70
|
+
>;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const ManualSidebarGroupSchema: z.ZodType<
|
|
74
|
+
ManualSidebarGroupOutput,
|
|
75
|
+
z.ZodTypeDef,
|
|
76
|
+
ManualSidebarGroupInput
|
|
77
|
+
> = SidebarBaseSchema.extend({
|
|
66
78
|
/** Array of links and subcategories to display in this category. */
|
|
67
79
|
items: z.lazy(() =>
|
|
68
80
|
z
|
|
@@ -83,7 +95,11 @@ const SidebarItemSchema = z.union([
|
|
|
83
95
|
export type SidebarItem = z.infer<typeof SidebarItemSchema>;
|
|
84
96
|
|
|
85
97
|
const SidebarGroupSchema: z.ZodType<
|
|
86
|
-
|
|
98
|
+
| z.output<typeof ManualSidebarGroupSchema>
|
|
99
|
+
| z.output<typeof AutoSidebarGroupSchema>,
|
|
100
|
+
z.ZodTypeDef,
|
|
101
|
+
| z.input<typeof ManualSidebarGroupSchema>
|
|
102
|
+
| z.input<typeof AutoSidebarGroupSchema>
|
|
87
103
|
> = z.union([ManualSidebarGroupSchema, AutoSidebarGroupSchema]);
|
|
88
104
|
|
|
89
105
|
const UserConfigSchema = z.object({
|