Skip to content

Commit 6f2ea87

Browse files
authored
Update netlify.mdx from withastro#11497
1 parent 6a6b6d0 commit 6f2ea87

File tree

1 file changed

+16
-21
lines changed
  • src/content/docs/zh-cn/guides/integrations-guide

1 file changed

+16
-21
lines changed

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

+16-21
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
```
@@ -100,13 +101,12 @@ netlify deploy
100101

101102
要在预渲染页面上实现重定向、访问控制或自定义响应头,请通过启用 [`edgeMiddleware` 选项](/zh-cn/reference/adapter-reference/#edgemiddleware) 在 Netlify Edge Functions 上运行你的中间件:
102103

103-
```js title="astro.config.mjs" ins={8}
104+
```js title="astro.config.mjs" ins={7}
104105
import { defineConfig } from 'astro/config';
105106
import netlify from '@astrojs/netlify';
106107

107108
export default defineConfig({
108109
// ...
109-
output: 'server',
110110
adapter: netlify({
111111
edgeMiddleware: true,
112112
}),
@@ -153,27 +153,25 @@ declare namespace App {
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'],
@@ -219,17 +217,17 @@ Astro [Session API](/zh-cn/guides/sessions/) 允许你在请求间,轻松地
219217

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

222-
```ts title="astro.config.mjs"
220+
```ts title="astro.config.mjs" ins={4}
223221
export default defineConfig({
224222
// ...
225-
output: 'server',
226223
adapter: netlify({
227224
cacheOnDemandPages: true,
228225
}),
229226
});
230227
```
231228

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

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

266-
```js title="astro.config.mjs" ins={8}
264+
```js title="astro.config.mjs" ins={7}
267265
import { defineConfig } from 'astro/config';
268266
import netlify from '@astrojs/netlify';
269267

270268
export default defineConfig({
271269
// ...
272-
output: 'server',
273270
adapter: netlify({
274271
includeFiles: ['./my-data.json'], // 相对于 `root`
275272
}),
@@ -291,13 +288,12 @@ export default defineConfig({
291288

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

294-
```js title="astro.config.mjs" ins={8}
291+
```js title="astro.config.mjs" ins={7}
295292
import { defineConfig } from 'astro/config';
296293
import netlify from '@astrojs/netlify';
297294

298295
export default defineConfig({
299296
// ...
300-
output: 'server',
301297
adapter: netlify({
302298
excludeFiles: ['./src/some_big_file.jpg'], // 相对于 `root`
303299
}),
@@ -308,12 +304,11 @@ export default defineConfig({
308304

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

311-
```js title="astro.config.mjs" ins={8, 11-12}
307+
```js title="astro.config.mjs" ins={7, 10-11}
312308
import { defineConfig } from 'astro/config';
313309
import netlify from '@astrojs/netlify';
314310

315311
export default defineConfig({
316-
output: 'server',
317312
adapter: netlify({
318313
includeFiles: [
319314
'./data/**/*.json'

0 commit comments

Comments
 (0)