Skip to content

Commit 98c3e11

Browse files
liruifengvNin3leeyanthomasdev
authored
i18n(zh-cn): Update tutorial/* (#12461)
Co-authored-by: Nin3 <[email protected]> Co-authored-by: Yan <[email protected]>
1 parent cc33e66 commit 98c3e11

File tree

7 files changed

+97
-71
lines changed

7 files changed

+97
-71
lines changed

src/content/docs/zh-cn/tutorial/2-pages/4.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Astro 的 `<style>` 标签还可以使用 `define:vars={ {...} }` 指令引用 `
105105
const finished = false;
106106
const goal = 3;
107107
108-
const skillColor = "navy";
108+
const skillColor = "crimson";
109109
---
110110
```
111111

@@ -125,7 +125,7 @@ Astro 的 `<style>` 标签还可以使用 `define:vars={ {...} }` 指令引用 `
125125
</style>
126126
```
127127

128-
3. 在浏览器预览中查看“关于”页面。你应该看到技能现在是海军蓝色`navy`,由传递给 `define:vars` 指令的 `skillColor` 变量设置。
128+
3. 在浏览器预览中查看“关于”页面。你应该看到技能现在是深红色,由传递给 `define:vars` 指令的 `skillColor` 变量设置。
129129
</Steps>
130130

131131
<Box icon="puzzle-piece">
@@ -150,7 +150,7 @@ Astro 的 `<style>` 标签还可以使用 `define:vars={ {...} }` 指令引用 `
150150
```
151151

152152
2. 在你的 frontmatter 脚本中添加任何缺失的变量定义,以便你的新 `<style>` 标签成功地将这些样式应用到你的技能列表中:
153-
- 文字颜色为海军蓝
153+
- 文字颜色为深红色
154154
- 文本是粗体
155155
- 列表项全部大写(全部大写字母)
156156

@@ -175,7 +175,7 @@ const happy = true;
175175
const finished = false;
176176
const goal = 3;
177177
178-
const skillColor = "navy";
178+
const skillColor = "crimson";
179179
const fontWeight = "bold";
180180
const textCase = "uppercase";
181181
---

src/content/docs/zh-cn/tutorial/2-pages/5.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import { Steps } from '@astrojs/starlight/components';
7373
const finished = false;
7474
const goal = 3;
7575
76-
const skillColor = "navy";
76+
const skillColor = "crimson";
7777
const fontWeight = "bold";
7878
const textCase = "uppercase";
7979
---

src/content/docs/zh-cn/tutorial/3-components/3.mdx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ import Badge from "~/components/Badge.astro"
8888
## 添加响应式样式
8989

9090
<Steps>
91-
1.`Navigation.astro` 中使用 CSS 类来控制你的导航链接。将现有的导航链接包裹在一个带有类名 `nav-links``<div>` 元素中。
91+
1.`Navigation.astro` 中使用 CSS 类来控制你的导航链接。将现有的导航链接包裹在一个带有类名 `nav-links``<div>` 元素中,并且把 id 属性设置为 `main-menu`
9292

9393
```astro title="src/components/Navigation.astro" ins={3,7}
9494
---
9595
---
96-
<div class="nav-links">
96+
<div id="main-menu" class="nav-links">
9797
<a href="/">首页</a>
9898
<a href="/about/">关于</a>
9999
<a href="/blog/">博客</a>
@@ -110,7 +110,7 @@ import Badge from "~/components/Badge.astro"
110110
首先定义在较小屏幕尺寸上应该渲染的布局!较小的屏幕尺寸需要更简单的布局,然后,调整你的样式以适应较大的设备。如果你先设计复杂情况,那么接下来你反而要努力将其简化。
111111
:::
112112

113-
```css title="src/styles/global.css" ins={23-100}
113+
```css title="src/styles/global.css" ins={23-60}
114114
html {
115115
background-color: #f1f5f9;
116116
font-family: sans-serif;
@@ -137,9 +137,6 @@ import Badge from "~/components/Badge.astro"
137137

138138
.nav-links {
139139
width: 100%;
140-
top: 5rem;
141-
left: 48px;
142-
background-color: #ff9776;
143140
display: none;
144141
margin: 0;
145142
}
@@ -152,17 +149,14 @@ import Badge from "~/components/Badge.astro"
152149
font-size: 1.2rem;
153150
font-weight: bold;
154151
text-transform: uppercase;
152+
color: #0d0950;
155153
}
156154

157155
.nav-links a:hover,
158156
.nav-links a:focus {
159157
background-color: #ff9776;
160158
}
161159

162-
.expanded {
163-
display: unset;
164-
}
165-
166160
@media screen and (min-width: 636px) {
167161
.nav-links {
168162
margin-left: 5em;
@@ -176,7 +170,6 @@ import Badge from "~/components/Badge.astro"
176170
display: inline-block;
177171
padding: 15px 20px;
178172
}
179-
180173
}
181174
```
182175
</Steps>

src/content/docs/zh-cn/tutorial/3-components/4.mdx

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,74 +12,65 @@ import Option from '~/components/tutorial/Option.astro';
1212
import PreCheck from '~/components/tutorial/PreCheck.astro';
1313
import { Steps } from '@astrojs/starlight/components';
1414

15-
让我们在移动屏幕上添加一个汉堡菜单(Hamburger Menus)以打开和关闭你的导航链接,这需要一些客户端的交互!
15+
让我们在移动屏幕上添加一个按钮以打开和关闭你的导航菜单,这需要一些客户端的交互!
1616

1717
<PreCheck>
18-
- 创建一个汉堡菜单组件
18+
- 创建一个菜单组件
1919
- 编写一个 `<script>` 使你的网站访问者可以打开和关闭导航菜单
2020
- 将你的 JavaScript 移动到 `.js` 文件中
2121
</PreCheck>
2222

23-
## 搭建一个汉堡菜单组件
23+
## 搭建一个菜单组件
2424

25-
创建一个 `<Hamburger />` 组件,用于打开和关闭移动端菜单。
25+
创建一个 `<Menu />` 组件,用于打开和关闭移动端菜单。
2626

2727
<Steps>
28-
1.`src/components/` 中创建一个名为 `Hamburger.astro` 的文件。
28+
1.`src/components/` 中创建一个名为 `Menu.astro` 的文件。
2929

30-
2. 将以下代码复制到你的组件中。这将表示你的三行「汉堡」菜单,在移动设备上打开和关闭导航链接菜单。(稍后你将把新的 CSS 样式添加到 `global.css` 中。)
30+
2. 将以下代码复制到你的组件中。这将创建一个按钮,用于在移动端切换导航链接的可见性。(稍后你将把新的 CSS 样式添加到 `global.css` 中。)
3131

32-
```astro title="src/components/Hamburger.astro"
32+
```astro title="src/components/Menu.astro"
3333
---
3434
---
35-
<div class="hamburger">
36-
<span class="line"></span>
37-
<span class="line"></span>
38-
<span class="line"></span>
39-
</div>
35+
<button aria-expanded="false" aria-controls="main-menu" class="menu">
36+
Menu
37+
</button>
4038
```
4139

42-
3. 将这个新的 `<Hamburger />` 组件放置在 `Header.astro``<Navigation />` 组件之前。
40+
3. 将这个新的 `<Menu />` 组件放置在 `Header.astro``<Navigation />` 组件之前。
4341

4442
<details>
4543
<summary>给我看看代码!</summary>
4644

4745
```astro title="src/components/Header.astro" ins={2,7}
4846
---
49-
import Hamburger from './Hamburger.astro';
47+
import Menu from './Menu.astro';
5048
import Navigation from './Navigation.astro';
5149
---
5250
<header>
5351
<nav>
54-
<Hamburger />
52+
<Menu />
5553
<Navigation />
5654
</nav>
5755
</header>
5856
```
5957
</details>
6058

61-
4. 为你的 Hamburger 组件添加以下样式:
59+
4. 为你的 Menu 组件添加以下样式,包括一些响应式样式
6260

63-
```css title="src/styles/global.css" ins={2-13, 56-58}
61+
```css title="src/styles/global.css" ins={2-9, 33-35, 51-53}
6462
/* 导航样式 */
65-
.hamburger {
66-
padding-right: 20px;
67-
cursor: pointer;
68-
}
69-
70-
.hamburger .line {
71-
display: block;
72-
width: 40px;
73-
height: 5px;
74-
margin-bottom: 10px;
75-
background-color: #ff9776;
63+
.menu {
64+
background-color: #0d0950;
65+
border: none;
66+
color: #fff;
67+
font-size: 1.2rem;
68+
font-weight: bold;
69+
padding: 5px 10px;
7670
}
7771

7872
.nav-links {
7973
width: 100%;
80-
top: 5rem;
81-
left: 48px;
82-
background-color: #ff9776;
8374
display: none;
8475
margin: 0;
8576
}
@@ -92,13 +83,15 @@ import { Steps } from '@astrojs/starlight/components';
9283
font-size: 1.2rem;
9384
font-weight: bold;
9485
text-transform: uppercase;
86+
color: #0d0950;
9587
}
9688

