@astrojs/starlight 0.19.0 → 0.19.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/CHANGELOG.md +10 -0
- package/package.json +1 -1
- package/props.ts +1 -0
- package/translations/index.ts +2 -0
- package/translations/zh-TW.json +26 -0
- package/utils/starlight-page.ts +97 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @astrojs/starlight
|
|
2
2
|
|
|
3
|
+
## 0.19.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1527](https://github.com/withastro/starlight/pull/1527) [`163bc84`](https://github.com/withastro/starlight/commit/163bc848e173eecca92d1cb034045fdb42aa4ff1) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Exports the `StarlightPageProps` TypeScript type representing the props expected by the `<StarlightPage />` component.
|
|
8
|
+
|
|
9
|
+
- [#1504](https://github.com/withastro/starlight/pull/1504) [`fc83a05`](https://github.com/withastro/starlight/commit/fc83a05235b74be2bfe6ba8e7f95a8a5a618ead3) Thanks [@mingjunlu](https://github.com/mingjunlu)! - Adds Traditional Chinese UI translations
|
|
10
|
+
|
|
11
|
+
- [#1534](https://github.com/withastro/starlight/pull/1534) [`aada680`](https://github.com/withastro/starlight/commit/aada6805abc0068f07393585b86978ef5200439c) Thanks [@delucis](https://github.com/delucis)! - Improves DX of the `sidebar` prop used by the new `<StarlightPage>` component.
|
|
12
|
+
|
|
3
13
|
## 0.19.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/package.json
CHANGED
package/props.ts
CHANGED
package/translations/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ import ru from './ru.json';
|
|
|
24
24
|
import vi from './vi.json';
|
|
25
25
|
import uk from './uk.json';
|
|
26
26
|
import hi from './hi.json';
|
|
27
|
+
import zhTW from './zh-TW.json';
|
|
27
28
|
|
|
28
29
|
const { parse } = builtinI18nSchema();
|
|
29
30
|
|
|
@@ -54,5 +55,6 @@ export default Object.fromEntries(
|
|
|
54
55
|
vi,
|
|
55
56
|
uk,
|
|
56
57
|
hi,
|
|
58
|
+
'zh-TW': zhTW,
|
|
57
59
|
}).map(([key, dict]) => [key, parse(dict)])
|
|
58
60
|
);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"skipLink.label": "跳到內容",
|
|
3
|
+
"search.label": "搜尋",
|
|
4
|
+
"search.shortcutLabel": "(按 / 鍵開始搜尋)",
|
|
5
|
+
"search.cancelLabel": "取消",
|
|
6
|
+
"search.devWarning": "正式版本才能使用搜尋功能。\n如要在本地測試,請先建置並預覽網站。",
|
|
7
|
+
"themeSelect.accessibleLabel": "選擇佈景主題",
|
|
8
|
+
"themeSelect.dark": "深色",
|
|
9
|
+
"themeSelect.light": "淺色",
|
|
10
|
+
"themeSelect.auto": "自動",
|
|
11
|
+
"languageSelect.accessibleLabel": "選擇語言",
|
|
12
|
+
"menuButton.accessibleLabel": "選單",
|
|
13
|
+
"sidebarNav.accessibleLabel": "主要",
|
|
14
|
+
"tableOfContents.onThisPage": "本頁內容",
|
|
15
|
+
"tableOfContents.overview": "概述",
|
|
16
|
+
"i18n.untranslatedContent": "本頁內容尚未翻譯。",
|
|
17
|
+
"page.editLink": "編輯頁面",
|
|
18
|
+
"page.lastUpdated": "最後更新於:",
|
|
19
|
+
"page.previousLink": "前一則",
|
|
20
|
+
"page.nextLink": "下一則",
|
|
21
|
+
"404.text": "找不到頁面。請檢查網址或改用搜尋功能。",
|
|
22
|
+
"aside.note": "注意",
|
|
23
|
+
"aside.tip": "提示",
|
|
24
|
+
"aside.caution": "警告",
|
|
25
|
+
"aside.danger": "危險"
|
|
26
|
+
}
|
package/utils/starlight-page.ts
CHANGED
|
@@ -9,6 +9,8 @@ import { slugToLocaleData, urlToSlug } from './slugs';
|
|
|
9
9
|
import { getPrevNextLinks, getSidebar } from './navigation';
|
|
10
10
|
import { useTranslations } from './translations';
|
|
11
11
|
import { docsSchema } from '../schema';
|
|
12
|
+
import { BadgeConfigSchema } from '../schemas/badge';
|
|
13
|
+
import { SidebarLinkItemHTMLAttributesSchema } from '../schemas/sidebar';
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* The frontmatter schema for Starlight pages derived from the default schema for Starlight’s
|
|
@@ -56,6 +58,96 @@ type StarlightPageFrontmatter = Omit<
|
|
|
56
58
|
'editUrl' | 'sidebar'
|
|
57
59
|
> & { editUrl?: string | false };
|
|
58
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Link configuration schema for `<StarlightPage>`.
|
|
63
|
+
* Sets default values where possible to be more user friendly than raw `SidebarEntry` type.
|
|
64
|
+
*/
|
|
65
|
+
const LinkSchema = z
|
|
66
|
+
.object({
|
|
67
|
+
/** @deprecated Specifying `type` is no longer required. */
|
|
68
|
+
type: z.literal('link').default('link'),
|
|
69
|
+
label: z.string(),
|
|
70
|
+
href: z.string(),
|
|
71
|
+
isCurrent: z.boolean().default(false),
|
|
72
|
+
badge: BadgeConfigSchema(),
|
|
73
|
+
attrs: SidebarLinkItemHTMLAttributesSchema(),
|
|
74
|
+
})
|
|
75
|
+
// Make sure badge is in the object even if undefined — Zod doesn’t seem to have a way to set `undefined` as a default.
|
|
76
|
+
.transform((item) => ({ badge: undefined, ...item }));
|
|
77
|
+
|
|
78
|
+
/** Base schema for link groups without the recursive `items` array. */
|
|
79
|
+
const LinkGroupBase = z.object({
|
|
80
|
+
/** @deprecated Specifying `type` is no longer required. */
|
|
81
|
+
type: z.literal('group').default('group'),
|
|
82
|
+
label: z.string(),
|
|
83
|
+
collapsed: z.boolean().default(false),
|
|
84
|
+
badge: BadgeConfigSchema(),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// These manual types are needed to correctly type the recursive link group type.
|
|
88
|
+
type ManualLinkGroupInput = Prettify<
|
|
89
|
+
z.input<typeof LinkGroupBase> &
|
|
90
|
+
// The original implementation of `<StarlightPage>` in v0.19.0 used `entries`.
|
|
91
|
+
// We want to use `items` so it matches the sidebar config in `astro.config.mjs`.
|
|
92
|
+
// Keeping `entries` support for now to not break anyone.
|
|
93
|
+
// TODO: warn about `entries` usage in a future version
|
|
94
|
+
// TODO: remove support for `entries` in a future version
|
|
95
|
+
(| {
|
|
96
|
+
/** Array of links and subcategories to display in this category. */
|
|
97
|
+
items: Array<z.input<typeof LinkSchema> | ManualLinkGroupInput>;
|
|
98
|
+
}
|
|
99
|
+
| {
|
|
100
|
+
/**
|
|
101
|
+
* @deprecated Use `items` instead of `entries`.
|
|
102
|
+
* Support for `entries` will be removed in a future version of Starlight.
|
|
103
|
+
*/
|
|
104
|
+
entries: Array<z.input<typeof LinkSchema> | ManualLinkGroupInput>;
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
>;
|
|
108
|
+
type ManualLinkGroupOutput = z.output<typeof LinkGroupBase> & {
|
|
109
|
+
entries: Array<z.output<typeof LinkSchema> | ManualLinkGroupOutput>;
|
|
110
|
+
badge: z.output<typeof LinkGroupBase>['badge'];
|
|
111
|
+
};
|
|
112
|
+
type LinkGroupSchemaType = z.ZodType<ManualLinkGroupOutput, z.ZodTypeDef, ManualLinkGroupInput>;
|
|
113
|
+
/**
|
|
114
|
+
* Link group configuration schema for `<StarlightPage>`.
|
|
115
|
+
* Sets default values where possible to be more user friendly than raw `SidebarEntry` type.
|
|
116
|
+
*/
|
|
117
|
+
const LinkGroupSchema: LinkGroupSchemaType = z.preprocess(
|
|
118
|
+
// Map `items` to `entries` as expected by the `SidebarEntry` type.
|
|
119
|
+
(arg) => {
|
|
120
|
+
if (arg && typeof arg === 'object' && 'items' in arg) {
|
|
121
|
+
const { items, ...rest } = arg;
|
|
122
|
+
return { ...rest, entries: items };
|
|
123
|
+
}
|
|
124
|
+
return arg;
|
|
125
|
+
},
|
|
126
|
+
LinkGroupBase.extend({
|
|
127
|
+
entries: z.lazy(() => z.union([LinkSchema, LinkGroupSchema]).array()),
|
|
128
|
+
})
|
|
129
|
+
// Make sure badge is in the object even if undefined.
|
|
130
|
+
.transform((item) => ({ badge: undefined, ...item }))
|
|
131
|
+
) as LinkGroupSchemaType;
|
|
132
|
+
|
|
133
|
+
/** Sidebar configuration schema for `<StarlightPage>` */
|
|
134
|
+
const StarlightPageSidebarSchema = z.union([LinkSchema, LinkGroupSchema]).array();
|
|
135
|
+
type StarlightPageSidebarUserConfig = z.input<typeof StarlightPageSidebarSchema>;
|
|
136
|
+
|
|
137
|
+
/** Parse sidebar prop to ensure all required defaults are in place. */
|
|
138
|
+
const normalizeSidebarProp = (
|
|
139
|
+
sidebarProp: StarlightPageSidebarUserConfig
|
|
140
|
+
): StarlightRouteData['sidebar'] => {
|
|
141
|
+
const sidebar = StarlightPageSidebarSchema.safeParse(sidebarProp, { errorMap });
|
|
142
|
+
if (!sidebar.success) {
|
|
143
|
+
throwValidationError(
|
|
144
|
+
sidebar.error,
|
|
145
|
+
'Invalid sidebar prop passed to the `<StarlightPage/>` component.'
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return sidebar.data;
|
|
149
|
+
};
|
|
150
|
+
|
|
59
151
|
/**
|
|
60
152
|
* The props accepted by the `<StarlightPage/>` component.
|
|
61
153
|
*/
|
|
@@ -63,7 +155,8 @@ export type StarlightPageProps = Prettify<
|
|
|
63
155
|
// Remove the index signature from `Route`, omit undesired properties and make the rest optional.
|
|
64
156
|
Partial<Omit<RemoveIndexSignature<PageProps>, 'entry' | 'entryMeta' | 'id' | 'locale' | 'slug'>> &
|
|
65
157
|
// Add the sidebar definitions for a Starlight page.
|
|
66
|
-
Partial<Pick<StarlightRouteData, 'hasSidebar'
|
|
158
|
+
Partial<Pick<StarlightRouteData, 'hasSidebar'>> & {
|
|
159
|
+
sidebar?: StarlightPageSidebarUserConfig;
|
|
67
160
|
// And finally add the Starlight page frontmatter properties in a `frontmatter` property.
|
|
68
161
|
frontmatter: StarlightPageFrontmatter;
|
|
69
162
|
}
|
|
@@ -94,7 +187,9 @@ export async function generateStarlightPageRouteData({
|
|
|
94
187
|
const pageFrontmatter = await getStarlightPageFrontmatter(frontmatter);
|
|
95
188
|
const id = `${stripLeadingAndTrailingSlashes(slug)}.md`;
|
|
96
189
|
const localeData = slugToLocaleData(slug);
|
|
97
|
-
const sidebar = props.sidebar
|
|
190
|
+
const sidebar = props.sidebar
|
|
191
|
+
? normalizeSidebarProp(props.sidebar)
|
|
192
|
+
: getSidebar(url.pathname, localeData.locale);
|
|
98
193
|
const headings = props.headings ?? [];
|
|
99
194
|
const pageDocsEntry: StarlightPageDocsEntry = {
|
|
100
195
|
id,
|