Skip to content

Commit 908072d

Browse files
i18n(zh-cn): Update configuration-reference.mdx and related docs (#11522)
Co-authored-by: Yan <[email protected]>
1 parent 1861690 commit 908072d

File tree

6 files changed

+765
-181
lines changed

6 files changed

+765
-181
lines changed

src/content/docs/zh-cn/guides/integrations-guide/cloudflare.mdx

Lines changed: 198 additions & 75 deletions
Large diffs are not rendered by default.

src/content/docs/zh-cn/guides/integrations-guide/netlify.mdx

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
type: integration
33
title: '@astrojs/netlify'
4-
description: 了解如何使用 @astrojs/netlify SSR 适配器来部署 Astro 项目。
4+
description: 了解如何使用 @astrojs/netlify 适配器来部署 Astro 项目。
55
sidebar:
66
label: Netlify
77
githubIntegrationURL: 'https://github.com/withastro/astro/tree/main/packages/integrations/netlify/'
@@ -11,9 +11,9 @@ i18nReady: true
1111
import PackageManagerTabs from '~/components/tabs/PackageManagerTabs.astro'
1212
import Since from '~/components/Since.astro';
1313

14-
此适配器可以部署你的 [按需渲染路由](/zh-cn/guides/on-demand-rendering/) [Netlify](https://www.netlify.com/)
14+
此适配器允许 Astro 将你的 [按需渲染路由及其功能](/zh-cn/guides/on-demand-rendering/) 部署到 [Netlify](https://www.netlify.com/),包括 [服务器群岛](/zh-cn/guides/server-islands/)[actions](/zh-cn/guides/actions/) 以及 [sessions](/zh-cn/guides/sessions/)
1515

16-
如果你正在使用 Astro 作为静态站点生成器,则不需要适配器。
16+
如果你需要额外的、需要服务器参与的 Netlify 功能(例如 [Netlify 图片 CDN](#netlify-图片-cdn-支持)),那么你会需要用上此适配器,但如果你只是将 Astro 作为静态的站点构建器,则不需要适配器。
1717

1818
在我们的 [Netlify 部署指南](/zh-cn/guides/deploy/netlify/) 中学习如何部署你的 Astro 网站。
1919

@@ -25,7 +25,7 @@ import Since from '~/components/Since.astro';
2525

2626
Astro 包含了一个 `astro add` 命令,用于自动设置官方集成。如果你愿意,可以改为 [手动安装集成](#手动安装)
2727

28-
在 Astro 项目中使用以下 `asrto add` 命令添加 Netlify 适配器,以启用 SSR。这将安装 `@astrojs/netlify` 并一步到位地对你的 `astro.config.mjs` 文件进行相应的更改。
28+
在 Astro 项目中使用以下 `asrto add` 命令添加 Netlify 适配器,以启用按需渲染。这将安装 `@astrojs/netlify` 并一步到位地对你的 `astro.config.mjs` 文件进行相应的更改。
2929

3030
<PackageManagerTabs>
3131
<Fragment slot="npm">
@@ -45,6 +45,8 @@ Astro 包含了一个 `astro add` 命令,用于自动设置官方集成。如
4545
</Fragment>
4646
</PackageManagerTabs>
4747

48+
现在,你可以启用 [对每个页面的按需渲染](/zh-cn/guides/on-demand-rendering/#启用按需渲染),或者将你的构建输出配置设置为 `output: 'server'` 从而 [默认对所有页面都进行服务器端渲染](/zh-cn/guides/on-demand-rendering/#server-模式)
49+
4850
### 手动安装
4951

5052
首先,使用适合你的包管理器将 Netlify 适配器安装到你的项目依赖中:
@@ -67,15 +69,14 @@ Astro 包含了一个 `astro add` 命令,用于自动设置官方集成。如
6769
</Fragment>
6870
</PackageManagerTabs>
6971

70-
然后,将适配器和你所需的 [按需渲染模式](/zh-cn/guides/on-demand-rendering/) 添加到你的 `astro.config.*` 文件中:
72+
然后,将适配器添加到 `astro.config.*` 文件中:
7173

72-
```js title="astro.config.mjs" ins={2, 6-7}
74+
```js title="astro.config.mjs" ins={2, 6}
7375
import { defineConfig } from 'astro/config';
7476
import netlify from '@astrojs/netlify';
7577

7678
export default defineConfig({
7779
// ...
78-
output: 'server',
7980
adapter: netlify(),
8081
});
8182
```
@@ -94,6 +95,28 @@ netlify deploy
9495

9596
这篇 [Netlify 博客文章](https://www.netlify.com/blog/how-to-deploy-astro/)[Netlify 文档](https://docs.netlify.com/integrations/frameworks/astro/) 提供了更多关于如何使用这个集成部署到 Netlify 的信息。
9697

98+
### 在 Netlify Edge Functions 上运行 Astro 中间件
99+
100+
任何 Astro 中间件都会在构建时应用于预渲染页面,在运行时应用于按需渲染页面。
101+
102+
要在预渲染页面上实现重定向、访问控制或自定义响应头,请通过启用 [`edgeMiddleware` 选项](/zh-cn/reference/adapter-reference/#edgemiddleware) 在 Netlify Edge Functions 上运行你的中间件:
103+
104+
```js title="astro.config.mjs" ins={7}
105+
import { defineConfig } from 'astro/config';
106+
import netlify from '@astrojs/netlify';
107+
108+
export default defineConfig({
109+
// ...
110+
adapter: netlify({
111+
edgeMiddleware: true,
112+
}),
113+
});
114+
```
115+
116+
`edgeMiddleware` 启用时,边缘函数将为所有请求执行你的中间件代码,包括静态资源、预渲染页面和按需渲染页面。
117+
118+
对于按需渲染的页面,`context.locals` 对象会被 JSON 序列化并通过标头发送给无服务器函数,由该函数执行渲染。作为安全措施,除非请求来自生成的边缘函数,否则无服务器函数将拒绝服务,并返回 `403 Forbidden` 响应。
119+
97120
### 从你的站点访问 edge 上下文
98121

99122
Netlify Edge Functions 提供了一个 [context 对象](https://docs.netlify.com/edge-functions/api/#netlify-specific-context-object),其中包含有关请求的元数据,例如用户的 IP、地理位置数据和 cookie。
@@ -124,56 +147,31 @@ declare namespace App {
124147

125148
这不适用于预渲染的页面。
126149

127-
### 在 Netlify Edge Functions 上运行 Astro 中间件
128-
129-
任何 Astro 中间件都会在构建时应用于预渲染页面,在运行时应用于按需渲染页面。
130-
131-
要在预渲染页面上实现重定向、访问控制或自定义响应头,请通过启用 [`edgeMiddleware` 选项](/zh-cn/reference/adapter-reference/#edgemiddleware) 在 Netlify Edge Functions 上运行你的中间件:
132-
133-
```js title="astro.config.mjs" ins={8}
134-
import { defineConfig } from 'astro/config';
135-
import netlify from '@astrojs/netlify';
136-
137-
export default defineConfig({
138-
// ...
139-
output: 'server',
140-
adapter: netlify({
141-
edgeMiddleware: true,
142-
}),
143-
});
144-
```
145-
146-
`edgeMiddleware` 启用时,边缘函数将为所有请求执行你的中间件代码,包括静态资源、预渲染页面和按需渲染页面。
147-
148-
对于按需渲染的页面,`context.locals` 对象会被 JSON 序列化并通过标头发送给无服务器函数,由该函数执行渲染。作为安全措施,除非请求来自生成的边缘函数,否则无服务器函数将拒绝服务,并返回 `403 Forbidden` 响应。
149-
150150
### Netlify 图片 CDN 支持
151151

152152
这个适配器默认使用 [Netlify 图片 CDN](https://docs.netlify.com/image-cdn/overview/) 来实时转换图片,因而不会影响构建时间。它背后是使用 [Astro 图片服务](/zh-cn/reference/image-service-reference/) 实现的。
153153

154154
如果你想退出 Netlify 的图片 CDN 远程图片优化,可以使用 `imageCDN` 选项:
155155

156-
```js title="astro.config.mjs" ins={8}
156+
```js title="astro.config.mjs" ins={7}
157157
import { defineConfig } from 'astro/config';
158158
import netlify from '@astrojs/netlify';
159159

160160
export default defineConfig({
161161
// ...
162-
output: 'server',
163162
adapter: netlify({
164163
imageCDN: false,
165164
}),
166165
});
167166
```
168167
如果你使用的图片托管在另一个域名上,你必须使用 [`image.domains`](/zh-cn/reference/configuration-reference/#imagedomains)[`image.remotePatterns`](/zh-cn/reference/configuration-reference/#imageremotepatterns) 配置选项授权该域名或 URL 模式:
169168

170-
```js title="astro.config.mjs" ins={8-10}
169+
```js title="astro.config.mjs" ins={7-9}
171170
import { defineConfig } from 'astro/config';
172171
import netlify from '@astrojs/netlify';
173172

174173
export default defineConfig({
175174
// ...
176-
output: 'server',
177175
adapter: netlify(),
178176
image: {
179177
domains: ['example.com'],
@@ -209,21 +207,27 @@ export default defineConfig({
209207
你仍然可以包含一个 `public/_redirects` 文件来手动重定向。你在重定向配置中指定的任何重定向都会被追加到你自己的重定向的末尾。
210208
:::
211209

210+
### Sessions
211+
212+
Astro [Session API](/zh-cn/guides/sessions/) 允许你在请求间,轻松地存储用户数据。该功能可用于用户数据和偏好选项,购物车内容,资格鉴权。不同于 cookie 存储,这里不存在对数据大小的限制,并且可以将其存储在不同的设备上。
213+
214+
当使用 Netlify 适配器时,Astro 将自动配置 [Netlify Blobs](https://docs.netlify.com/blobs/overview/) 用于会话(session)存储。如果你更倾向于使用其他的会话存储驱动,你可以在 Astro config 中指定。更多细节请参见 [`session` 配置参考](/zh-cn/reference/configuration-reference/#sessiondriver)
215+
212216
### 缓存页面
213217

214218
可以缓存没有任何动态内容的按需渲染页面,以提高性能并降低资源使用率。在适配器中启用 `cacheOnDemandPages` 选项将会缓存所有服务器渲染的页面,最长可达一年:
215219

216-
```ts title="astro.config.mjs"
220+
```ts title="astro.config.mjs" ins={4}
217221
export default defineConfig({
218222
// ...
219-
output: 'server',
220223
adapter: netlify({
221224
cacheOnDemandPages: true,
222225
}),
223226
});
224227
```
225228

226229
这可以通过向你的响应添加缓存头来根据每个页面进行更改:
230+
227231
```astro title="pages/index.astro"
228232
---
229233
import Layout from '../components/Layout.astro';
@@ -257,13 +261,12 @@ Astro.response.headers.set('CDN-Cache-Control', 'public, max-age=45, must-revali
257261

258262
请提供一个数组,其中包含需附加的文件路径,路径需要是相对于项目 [`root`](/zh-cn/reference/configuration-reference/#root) 的相对路径。绝对路径可能会无法正常工作。
259263

260-
```js title="astro.config.mjs" ins={8}
264+
```js title="astro.config.mjs" ins={7}
261265
import { defineConfig } from 'astro/config';
262266
import netlify from '@astrojs/netlify';
263267

264268
export default defineConfig({
265269
// ...
266-
output: 'server',
267270
adapter: netlify({
268271
includeFiles: ['./my-data.json'], // 相对于 `root`
269272
}),
@@ -285,13 +288,12 @@ export default defineConfig({
285288

286289
请提供一个数组,其中包含需要排除的文件路径,路径需要是相对于项目 [`root`](/zh-cn/reference/configuration-reference/#root) 的相对路径。绝对路径可能会无法正常工作。
287290

288-
```js title="astro.config.mjs" ins={8}
291+
```js title="astro.config.mjs" ins={7}
289292
import { defineConfig } from 'astro/config';
290293
import netlify from '@astrojs/netlify';
291294

292295
export default defineConfig({
293296
// ...
294-
output: 'server',
295297
adapter: netlify({
296298
excludeFiles: ['./src/some_big_file.jpg'], // 相对于 `root`
297299
}),
@@ -302,12 +304,11 @@ export default defineConfig({
302304

303305
不论是 `includeFiles` 还是 `excludeFiles` 都支持使用 [glob 模式](/zh-cn/guides/imports/#glob-模式) 来匹配多项文件:
304306

305-
```js title="astro.config.mjs" ins={8, 11-12}
307+
```js title="astro.config.mjs" ins={7, 10-11}
306308
import { defineConfig } from 'astro/config';
307309
import netlify from '@astrojs/netlify';
308310

309311
export default defineConfig({
310-
output: 'server',
311312
adapter: netlify({
312313
includeFiles: [
313314
'./data/**/*.json'

src/content/docs/zh-cn/guides/integrations-guide/node.mdx

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
type: integration
33
title: '@astrojs/node'
4-
description: 了解如何使用 @astrojs/node 来部署你的 Astro 项目。
4+
description: 了解如何使用 @astrojs/node 适配器来部署你的 Astro 项目。
55
sidebar:
66
label: Node
77
githubIntegrationURL: 'https://github.com/withastro/astro/tree/main/packages/integrations/node/'
@@ -11,7 +11,7 @@ i18nReady: true
1111

1212
import PackageManagerTabs from '~/components/tabs/PackageManagerTabs.astro'
1313

14-
此适配器允许 Astro 将你的 [按需渲染路由](/zh-cn/guides/on-demand-rendering/)部署到 Node 目标。
14+
此适配器允许 Astro 将你的 [按需渲染路由及其功能](/zh-cn/guides/on-demand-rendering/) 部署到 Node 目标,包括 [服务器群岛](/zh-cn/guides/server-islands/)[actions](/zh-cn/guides/actions/) 以及 [sessions](/zh-cn/guides/sessions/)
1515

1616
如果你将 Astro 用作静态站点构建器,则不需要适配器。
1717

@@ -23,8 +23,7 @@ import PackageManagerTabs from '~/components/tabs/PackageManagerTabs.astro'
2323

2424
Astro 包含了一个 `astro add` 命令,用于自动设置官方集成。如果你愿意,可以改为[手动安装集成](#手动安装)
2525

26-
使用 `astro add` 命令将 Node 适配器添加到你的 Astro 项目中,以启用服务端渲染。
27-
这将一步安装 `@astrojs/node` 并对你的 `astro.config.*` 文件进行适当的修改。
26+
使用 `astro add` 命令将 Node 适配器添加到你的 Astro 项目中,以启用按需渲染。这将一步到位地安装 `@astrojs/node` 并对你的 `astro.config.*` 文件进行适当的修改。
2827

2928
<PackageManagerTabs>
3029
<Fragment slot="npm">
@@ -44,6 +43,8 @@ Astro 包含了一个 `astro add` 命令,用于自动设置官方集成。如
4443
</Fragment>
4544
</PackageManagerTabs>
4645

46+
现在,你可以启用 [对每个页面的按需渲染](/zh-cn/guides/on-demand-rendering/#启用按需渲染),或者将你的构建输出配置设置为 `output: 'server'` 从而 [默认对所有页面都进行服务器端渲染](/zh-cn/guides/on-demand-rendering/#server-模式)
47+
4748
### 手动安装
4849

4950
首先,使用适合你的包管理器将 Node 适配器添加到你的项目依赖中。
@@ -66,14 +67,13 @@ Astro 包含了一个 `astro add` 命令,用于自动设置官方集成。如
6667
</Fragment>
6768
</PackageManagerTabs>
6869

69-
然后,将适配器和你所需的[按需渲染模式](/zh-cn/guides/on-demand-rendering/)添加到你的 `astro.config.*` 文件中:
70+
然后,将适配器添加到 `astro.config.*` 文件中:
7071

71-
```js title="astro.config.mjs" ins={2,5-8}
72+
```js title="astro.config.mjs" ins={2,5-7}
7273
import { defineConfig } from 'astro/config';
7374
import node from '@astrojs/node';
7475

7576
export default defineConfig({
76-
output: 'server',
7777
adapter: node({
7878
mode: 'standalone',
7979
}),
@@ -84,25 +84,26 @@ export default defineConfig({
8484

8585
@astrojs/node 可以通过将选项传递给适配器函数来配置。以下选项可用:
8686

87-
### 模式
87+
### `mode`
88+
<p>
89+
**类型:** `'middleware' | 'standalone'` <br />
90+
</p>
8891

8992
控制适配器是构建为 `middleware` 模式还是 `standalone` 模式。
9093

9194
* `middleware` 模式允许将构建的输出用作另一个 Node.js 服务器的中间件,例如 Express.js 或 Fastify。
95+
* `standalone` 构建到服务器,随着入口模块的运行会自动启动。这使你可以更轻松地部署到主机,而无需任何额外的代码。
9296

93-
```js title="astro.config.mjs"
94-
import { defineConfig } from 'astro/config';
95-
import node from '@astrojs/node';
96-
97-
export default defineConfig({
98-
output: 'server',
99-
adapter: node({
100-
mode: 'middleware',
101-
}),
102-
});
103-
```
97+
```js title="astro.config.mjs" {6}
98+
import { defineConfig } from 'astro/config';
99+
import node from '@astrojs/node';
104100

105-
* `standalone` 构建到服务器,随着入口模块的运行会自动启动。这使你可以更轻松地部署到主机,而无需任何额外的代码。
101+
export default defineConfig({
102+
adapter: node({
103+
mode: 'middleware',
104+
}),
105+
});
106+
```
106107

107108
## 用法
108109

@@ -220,3 +221,9 @@ export $(cat .env.runtime) && astro build
220221
```
221222
Cache-Control: public, max-age=31536000, immutable
222223
```
224+
225+
### Sessions
226+
227+
Astro [Session API](/zh-cn/guides/sessions/) 允许你在请求间,轻松地存储用户数据。该功能可用于用户数据和偏好选项,购物车内容,资格鉴权。不同于 cookie 存储,这里不存在对数据大小的限制,并且可以将其存储在不同的设备上。
228+
229+
当使用 Netlify 适配器时,Astro 将自动配置 [Netlify Blobs](https://docs.netlify.com/blobs/overview/) 用于会话(session)存储。如果你更倾向于使用其他的会话存储驱动,你可以在 Astro config 中指定。更多细节请参见 [`session` 配置参考](/zh-cn/reference/configuration-reference/#sessiondriver)。

0 commit comments

Comments
 (0)