Skip to content

Commit

Permalink
i18n(zh-cn): Update zh from upstream (#4393)
Browse files Browse the repository at this point in the history
  • Loading branch information
liruifengv committed Aug 29, 2023
1 parent a0bc8c5 commit 96eb594
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions src/content/docs/zh-cn/guides/images.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Astro 为你提供了多种在网站上使用图像的方法,无论它们是

你在 `src/` 中存储的本地图像可以被项目中的所有文件使用:`.astro``.md``.mdx``.mdoc` 和其他 UI 框架。图像可以存储在任何文件夹中,包括与你的内容一起。

只有当你想要避免任何处理时,才将图像存储在 `public/` 文件夹中。
如果你想要避免对图像做任何处理或者想要直接公开链接到图像,请将图像存储在 `public/` 文件夹中。

### 远程图像

Expand All @@ -35,10 +35,10 @@ Astro 可以使用 API 远程获取数据,也可以显示来自其完整 URL
```astro title="src/pages/blog/MyImages.astro"
---
import { Image } from 'astro:assets';
import localBirdImage from ''../../images/subfolder/localBirdImage.png';
import localBirdImage from '../../images/subfolder/localBirdImage.png';
---
<Image src={localBirdImage} alt="一只鸟坐在蛋窝上。"/>
<Image src="/bird-public-folder.jpg" alt="A bird." width="50" height="50"/>
<Image src="/images/bird-in-public-folder.jpg" alt="A bird." width="50" height="50"/>
<Image src="https://example.com/remote-bird.jpg" alt="A bird." width="50" height="50"/>
<img src={localBirdImage.src} alt="一只鸟坐在蛋窝上。">
Expand Down Expand Up @@ -84,7 +84,7 @@ import myImage from "../assets/my_image.png"; // Image is 1600x900

目前,内置的 assets 功能不包括 `<Picture />` 组件。

相反,你可以 [使用 `getImage()` 生成图像或自定义组件](/zh-cn/guides/images/#使用-getimage-生成图像),这些组件使用 HTML 图像属性 `srcset``sizes``<picture>` 标签进行 [艺术指导或创建响应式图像](https://developer.mozilla.org/zh-CN/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images#art_direction)
相反,你可以 [使用 `getImage()` 生成图像或自定义组件](#使用-getimage-生成图像),这些组件使用 HTML 图像属性 `srcset``sizes``<picture>` 标签进行 [艺术指导或创建响应式图像](https://developer.mozilla.org/zh-CN/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images#art_direction)

#### 属性

Expand All @@ -99,7 +99,7 @@ import myImage from "../assets/my_image.png"; // Image is 1600x900
import { Image } from 'astro:assets';
import myImportedImage from `../assets/my-local-image.png`
---
<Image src={myImportedImage} alt="descriptive text" />
<Image src={myImportedImage} alt="descriptive text" />
```

- **`public/` 文件夹中的图像** - 使用图像相对于 `public` 文件夹的**文件路径**作为属性值:
Expand All @@ -112,7 +112,8 @@ import myImage from "../assets/my_image.png"; // Image is 1600x900
src="/images/my-public-image.png"
alt="descriptive text"
width="200"
height="150" />
height="150"
/>
```

- **远程图像** - 使用图像的**完整 URL**作为属性值:
Expand Down Expand Up @@ -170,7 +171,7 @@ import myImage from "../assets/my_image.png";
<Image src={myImage} alt="" class="my-class" />
```

```astro
```html
<!-- 输出 -->
<img
src="/_astro/my_image.hash.webp"
Expand Down Expand Up @@ -215,9 +216,9 @@ const {src, ...attrs} = Astro.props;

本地图像必须从现有的 `.astro` 文件的相对路径**导入**,或者配置并使用 [导入别名](/zh-cn/guides/aliases/)。然后,你可以访问图像的 `src` 和其他属性,以在 `<img>` 标签中使用。

例如,使用图像自己的 `height``width` 属性作为默认值,以避免布局位移累计 CLS 并改善核心 Web 性能指标。
例如,使用图像自己的 `height``width` 属性,以避免布局位移累计 CLS 并改善核心 Web 性能指标。

```astro "myDog.src"
```astro "myDog.width" "myDog.height"
---
// 导入本地图像
import myDog from `../../images/pets/local-dog.jpg`
Expand Down Expand Up @@ -297,7 +298,7 @@ export default defineConfig({

## Markdown 文件中的图像

`.md` 文件中使用标准的 Markdown `![alt](src)` 语法。这个语法可以与 Astro 的 Image Services API 一起使用,来优化你的本地图像和授权的远程图像。
`.md` 文件中使用标准的 Markdown `![alt](src)` 语法。这个语法可以与 Astro 的 [图像服务 API](/zh-cn/reference/image-service-reference/) 一起使用,来优化你的本地图像和授权的远程图像。

```md
<!-- src/pages/post-1.md -->
Expand Down Expand Up @@ -346,7 +347,6 @@ import rocket from '../assets/rocket.png';
<img src="/images/stars.png" alt="A starry night sky." />
![A starry night sky.](/images/stars.png)


// 其它服务上的远程图像
<Image src="https://example.com/images/remote-image.png" />
<img src="https://example.com/images/remote-image.png" />
Expand Down Expand Up @@ -420,8 +420,7 @@ const allBlogPosts = await getCollection("blog");
```jsx title="src/components/ReactImage.jsx"
import stars from "../assets/stars.png"

export default function ReactImgage () {

export default function ReactImage () {
return (
<img src={stars.src} alt="繁星点点的夜空。" />
)
Expand Down Expand Up @@ -481,8 +480,8 @@ const optimizedBackground = await getImage({src: myBackground, format: 'avif'})

```js
{
options: {...} // 传递的原始参数
src: "https//..." // 生成图像的路径
options: {...} // 传递的原始参数
src: "https//..." // 生成图像的路径
attributes: {...} // 渲染图像所需的附加 HTML 属性(宽度、高度、样式等)
}
```
Expand Down Expand Up @@ -539,7 +538,7 @@ import { defineConfig } from 'astro/config';

export default defineConfig({
experimental: {
assets: true
assets: true
}
});
```
Expand Down Expand Up @@ -568,20 +567,21 @@ import rocket from '../../assets/rocket.png';

如果你之前因为这些限制而避免使用 `astro:assets`,现在你可以在没有问题的情况下使用它们。你可以配置无操作图像服务来显式地选择这种行为:

```astro
// astro.config.mjs
export default {
image: {
service: {
entrypoint: 'astro/assets/services/noop'
}
}
}
```
```js title="astro.config.mjs" ins={4-8}
import { defineConfig } from 'astro/config';

export default defineConfig({
image: {
service: {
entrypoint: 'astro/assets/services/noop'
}
}
});
```

### 决定在哪里存储你的图像

请参阅 [图像指南](/zh-cn/guides/images/#在哪里存储图像) 来帮助你决定在哪里存储你的图像。你可能希望利用 `astro:assets` 带来的灵活性,来存储你的图像的新选项。例如,现在可以使用标准的 Markdown `![alt](src)` 语法,在 Markdown、MDX 和 Markdoc 中引用项目 `src/` 中的相对图像。
请参阅 [图像指南](#在哪里存储图像) 来帮助你决定在哪里存储你的图像。你可能希望利用 `astro:assets` 带来的灵活性,来存储你的图像的新选项。例如,现在可以使用标准的 Markdown `![alt](src)` 语法,在 Markdown、MDX 和 Markdoc 中引用项目 `src/` 中的相对图像。

### 更新现有的 `<img>` 标签

Expand Down Expand Up @@ -670,19 +670,17 @@ import rocket from '../images/rocket.svg';
/>
```

3. 移除任何现有的 `<Picture />` 组件
3. 移除任何现有的 `<Picture />` 组件

目前,内置的 assets 功能不包括 `<Picture />` 组件。

相反,你可以使用 HTML 图像属性 `srcset``sizes``<picture>` 标签进行艺术指导或创建响应式图像。

4. 卸载 Sharp

[Sharp](https://github.com/lovell/sharp) 现在是 `astro:assets` 的默认图像服务。你不再需要在你的项目中本地安装这个依赖。
4. 选择一个默认图像服务。

使用你的包管理器卸载 Sharp,或者从你的 `package.json` 文件中手动删除
[Sharp](https://github.com/lovell/sharp) 现在是 `astro:assets` 的默认图像服务。如果你想使用 Sharp,无需任何配置

如果你想使用 [Squoosh](https://github.com/GoogleChromeLabs/squoosh) 来转换你的图像,请使用以下配置更新你的配置
如果你想使用 [Squoosh](https://github.com/GoogleChromeLabs/squoosh) 来转换你的图像,请使用下面的 `image.service` 选项更新你的配置

```js title="astro.config.mjs" ins={4-6}
import { defineConfig, squooshImageService } from 'astro/config';
Expand Down

0 comments on commit 96eb594

Please sign in to comment.