@@ -46,7 +46,7 @@ import { data } from './example.data.js'
4646``` js
4747export default {
4848 async load () {
49- // fetch remote data
49+ // 获取远程数据
5050 return (await fetch (' ...' )).json ()
5151 }
5252}
@@ -67,9 +67,8 @@ import { parse } from 'csv-parse/sync'
6767export default {
6868 watch: [' ./data/*.csv' ],
6969 load (watchedFiles ) {
70- // watchedFiles will be an array of absolute paths of the matched files.
71- // generate an array of blog post metadata that can be used to render
72- // a list in the theme layout
70+ // watchFiles 是一个所匹配文件的绝对路径的数组。
71+ // 生成一个博客文章元数据数组,可用于在主题布局中呈现列表。
7372 return watchedFiles .map ((file ) => {
7473 return parse (fs .readFileSync (file, ' utf-8' ), {
7574 columns: true ,
@@ -99,14 +98,14 @@ export default createContentLoader('posts/*.md', /* options */)
9998
10099``` ts
101100interface ContentData {
102- // mapped URL for the page. e.g. /posts/hello.html (does not include base)
103- // manually iterate or use custom `transform` to normalize the paths
101+ // 页面的映射 URL,如 /posts/hello.html(不包括 base)
102+ // 手动迭代或使用自定义 `transform` 来标准化路径
104103 url: string
105- // frontmatter data of the page
104+ // 页面的 frontmatter 数据
106105 frontmatter: Record <string , any >
107106
108- // the following are only present if relevant options are enabled
109- // we will discuss them below
107+ // 只有启用了相关选项,才会出现以下内容
108+ // 我们将在下面讨论它们
110109 src: string | undefined
111110 html: string | undefined
112111 excerpt: string | undefined
@@ -140,18 +139,18 @@ import { data as posts } from './posts.data.js'
140139import { createContentLoader } from ' vitepress'
141140
142141export default createContentLoader (' posts/*.md' , {
143- includeSrc: true , // include raw markdown source ?
144- render: true , // include rendered full page HTML?
145- excerpt: true , // include excerpt ?
142+ includeSrc: true , // 包含原始 markdown 源 ?
143+ render: true , // 包含渲染的整页 HTML?
144+ excerpt: true , // 包含摘录 ?
146145 transform (rawData ) {
147- // map, sort, or filter the raw data as you wish.
148- // the final result is what will be shipped to the client.
146+ // 根据需要对原始数据进行 map、 sort 或 filter
147+ // 最终的结果是将发送给客户端的内容
149148 return rawData .sort ((a , b ) => {
150149 return + new Date (b .frontmatter .date ) - + new Date (a .frontmatter .date )
151150 }).map ((page ) => {
152- page .src // raw markdown source
153- page .html // rendered full page HTML
154- page .excerpt // rendered excerpt HTML (content above first `---`)
151+ page .src // 原始 markdown 源
152+ page .html // 渲染的整页 HTML
153+ page .excerpt // 渲染的摘录 HTML(第一个 `---` 上面的内容)
155154 return {/* ... */ }
156155 })
157156 }
@@ -167,7 +166,7 @@ export default createContentLoader('posts/*.md', {
167166export default {
168167 async buildEnd () {
169168 const posts = await createContentLoader (' posts/*.md' ).load ()
170- // generate files based on posts metadata, e.g. RSS feed
169+ // 根据 posts 元数据生成文件,如 RSS 订阅源
171170 }
172171}
173172```
@@ -177,24 +176,24 @@ export default {
177176``` ts
178177interface ContentOptions <T = ContentData []> {
179178 /**
180- * Include src?
179+ * 包含 src?
181180 * @default false
182181 */
183182 includeSrc? : boolean
184183
185184 /**
186- * Render src to HTML and include in data ?
185+ * 将 src 渲染为 HTML 并包含在数据中 ?
187186 * @default false
188187 */
189188 render? : boolean
190189
191190 /**
192- * If `boolean`, whether to parse and include excerpt ? (rendered as HTML)
191+ * 如果为 `boolean`,是否解析并包含摘录 ? (呈现为 HTML)
193192 *
194- * If `function`, control how the excerpt is extracted from the content.
193+ * 如果为 `function`,则控制如何从内容中提取摘录
195194 *
196- * If `string`, define a custom separator to be used for extracting the
197- * excerpt. Default separator is `---` if `excerpt` is `true`.
195+ * 如果为 `string`,则定义用于提取摘录的自定义分隔符
196+ * 如果 `excerpt` 为 `true`,则默认分隔符为 `---`
198197 *
199198 * @see https://github.com/jonschlinkert/gray-matter#optionsexcerpt
200199 * @see https://github.com/jonschlinkert/gray-matter#optionsexcerpt_separator
@@ -207,8 +206,7 @@ interface ContentOptions<T = ContentData[]> {
207206 | string
208207
209208 /**
210- * Transform the data. Note the data will be inlined as JSON in the client
211- * bundle if imported from components or markdown files.
209+ * 转换数据。请注意,如果从组件或 Markdown 文件导入,数据将以 JSON 形式内联到客户端包中
212210 */
213211 transform? : (data : ContentData []) => T | Promise <T >
214212}
@@ -222,14 +220,14 @@ interface ContentOptions<T = ContentData[]> {
222220import { defineLoader } from ' vitepress'
223221
224222export interface Data {
225- // data type
223+ // data 类型
226224}
227225
228226declare const data: Data
229227export { data }
230228
231229export default defineLoader ({
232- // type checked loader options
230+ // 类型检查加载器选项
233231 watch: [' ...' ],
234232 async load(): Promise <Data > {
235233 // ...
0 commit comments