提交 fa404dc6 编写于 作者: E Evan You

feat: support excerpt extraction with `<!-- more -->` (close #174)

上级 cd9b7888
......@@ -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 `<!-- more -->` 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 `<Content/>` 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:
......
......@@ -54,6 +54,10 @@ VuePress 使用单文件组件来构建自定义主题。想要开发一个自
最后,别忘了,作为 Vue Router API 的一部分,`this.$route``this.$router` 同样可以使用。
## 内容摘抄
如果一个 markdown 文件中有一个 `<!-- more -->` 注释,则该注释之前的内容会被抓取并暴露在 `$page.excerpt` 属性中。如果你在开发一个博客主题,你可以用这个属性来渲染一个带摘抄的文章列表。
## 获取渲染内容
当前的 `.md` 文件渲染的内容,可以作为一个独特的全局组件 `<Content/>` 来使用,你可能想要它显示在页面中的某个地方。一个最简单的主题,可以是一个唯一的 `Layout.vue` 组件,并包含以下内容:
......
......@@ -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
}))
......
......@@ -48,6 +48,7 @@ exports.parseFrontmatter = content => {
const toml = require('toml')
return matter(content, {
excerpt_separator: '<!-- more -->',
engines: {
toml: toml.parse.bind(toml),
excerpt: false
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册