Skip to content

Commit 79400ff

Browse files
authored
Merge branch 'main' into dx-755/schema-extensions
2 parents 3d02ebe + 7c0b8cb commit 79400ff

26 files changed

+218
-95
lines changed

.changeset/beige-shoes-whisper.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/starlight': minor
3+
---
4+
5+
Adds a configuration option to disable site indexing with Pagefind and the default search UI

.changeset/pink-mirrors-cough.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astrojs/starlight': minor
3+
---
4+
5+
Exposes localized UI strings in route data
6+
7+
Component overrides can now access a `labels` object in their props which includes all the localized UI strings for the current page.

docs/src/content/docs/reference/configuration.mdx

+10
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,16 @@ When `false`, the colors provided by the active syntax highlighting theme are us
411411
When using custom themes and setting this to `true`, you must provide at least one dark and one light theme to ensure proper color contrast.
412412
:::
413413

414+
### `pagefind`
415+
416+
**type:** `boolean`
417+
**default:** `true`
418+
419+
Define whether Starlight’s default site search provider [Pagefind](https://pagefind.app/) is enabled.
420+
421+
Set to `false` to disable indexing your site with Pagefind.
422+
This will also hide the default search UI if in use.
423+
414424
### `head`
415425

416426
**type:** [`HeadConfig[]`](#headconfig)

docs/src/content/docs/reference/overrides.md

+10
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ JavaScript `Date` object representing when this page was last updated if enabled
135135

136136
`URL` object for the address where this page can be edited if enabled.
137137

138+
#### `labels`
139+
140+
**Type:** `Record<string, string>`
141+
142+
An object containing UI strings localized for the current page. See the [“Translate Starlight’s UI”](/guides/i18n/#translate-starlights-ui) guide for a list of all the available keys.
143+
138144
---
139145

140146
## Components
@@ -228,6 +234,10 @@ The default implementation includes logic for rendering logos defined in Starlig
228234
Component used to render Starlight’s search UI.
229235
The default implementation includes the button in the header and the code for displaying a search modal when it is clicked and loading [Pagefind’s UI](https://pagefind.app/).
230236

237+
When [`pagefind`](/reference/configuration/#pagefind) is disabled, the default search component will not be rendered.
238+
However, if you override `Search`, your custom component will always be rendered even if the `pagefind` configuration option is `false`.
239+
This allows you to add UI for alternative search providers when disabling Pagefind.
240+
231241
#### `SocialIcons`
232242

233243
**Default component:** [`SocialIcons.astro`](https://github.com/withastro/starlight/blob/main/packages/starlight/components/SocialIcons.astro)

docs/src/content/docs/zh-cn/getting-started.mdx

+73-26
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,34 @@ description: 了解如何使用 Astro 的 Starlight 开始构建下一个文档
55

66
import { Tabs, TabItem } from '@astrojs/starlight/components';
77

8-
## 创建一个新项目
9-
108
Starlight 是一个基于 [Astro](https://astro.build) 框架构建的全功能文档主题。
9+
查看 [手动配置](/zh-cn/manual-setup/) 以将Starlight添加到现有的Astro项目中。
10+
这个指南将帮助你开始一个新项目。
11+
12+
## 快速入门
1113

12-
你可以使用以下命令创建一个新的 Astro + Starlight 项目:
14+
### 创建一个新项目
15+
16+
在你的终端中运行以下命令来创建一个新的Astro + Starlight项目:
1317

1418
<Tabs>
1519
<TabItem label="npm">
1620

1721
```sh
18-
# 使用 npm 创建一个新项目
1922
npm create astro@latest -- --template starlight
2023
```
2124

2225
</TabItem>
2326
<TabItem label="pnpm">
2427

2528
```sh
26-
# 使用 pnpm 创建一个新项目
2729
pnpm create astro --template starlight
2830
```
2931

3032
</TabItem>
3133
<TabItem label="Yarn">
3234

3335
```sh
34-
# 使用 yarn 创建一个新项目
3536
yarn create astro --template starlight
3637
```
3738

@@ -45,24 +46,69 @@ yarn create astro --template starlight
4546
[在 StackBlitz 上打开模板](https://stackblitz.com/github/withastro/starlight/tree/main/examples/basics)
4647
:::
4748

48-
## 使用 Starlight 创建内容
49+
### 启动开发服务器
4950

50-
Starlight 已经准备好让你添加新的内容,或者将你现有的文件带过来!
51+
在本地工作时,[Astro的开发服务器](https://docs.astro.build/zh-cn/reference/cli-reference/#astro-dev)允许你预览你的工作,并在你进行更改时自动刷新你的浏览器。
5152

52-
### 文件格式
53+
在你的项目目录中,运行以下命令来启动开发服务器:
5354

54-
Starlight 支持使用 Markdown 和 MDX 来编写内容。(你可以通过安装实验性的 [Astro Markdoc 集成](https://docs.astro.build/zh-cn/guides/integrations-guide/markdoc/) 来添加对 Markdoc 的支持。)
55+
<Tabs>
56+
<TabItem label="npm">
5557

56-
### 添加页面
58+
```sh
59+
npm run dev
60+
```
5761

58-
`src/content/docs/` 中创建 `.md``.mdx` 文件,就可以自动将新页面添加到你的站点中。添加子文件夹来组织你的文件,并创建多个路径段:
62+
</TabItem>
63+
<TabItem label="pnpm">
5964

65+
```sh
66+
pnpm dev
6067
```
61-
src/content/docs/hello-world.md => your-site.com/hello-world
62-
src/content/docs/guides/faq.md => your-site.com/guides/faq
68+
69+
</TabItem>
70+
<TabItem label="Yarn">
71+
72+
```sh
73+
yarn dev
6374
```
6475

65-
### 类型安全的 frontmatter
76+
</TabItem>
77+
</Tabs>
78+
79+
这将在你的终端上记录一个包含本地预览网址的消息。
80+
打开这个网址开始浏览你的网站。
81+
82+
### 添加内容
83+
84+
Starlight已经准备好让你添加新内容或导入你现有的文件!
85+
86+
#### 文件格式
87+
88+
Starlight支持在Markdown和MDX中编写内容,无需进行任何配置。
89+
你可以通过安装实验性的[Astro Markdoc](https://docs.astro.build/zh-cn/guides/integrations-guide/markdoc/)集成来添加对Markdoc的支持。
90+
91+
#### 添加页面
92+
93+
通过在 `src/content/docs/` 中创建 `.md``.mdx` 文件来为你的站点添加新页面。
94+
使用子文件夹来组织你的文件并创建多个路径段。
95+
96+
例如,以下文件结构将在 `example.com/hello-world``example.com/guides/faq` 生成页面:
97+
98+
import FileTree from '../../../components/file-tree.astro';
99+
100+
<FileTree>
101+
102+
- src/
103+
- content/
104+
- docs/
105+
- guides/
106+
- faq.md
107+
- hello-world.md
108+
109+
</FileTree>
110+
111+
#### 类型安全的 frontmatter
66112

67113
所有 Starlight 页面都共享一个可自定义的 [frontmatter 属性集](/zh-cn/reference/frontmatter/),用于控制页面的外观:
68114

@@ -75,16 +121,19 @@ description: This is a page in my Starlight-powered site
75121

76122
如果你忘记了任何重要的东西,Starlight 会提醒你。
77123

78-
## 部署你的 Starlight 网站
124+
### 下一步
79125

80-
一旦你创建并自定义了你的 Starlight 网站,你就可以将它部署到你选择的 web 服务器或托管平台上,包括 Netlify、Vercel、GitHub Pages 等等。
81-
82-
[在 Astro 文档中了解如何部署 Astro 网站。](https://docs.astro.build/zh-cn/guides/deploy/)
126+
- **配置:**[自定义 Starlight](/zh-cn/guides/customization/)中了解常见选项。
127+
- **导航:** 使用[侧边栏导航](/zh-cn/guides/sidebar/)指南设置你的侧边栏。
128+
- **组件:**[组件](/zh-cn/guides/components/)指南中发现内置的卡片、标签页等更多内容。
129+
- **部署:** 使用Astro文档中的[部署你的 Astro 站点](https://docs.astro.build/zh-cn/guides/deploy/)指南发布你的站点。
83130

84131
## 更新 Starlight
85132

86133
:::tip[提示]
87-
由于 Starlight 是 beta 软件,所以会经常更新和改进。请务必定期更新 Starlight!
134+
由于 Starlight 是 beta 软件,所以会经常更新和改进。
135+
136+
请务必定期更新 Starlight!
88137
:::
89138

90139
Starlight 是一个 Astro 集成,可以像任何 `@astrojs/*` 集成一样更新:
@@ -93,37 +142,35 @@ Starlight 是一个 Astro 集成,可以像任何 `@astrojs/*` 集成一样更
93142
<TabItem label="npm">
94143

95144
```sh
96-
# 使用 npm 升级 Starlight
97145
npm install @astrojs/starlight@latest
98146
```
99147

100148
</TabItem>
101149
<TabItem label="pnpm">
102150

103151
```sh
104-
# 使用 pnpm 升级 Starlight
105152
pnpm upgrade @astrojs/starlight --latest
106153
```
107154

108155
</TabItem>
109156
<TabItem label="Yarn">
110157

111158
```sh
112-
# 使用 yarn 升级 Starlight
113159
yarn upgrade @astrojs/starlight --latest
114160
```
115161

116162
</TabItem>
117163
</Tabs>
118164

119-
你可以在 [Starlight 更新日志](https://github.com/withastro/starlight/blob/main/packages/starlight/CHANGELOG.md) 中查看每个版本的变动列表
165+
查阅 [Starlight 更新日志](https://github.com/withastro/starlight/blob/main/packages/starlight/CHANGELOG.md)中每个版本的变更列表
120166

121167
## Starlight 故障排除
122168

123169
本站点的参考部分提供了 Starlight [项目配置](/zh-cn/reference/configuration/)[单个页面 frontmatter 配置](/zh-cn/reference/frontmatter/)信息。使用这些页面来确保你的 Starlight 网站已正确配置和运行。
124170

125-
请参阅侧边栏中不断增长的指南列表,以获取有关添加内容和自定义 Starlight 网站的帮助。
171+
请参阅侧边栏中的指南列表,以获取有关添加内容和自定义 Starlight 网站的帮助。
126172

127-
如果你在这些文档中找不到答案,请访问[完整的 Astro 文档](https://docs.astro.build) 以获取完整的 Astro 文档。你的问题可能是通过了解 Starlight 主题下 Astro 的工作原理来解决的。
173+
如果你在这些文档中找不到答案,请访问[完整的 Astro 文档](https://docs.astro.build/zh-cn/) 以获取完整的 Astro 文档。
174+
你的问题可能是通过了解 Starlight 主题下 Astro 的工作原理来解决的。
128175

129176
你也可以检查任何已知的 [GitHub 上的 Starlight issues](https://github.com/withastro/starlight/issues),并在 [Astro Discord](https://astro.build/chat/) 上从我们活跃的、友好的社区中获得帮助!在我们的 `#support` 论坛中发布带有 “starlight” 标签的问题,或者访问我们专门的 `#starlight` 频道来讨论当前的开发和更多内容!

packages/starlight/404.astro

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const fallbackEntry: StarlightDocsEntry = {
2626
head: [],
2727
hero: { tagline: t('404.text'), actions: [] },
2828
pagefind: false,
29-
sidebar: { hidden: false },
29+
sidebar: { hidden: false, attrs: {} },
3030
},
3131
render: async () => ({
3232
Content: EmptyContent,

packages/starlight/__tests__/basics/route-data.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,13 @@ test('uses explicit last updated date from frontmatter', () => {
8585
expect(data.lastUpdated).toBeInstanceOf(Date);
8686
expect(data.lastUpdated).toEqual(route.entry.data.lastUpdated);
8787
});
88+
89+
test('includes localized labels', () => {
90+
const route = routes[0]!;
91+
const data = generateRouteData({
92+
props: { ...route, headings: [{ depth: 1, slug: 'heading-1', text: 'Heading 1' }] },
93+
url: new URL('https://example.com'),
94+
});
95+
expect(data.labels).toBeDefined();
96+
expect(data.labels['skipLink.label']).toBe('Skip to content');
97+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { expect, test, vi } from 'vitest';
2+
import { generateRouteData } from '../../utils/route-data';
3+
import { routes } from '../../utils/routing';
4+
5+
vi.mock('astro:content', async () =>
6+
(await import('../test-utils')).mockedAstroContent({
7+
docs: [
8+
['fr/index.mdx', { title: 'Accueil' }],
9+
['pt-br/index.mdx', { title: 'Pagina inicial' }],
10+
],
11+
})
12+
);
13+
14+
test('includes localized labels (fr)', () => {
15+
const route = routes[0]!;
16+
const data = generateRouteData({
17+
props: { ...route, headings: [{ depth: 1, slug: 'heading-1', text: 'Heading 1' }] },
18+
url: new URL('https://example.com'),
19+
});
20+
expect(data.labels).toBeDefined();
21+
expect(data.labels['skipLink.label']).toBe('Aller au contenu');
22+
});
23+
24+
test('includes localized labels (pt-br)', () => {
25+
const route = routes[1]!;
26+
const data = generateRouteData({
27+
props: { ...route, headings: [{ depth: 1, slug: 'heading-1', text: 'Heading 1' }] },
28+
url: new URL('https://example.com'),
29+
});
30+
expect(data.labels).toBeDefined();
31+
expect(data.labels['skipLink.label']).toBe('Pular para o conteúdo');
32+
});

packages/starlight/__tests__/i18n/translations.test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ describe('useTranslations()', () => {
2222
expect(t('page.editLink')).toBe(translations.en?.['page.editLink']);
2323
});
2424

25-
test('returns a pick method for filtering by key', () => {
26-
const t = useTranslations('en');
27-
expect(t.pick('tableOfContents.')).toEqual({
28-
'tableOfContents.onThisPage': 'On this page',
29-
'tableOfContents.overview': 'Overview',
30-
});
31-
});
32-
3325
test('uses built-in translations for regional variants', () => {
3426
const t = useTranslations('pt-br');
3527
expect(t('page.nextLink')).toBe(translations.pt?.['page.nextLink']);

packages/starlight/components/EditLink.astro

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
---
22
import Icon from '../user-components/Icon.astro';
33
import type { Props } from '../props';
4-
import { useTranslations } from '../utils/translations';
54
6-
const t = useTranslations(Astro.props.locale);
7-
const { editUrl } = Astro.props;
5+
const { editUrl, labels } = Astro.props;
86
---
97

108
{
119
editUrl && (
1210
<a href={editUrl} class="sl-flex">
1311
<Icon name="pencil" size="1.2em" />
14-
{t('page.editLink')}
12+
{labels['page.editLink']}
1513
</a>
1614
)
1715
}

packages/starlight/components/FallbackContentNotice.astro

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
---
22
import Icon from '../user-components/Icon.astro';
33
import type { Props } from '../props';
4-
import { useTranslations } from '../utils/translations';
54
6-
const t = useTranslations(Astro.props.locale);
5+
const { labels } = Astro.props;
76
---
87

98
<p class="sl-flex">
109
<Icon name={'warning'} size="1.5em" color="var(--sl-color-orange-high)" /><span
11-
>{t('i18n.untranslatedContent')}</span
10+
>{labels['i18n.untranslatedContent']}</span
1211
>
1312
</p>
1413

packages/starlight/components/Header.astro

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
import config from 'virtual:starlight/user-config';
23
import type { Props } from '../props';
34
45
import {
@@ -8,14 +9,20 @@ import {
89
SocialIcons,
910
ThemeSelect,
1011
} from 'virtual:starlight/components';
12+
13+
/**
14+
* Render the `Search` component if Pagefind is enabled or the default search component has been overridden.
15+
*/
16+
const shouldRenderSearch =
17+
config.pagefind || config.components.Search !== '@astrojs/starlight/components/Search.astro';
1118
---
1219

1320
<div class="header sl-flex">
1421
<div class="sl-flex">
1522
<SiteTitle {...Astro.props} />
1623
</div>
1724
<div class="sl-flex">
18-
<Search {...Astro.props} />
25+
{shouldRenderSearch && <Search {...Astro.props} />}
1926
</div>
2027
<div class="sl-hidden md:sl-flex right-group">
2128
<div class="sl-flex social-icons">

0 commit comments

Comments
 (0)