97-
.nav-links a:hover, a:focus {
89+
.nav-links a:hover,
90+
.nav-links a:focus{
9891
background-color: #ff9776;
9992
}
100-
101-
.expanded {
93+
94+
:has(.menu[aria-expanded="true"]) .nav-links {
10295
display: unset;
10396
}
10497

@@ -116,7 +109,7 @@ import { Steps } from '@astrojs/starlight/components';
116109
padding: 15px 20px;
117110
}
118111

119-
.hamburger {
112+
.menu {
120113
display: none;
121114
}
122115
}
@@ -125,24 +118,27 @@ import { Steps } from '@astrojs/starlight/components';
125118

126119
## 编写你的第一个 script 标签
127120

128-
你的页眉还不具有**交互性**,因为它无法响应用户输入,比如点击汉堡菜单来显示或隐藏导航链接菜单
121+
你的页眉还不具有**交互性**,因为它无法响应用户输入,比如点击菜单来显示或隐藏导航链接菜单
129122

130123
添加一个 `<script>` 标签提供客户端 JavaScript,以「监听」用户事件并做出相应的响应。
131124

132125
<Steps>
133126
1. 将以下 `<script>` 标签添加到 `index.astro`,就在结束的 `</body>` 标签之前。
134127

135-
```astro title="src/pages/index.astro" ins={2-6}
128+
```astro title="src/pages/index.astro" ins={2-9}
136129
<Footer />
137130
<script>
138-
document.querySelector('.hamburger')?.addEventListener('click', () => {
139-
document.querySelector('.nav-links')?.classList.toggle('expanded');
131+
const menu = document.querySelector('.menu');
132+
133+
menu.addEventListener('click', () => {
134+
const isExpanded = menu.getAttribute('aria-expanded') === 'true';
135+
menu.setAttribute('aria-expanded', !isExpanded);
140136
});
141137
</script>
142138
</body>
143139
```
144140

145-
2. 再次在各种尺寸下检查你的浏览器预览,并验证你是否在这个页面上拥有一个能够根据屏幕尺寸响应并对用户输入作出响应的正常运作的汉堡菜单
141+
2. 再次在各种尺寸下检查你的浏览器预览,并验证你是否在这个页面上拥有一个能够根据屏幕尺寸响应并对用户输入作出响应的正常运作的导航菜单
146142
</Steps>
147143

148144
### 导入一个 `.js` 文件
@@ -153,26 +149,32 @@ import { Steps } from '@astrojs/starlight/components';
153149
1. 创建 `src/scripts/menu.js`(你将不得不创建一个新的 `/scripts/` 文件夹),并将你的 JavaScript 移动到其中。
154150

155151
```js title="src/scripts/menu.js"
156-
document.querySelector('.hamburger').addEventListener('click', () => {
157-
document.querySelector('.nav-links').classList.toggle('expanded');
152+
const menu = document.querySelector('.menu');
153+
154+
menu.addEventListener('click', () => {
155+
const isExpanded = menu.getAttribute('aria-expanded') === 'true';
156+
menu.setAttribute('aria-expanded', !isExpanded);
158157
});
159158
```
160159

161160
2. 用以下文件导入替换 `index.astro` 中的 `<script>` 标签的内容:
162161

163-
```astro title="src/pages/index.astro" ins={7} del={3-5}
162+
```astro title="src/pages/index.astro" ins={10} del={3-8}
164163
<Footer />
165164
<script>
166-
document.querySelector('.hamburger')?.addEventListener('click', () => {
167-
document.querySelector('.nav-links')?.classList.toggle('expanded');
165+
const menu = document.querySelector('.menu');
166+
167+
menu.addEventListener('click', () => {
168+
const isExpanded = menu.getAttribute('aria-expanded') === 'true';
169+
menu.setAttribute('aria-expanded', !isExpanded);
168170
});
169171
170172
import "../scripts/menu.js";
171173
</script>
172174
</body>
173175
```
174176

175-
3. 再次在较小的尺寸下检查你的浏览器预览,验证汉堡菜单是否仍然可以打开和关闭导航链接菜单
177+
3. 再次在较小的尺寸下检查你的浏览器预览,验证菜单是否仍然可以打开和关闭导航链接菜单
176178

177179
4. 在你的其他两个页面 `about.astro``blog.astro` 中添加相同的带有导入的 `<script>`,并验证每个页面上是否有一个响应式、交互式的页眉。
178180

src/content/docs/zh-cn/tutorial/3-components/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Option from '~/components/tutorial/Option.astro';
2424
- 显示页面链接菜单的导航组件
2525
- 包含在每个页面底部的页脚组件
2626
- 在页脚中使用的社交媒体组件,链接到个人资料页面
27-
- 一个可交互的汉堡包组件,用于在移动设备上切换导航
27+
- 一个可交互的菜单组件,用于在移动设备上切换导航
2828

2929

3030
在此过程中,你将使用 CSS 和 JavaScript 来实现自适应屏幕尺寸变化和用户输入的响应式设计。

src/content/docs/zh-cn/tutorial/6-islands/2.mdx

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import { Steps } from '@astrojs/starlight/components';
2929
```astro title="src/components/ThemeIcon.astro"
3030
---
3131
---
32-
<button id="themeToggle">
33-
<svg width="30px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
32+
<button id="themeToggle" aria-label="Toggle theme">
33+
<svg aria-hidden="true" width="30px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
3434
<path class="sun" fill-rule="evenodd" d="M12 17.5a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zm0 1.5a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm12-7a.8.8 0 0 1-.8.8h-2.4a.8.8 0 0 1 0-1.6h2.4a.8.8 0 0 1 .8.8zM4 12a.8.8 0 0 1-.8.8H.8a.8.8 0 0 1 0-1.6h2.5a.8.8 0 0 1 .8.8zm16.5-8.5a.8.8 0 0 1 0 1l-1.8 1.8a.8.8 0 0 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM6.3 17.7a.8.8 0 0 1 0 1l-1.7 1.8a.8.8 0 1 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM12 0a.8.8 0 0 1 .8.8v2.5a.8.8 0 0 1-1.6 0V.8A.8.8 0 0 1 12 0zm0 20a.8.8 0 0 1 .8.8v2.4a.8.8 0 0 1-1.6 0v-2.4a.8.8 0 0 1 .8-.8zM3.5 3.5a.8.8 0 0 1 1 0l1.8 1.8a.8.8 0 1 1-1 1L3.5 4.6a.8.8 0 0 1 0-1zm14.2 14.2a.8.8 0 0 1 1 0l1.8 1.7a.8.8 0 0 1-1 1l-1.8-1.7a.8.8 0 0 1 0-1z"/>
3535
<path class="moon" fill-rule="evenodd" d="M16.5 6A10.5 10.5 0 0 1 4.7 16.4 8.5 8.5 0 1 0 16.4 4.7l.1 1.3zm-1.7-2a9 9 0 0 1 .2 2 9 9 0 0 1-11 8.8 9.4 9.4 0 0 1-.8-.3c-.4 0-.8.3-.7.7a10 10 0 0 0 .3.8 10 10 0 0 0 9.2 6 10 10 0 0 0 4-19.2 9.7 9.7 0 0 0-.9-.3c-.3-.1-.7.3-.6.7a9 9 0 0 1 .3.8z"/>
3636
</svg>
@@ -49,21 +49,30 @@ import { Steps } from '@astrojs/starlight/components';
4949
</style>
5050
```
5151

52-
2. 将图标添加到 `Header.astro` ,以便它在所有页面上显示。不要忘记导入该组件
52+
2. `Header.astro` 中导入并添加 `<ThemeIcon />` 组件,以便它在所有页面上显示。`<ThemeIcon />``<Menu />` 都包裹在一个 `<div>` 内部以将它们组合在一起进行样式设置,并按照以下方式添加 `<style>` 标签以提供一些基本样式来改善布局
5353

54-
```astro title="src/components/Header.astro" ins={4,9}
54+
```astro title="src/components/Header.astro" ins={4,8-9,11,16-21}
5555
---
56-
import Hamburger from './Hamburger.astro';
56+
import Menu from './Menu.astro';
5757
import Navigation from './Navigation.astro';
5858
import ThemeIcon from './ThemeIcon.astro';
5959
---
6060
<header>
6161
<nav>
62-
<Hamburger />
63-
<ThemeIcon />
62+
<div>
63+
<ThemeIcon />
64+
<Menu />
65+
</div>
6466
<Navigation />
6567
</nav>
6668
</header>
69+
70+
<style>
71+
div {
72+
display: flex;
73+
justify-content: space-between;
74+
}
75+
</style>
6776
```
6877

6978
3. 访问 `http://localhost:4321` 上的浏览器预览,查看图标是否出现在所有页面上。你可以尝试点击它,但你还没有编写脚本使其具有交互性。
@@ -82,12 +91,34 @@ import { Steps } from '@astrojs/starlight/components';
8291
color: #fff;
8392
}
8493

94+
.dark .menu {
95+
background-color: #fff;
96+
color: #000;
97+
}
98+
99+
.dark .nav-links a:hover,
100+
.dark .nav-links a:focus {
101+
color: #0d0950;
102+
}
103+
85104
.dark .nav-links a {
86105
color: #fff;
87106
}
107+
108+
.dark a {
109+
color: #ff9776;
110+
}
88111
```
89112
</Steps>
90113

114+
:::tip[检查颜色的可访问性]
115+
当你更新网站以包含深色模式时,使用的某些颜色可能需要更新。
116+
117+
添加新样式和颜色时,请务必检查渲染的网站,并在必要时进行调整!这可能意味着添加更多 `.dark` CSS 样式规则以在深色模式下显示不同的样式,或者你可能希望更新一些颜色,以便它们在两个主题中同样有效。
118+
119+
在为你的网站创建一组颜色时,请考虑使用可访问性工具,例如对比度检查器。或者,你可以使用浏览器扩展程序对你的网站进行检查,以发现任何潜在问题。
120+
:::
121+
91122
## 添加客户端交互性
92123

93124
要为 Astro 组件添加交互性,你可以使用 `<script>` 标签。该脚本可以从 `localStorage` 中检查和设置当前主题,并在单击图标时切换主题。

0 commit comments

Comments
 (0)