Skip to content

Commit

Permalink
docs: improve chinese translation (#3402)
Browse files Browse the repository at this point in the history
  • Loading branch information
zonemeen committed Jan 2, 2024
1 parent 862b4be commit 1407baf
Show file tree
Hide file tree
Showing 23 changed files with 202 additions and 211 deletions.
6 changes: 3 additions & 3 deletions docs/zh/guide/cms.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ outline: deep
```js
export default {
async paths() {
// use respective CMS client library if needed
// 如有需要,使用相应的 CMS 客户端库
const data = await (await fetch('https://my-cms-api', {
headers: {
// token if necessary
// 如有必要,可使用 token
}
})).json()
return data.map(entry => {
return {
params: { id: entry.id, /* title, authors, date etc. */ },
params: { id: entry.id, /* title, authors, date */ },
content: entry.content
}
})
Expand Down
28 changes: 14 additions & 14 deletions docs/zh/guide/custom-theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

```
.
├─ docs # project root
├─ docs # 项目根目录
│ ├─ .vitepress
│ │ ├─ theme
│ │ │ └─ index.js # theme entry
│ │ └─ config.js # config file
│ │ │ └─ index.js # 主题入口
│ │ └─ config.js # 配置文件
│ └─ index.md
└─ package.json
```
Expand All @@ -24,26 +24,26 @@ VitePress 自定义主题是一个对象,该对象具有如下接口:
```ts
interface Theme {
/**
* Root layout component for every page
* 每个页面的根布局组件
* @required
*/
Layout: Component
/**
* Enhance Vue app instance
* 增强 Vue 应用实例
* @optional
*/
enhanceApp?: (ctx: EnhanceAppContext) => Awaitable<void>
/**
* Extend another theme, calling its `enhanceApp` before ours
* 扩展另一个主题,在我们的主题之前调用它的 `enhanceApp`
* @optional
*/
extends?: Theme
}

interface EnhanceAppContext {
app: App // Vue app instance
router: Router // VitePress router instance
siteData: Ref<SiteData> // Site-level metadata
app: App // Vue 应用实例
router: Router // VitePress 路由实例
siteData: Ref<SiteData> // 站点级元数据
}
```

Expand All @@ -52,8 +52,8 @@ interface EnhanceAppContext {
```js
// .vitepress/theme/index.js

// You can directly import Vue files in the theme entry
// VitePress is pre-configured with @vitejs/plugin-vue.
// 可以直接在主题入口导入 Vue 文件
// VitePress 已预先配置 @vitejs/plugin-vue
import Layout from './Layout.vue'

export default {
Expand All @@ -77,7 +77,7 @@ export default {
<template>
<h1>Custom Layout!</h1>
<!-- this is where markdown content will be rendered -->
<!-- 此处将渲染 markdown 内容 -->
<Content />
</template>
```
Expand Down Expand Up @@ -200,7 +200,7 @@ export default {
import baseConfig from 'awesome-vitepress-theme/config'

export default {
// extend theme base config (if needed)
// 扩展主题的基本配置(如需要)
extends: baseConfig
}
```
Expand All @@ -216,7 +216,7 @@ import type { ThemeConfig } from 'awesome-vitepress-theme'
export default defineConfigWithTheme<ThemeConfig>({
extends: baseConfig,
themeConfig: {
// Type is `ThemeConfig`
// 类型为 `ThemeConfig`
}
})
```
54 changes: 26 additions & 28 deletions docs/zh/guide/data-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { data } from './example.data.js'
```js
export default {
async load() {
// fetch remote data
// 获取远程数据
return (await fetch('...')).json()
}
}
Expand All @@ -67,9 +67,8 @@ import { parse } from 'csv-parse/sync'
export default {
watch: ['./data/*.csv'],
load(watchedFiles) {
// watchedFiles will be an array of absolute paths of the matched files.
// generate an array of blog post metadata that can be used to render
// a list in the theme layout
// watchFiles 是一个所匹配文件的绝对路径的数组。
// 生成一个博客文章元数据数组,可用于在主题布局中呈现列表。
return watchedFiles.map((file) => {
return parse(fs.readFileSync(file, 'utf-8'), {
columns: true,
Expand Down Expand Up @@ -99,14 +98,14 @@ export default createContentLoader('posts/*.md', /* options */)

```ts
interface ContentData {
// mapped URL for the page. e.g. /posts/hello.html (does not include base)
// manually iterate or use custom `transform` to normalize the paths
// 页面的映射 URL,如 /posts/hello.html(不包括 base
// 手动迭代或使用自定义 `transform` 来标准化路径
url: string
// frontmatter data of the page
// 页面的 frontmatter 数据
frontmatter: Record<string, any>

// the following are only present if relevant options are enabled
// we will discuss them below
// 只有启用了相关选项,才会出现以下内容
// 我们将在下面讨论它们
src: string | undefined
html: string | undefined
excerpt: string | undefined
Expand Down Expand Up @@ -140,18 +139,18 @@ import { data as posts } from './posts.data.js'
import { createContentLoader } from 'vitepress'

export default createContentLoader('posts/*.md', {
includeSrc: true, // include raw markdown source?
render: true, // include rendered full page HTML?
excerpt: true, // include excerpt?
includeSrc: true, // 包含原始 markdown ?
render: true, // 包含渲染的整页 HTML?
excerpt: true, // 包含摘录?
transform(rawData) {
// map, sort, or filter the raw data as you wish.
// the final result is what will be shipped to the client.
// 根据需要对原始数据进行 map、sort filter
// 最终的结果是将发送给客户端的内容
return rawData.sort((a, b) => {
return +new Date(b.frontmatter.date) - +new Date(a.frontmatter.date)
}).map((page) => {
page.src // raw markdown source
page.html // rendered full page HTML
page.excerpt // rendered excerpt HTML (content above first `---`)
page.src // 原始 markdown
page.html // 渲染的整页 HTML
page.excerpt // 渲染的摘录 HTML(第一个 `---` 上面的内容)
return {/* ... */}
})
}
Expand All @@ -167,7 +166,7 @@ export default createContentLoader('posts/*.md', {
export default {
async buildEnd() {
const posts = await createContentLoader('posts/*.md').load()
// generate files based on posts metadata, e.g. RSS feed
// 根据 posts 元数据生成文件,如 RSS 订阅源
}
}
```
Expand All @@ -177,24 +176,24 @@ export default {
```ts
interface ContentOptions<T = ContentData[]> {
/**
* Include src?
* 包含 src?
* @default false
*/
includeSrc?: boolean

/**
* Render src to HTML and include in data?
* src 渲染为 HTML 并包含在数据中?
* @default false
*/
render?: boolean

/**
* If `boolean`, whether to parse and include excerpt? (rendered as HTML)
* 如果为 `boolean`,是否解析并包含摘录? (呈现为 HTML)
*
* If `function`, control how the excerpt is extracted from the content.
* 如果为 `function`,则控制如何从内容中提取摘录
*
* If `string`, define a custom separator to be used for extracting the
* excerpt. Default separator is `---` if `excerpt` is `true`.
* 如果为 `string`,则定义用于提取摘录的自定义分隔符
* 如果 `excerpt` 为 `true`,则默认分隔符为 `---`
*
* @see https://github.com/jonschlinkert/gray-matter#optionsexcerpt
* @see https://github.com/jonschlinkert/gray-matter#optionsexcerpt_separator
Expand All @@ -207,8 +206,7 @@ interface ContentOptions<T = ContentData[]> {
| string

/**
* Transform the data. Note the data will be inlined as JSON in the client
* bundle if imported from components or markdown files.
* 转换数据。请注意,如果从组件或 Markdown 文件导入,数据将以 JSON 形式内联到客户端包中
*/
transform?: (data: ContentData[]) => T | Promise<T>
}
Expand All @@ -222,14 +220,14 @@ interface ContentOptions<T = ContentData[]> {
import { defineLoader } from 'vitepress'

export interface Data {
// data type
// data 类型
}

declare const data: Data
export { data }

export default defineLoader({
// type checked loader options
// 类型检查加载器选项
watch: ['...'],
async load(): Promise<Data> {
// ...
Expand Down
32 changes: 16 additions & 16 deletions docs/zh/guide/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,61 +122,61 @@ Cache-Control: max-age=31536000,immutable
1. 在项目的 `.github/workflows` 目录中创建一个名为 `deploy.yml` 的文件,其中包含这样的内容:

```yaml
# Sample workflow for building and deploying a VitePress site to GitHub Pages
# 构建 VitePress 站点并将其部署到 GitHub Pages 的示例工作流程
#
name: Deploy VitePress site to Pages

on:
# Runs on pushes targeting the `main` branch. Change this to `master` if you're
# using the `master` branch as the default branch.
# 在针对 `main` 分支的推送上运行。如果您
# 使用 `master` 分支作为默认分支,请将其更改为 `master`
push:
branches: [main]

# Allows you to run this workflow manually from the Actions tab
# 允许您从 Actions 选项卡手动运行此工作流程
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
# 设置 GITHUB_TOKEN 的权限,以允许部署到 GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
# 只允许同时进行一次部署,跳过正在运行和最新队列之间的运行队列
# 但是,不要取消正在进行的运行,因为我们希望允许这些生产部署完成
concurrency:
group: pages
cancel-in-progress: false

jobs:
# Build job
# 构建工作
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # Not needed if lastUpdated is not enabled
# - uses: pnpm/action-setup@v2 # Uncomment this if you're using pnpm
# - uses: oven-sh/setup-bun@v1 # Uncomment this if you're using Bun
fetch-depth: 0 # 如果未启用 lastUpdated,则不需要
# - uses: pnpm/action-setup@v2 # 如果使用 pnpm,请取消注释
# - uses: oven-sh/setup-bun@v1 # 如果使用 Bun,请取消注释
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: npm # or pnpm / yarn
cache: npm # pnpm / yarn
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Install dependencies
run: npm ci # or pnpm install / yarn install / bun install
run: npm ci # pnpm install / yarn install / bun install
- name: Build with VitePress
run: |
npm run docs:build # or pnpm docs:build / yarn docs:build / bun run docs:build
npm run docs:build # pnpm docs:build / yarn docs:build / bun run docs:build
touch docs/.vitepress/dist/.nojekyll
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: docs/.vitepress/dist

# Deployment job
# 部署工作
deploy:
environment:
name: github-pages
Expand Down Expand Up @@ -211,7 +211,7 @@ Cache-Control: max-age=31536000,immutable
paths:
- node_modules/
script:
# - apk add git # Uncomment this if you're using small docker images like alpine and have lastUpdated enabled
# - apk add git # 如果你使用的是像 alpine 这样的小型 docker 镜像,并且启用了 lastUpdated,请取消注释
- npm install
- npm run docs:build
artifacts:
Expand Down
9 changes: 4 additions & 5 deletions docs/zh/guide/extending-default-theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default DefaultTheme
// .vitepress/config.js
export default {
transformHead({ assets }) {
// adjust the regex accordingly to match your font
// 相应地调整正则表达式以匹配字体
const myFontFile = assets.find(file => /font-name\.\w+\.woff2/)
if (myFontFile) {
return [
Expand Down Expand Up @@ -102,7 +102,7 @@ import DefaultTheme from 'vitepress/theme'
export default {
extends: DefaultTheme,
enhanceApp({ app }) {
// register your custom global components
// 注册自定义全局组件
app.component('MyGlobalComponent' /* ... */)
}
}
Expand All @@ -117,7 +117,7 @@ import DefaultTheme from 'vitepress/theme'
export default {
extends: DefaultTheme,
enhanceApp({ app }) {
// register your custom global components
// 注册自定义全局组件
app.component('MyGlobalComponent' /* ... */)
}
} satisfies Theme
Expand All @@ -136,8 +136,7 @@ import MyLayout from './MyLayout.vue'

export default {
extends: DefaultTheme,
// override the Layout with a wrapper component that
// injects the slots
// 使用注入插槽的包装组件覆盖 Layout
Layout: MyLayout
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/zh/guide/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ $ bunx vitepress init
```js
// .vitepress/config.js
export default {
// site-level options
// 站点级选项
title: 'VitePress',
description: 'Just playing around.',

themeConfig: {
// theme-level options
// 主题级选项
}
}
```
Expand Down
Loading

0 comments on commit 1407baf

Please sign in to comment.