Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n(zh-cn): Update basics/astro-pages.mdx and reference/api-reference.mdx #8610

Merged
merged 7 commits into from
Jun 21, 2024
Merged
19 changes: 19 additions & 0 deletions src/content/docs/zh-cn/basics/astro-pages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,25 @@ title: '我的 Markdown 页面'

在开发过程中,如果你有一个 `500.astro` 文件,运行时抛出的错误将被记录在终端中,而不是显示在错误覆盖层中。

### `error`

<p><Since v="4.11.0" /></p>

`src/pages/500.astro` 是一个特殊页面,它会在渲染过程中对抛出的任何错误都会自动传递一个 `error` 属性。这允许你向访客展示详细的错误信息(例如来自页面、中间件等)。

错误属性的数据类型可以是任何类型,这可能会影响你在代码中的定义或使用值的方式:

```astro title="src/pages/500.astro"
---
interface Props {
error: unknown
}
const { error } = Astro.props
---
<div>{error instanceof Error ? error.message : 'Unknown error'}</div>
```

为了避免在展示内容时从 `error` 属性中显示敏感信息,请首先考虑评估错误,并根据抛出的错误返回适当的内容。例如,应避免显示错误的堆栈,因为它包含有关服务器上代码结构的信息。

## 局部页面

Expand Down
36 changes: 33 additions & 3 deletions src/content/docs/zh-cn/reference/api-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Astro.response.headers.set('Set-Cookie', 'a=b; Path=/;');

通过设置过去的到期日期(Unix 时间为 0)使 cookie 失效。

一旦 Cookie 被 “删除”(过期),`Astro.cookies.has()` 将返回 `false`,`Astro.cookies.get()` 将返回一个 `value` 为 `undefined` 的 [`AstroCookie`](#astrocookie)。删除 Cookie 时可用的选项包括:`domain`、`path`、`httpOnly`、`sameSite` 和 `secure`。
一旦 Cookie 被“删除”(过期),`Astro.cookies.has()` 将返回 `false`,`Astro.cookies.get()` 将返回一个 `value` 为 `undefined` 的 [`AstroCookie`](#astrocookie)。删除 Cookie 时可用的选项包括:`domain`、`path`、`httpOnly`、`sameSite` 和 `secure`。

##### `headers`

Expand Down Expand Up @@ -305,7 +305,7 @@ cookie 的原始字符串值。

<p><Since v="4.1.0"/></p>

通过 `Astro.cookies.set()` 设置 cookie, 允许传入 `CookieSetOptions` 来自定义 cookie 如何被序列化。
通过 `Astro.cookies.set()` 设置 cookie,允许传入 `CookieSetOptions` 来自定义 cookie 如何被序列化。

##### `domain`

Expand Down Expand Up @@ -1690,7 +1690,37 @@ import { Code } from 'astro:components';
</p>
```

该组件在构建时为代码块提供语法高亮(不包括客户端 JavaScript)。该组件由 Shiki 驱动,它支持所有流行的[主题](https://shiki.style/themes)和[语言](https://shiki.style/languages)。另外,你可以通过给 `theme` 和 `lang` 传递自定义主题和语言分别添加它们。
该组件在构建时为代码块提供语法高亮(不包括客户端 JavaScript)。该组件由 Shiki 驱动,它支持所有流行的[主题](https://shiki.style/themes)和[语言](https://shiki.style/languages)。另外,你可以通过给 `theme`、`lang` 和 `transformers` 传递自定义主题、语言和[转换器](#转换器)并分别添加它们。

#### 转换器


<p><Since v="4.11.0" /></p>

[Shiki 转换器](https://shiki.tmrs.site/packages/transformers#shikijs-transformers) 可以通过将其作为数组传递到 `transformers` 属性中,来选择性地应用于代码。

注意,`transformers` 只能用于类,同时你必须提供自己的 CSS 规则来针对代码块的元素。

```astro
---
import { transformerNotationFocus } from '@shikijs/transformers'
import { Code } from 'astro:components'
const code = `const foo = 'hello'
const bar = ' world'
console.log(foo + bar) // [!code focus]
`
---
<Code
code={code}
lang="js"
transformers={[transformerNotationFocus()]} />

<style is:global>
pre.has-focused .line:not(.focused) {
filter: blur(1px);
}
</style>
```

### `<Fragment />`

Expand Down
Loading