diff --git a/docs/guide/custom-themes.md b/docs/guide/custom-themes.md index 75aeaefc8d596b63740779925f11ea19994df220..e1b38a29733870808b691ff436b58f6c943f0df1 100644 --- a/docs/guide/custom-themes.md +++ b/docs/guide/custom-themes.md @@ -54,6 +54,10 @@ If the user provided `themeConfig` in `.vuepress/config.js`, it will also be ava Finally, don't forget that `this.$route` and `this.$router` are also available as part of Vue Router's API. +## Content Excerpt + +If a markdown file contains a `` comment, any content above the comment will be extracted and exposed as `$page.excerpt`. If you are building custom theme for blogging, this data can be used to render a post list with excerpts. + ## Content Outlet The compiled content of the current `.md` file being rendered will be available as a special `` global component. You will need to render it somewhere in your layout in order to display the content of the page. The simplest theme can be just a single `Layout.vue` component with the following content: diff --git a/docs/zh/guide/custom-themes.md b/docs/zh/guide/custom-themes.md index d74ea3942678eca0965f9068b396e83446f1c0f5..bb69e82ddb5d153fdacf4517d47d73badbfee0f6 100644 --- a/docs/zh/guide/custom-themes.md +++ b/docs/zh/guide/custom-themes.md @@ -54,6 +54,10 @@ VuePress 使用单文件组件来构建自定义主题。想要开发一个自 最后,别忘了,作为 Vue Router API 的一部分,`this.$route` 和 `this.$router` 同样可以使用。 +## 内容摘抄 + +如果一个 markdown 文件中有一个 `` 注释,则该注释之前的内容会被抓取并暴露在 `$page.excerpt` 属性中。如果你在开发一个博客主题,你可以用这个属性来渲染一个带摘抄的文章列表。 + ## 获取渲染内容 当前的 `.md` 文件渲染的内容,可以作为一个独特的全局组件 `` 来使用,你可能想要它显示在页面中的某个地方。一个最简单的主题,可以是一个唯一的 `Layout.vue` 组件,并包含以下内容: diff --git a/lib/prepare.js b/lib/prepare.js index c2c7a66d1d0e3217e94f6e66db967afdae31878d..00b7a63faf96367a6ca42772a7cc58e2d2f46fb8 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -187,10 +187,12 @@ async function resolveOptions (sourceDir) { if (headers.length) { data.headers = headers } - delete frontmatter.content if (Object.keys(frontmatter.data).length) { data.frontmatter = frontmatter.data } + if (frontmatter.excerpt) { + data.excerpt = frontmatter.excerpt + } return data })) diff --git a/lib/util/index.js b/lib/util/index.js index 5f6bf82ca53e053283e93100edac677b8dff29e5..01ef6ac77fb4f7ba38427843c2cff0be48d7dbf9 100644 --- a/lib/util/index.js +++ b/lib/util/index.js @@ -48,6 +48,7 @@ exports.parseFrontmatter = content => { const toml = require('toml') return matter(content, { + excerpt_separator: '', engines: { toml: toml.parse.bind(toml), excerpt: false