Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 2ed2d27

Browse files
feat: support using content excerpt as summary (#83)
1 parent 4ae4231 commit 2ed2d27

8 files changed

+23
-19
lines changed

docs/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ location: Taipei
137137
---
138138
```
139139

140+
### Summary
141+
142+
By default, summary will be extracted from source markdowns. If you need to override it, we present the following two approaches:
143+
144+
1. [Writing the summary manually in frontmatter](./front-matter.md#summary)
145+
146+
2. [Setting up excerpt separator by writing a comment `<!-- more -->` right below what you want to extract as summary](https://vuepress.vuejs.org/theme/writing-a-theme.html#content-excerpt)
147+
140148
## Quick Start
141149

142150
To make it easier to get started, you can use [create-vuepress](https://github.com/vuepressjs/create-vuepress) which is indeed an npm package, but it doesn’t mean you need to install it manually first. Here's an example:

example/_posts/2018-11-7-frontmatter-in-vuepress.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ location: Hangzhou
1010

1111
Any markdown file that contains a YAML front matter block will be processed by [gray-matter](https://github.com/jonschlinkert/gray-matter). The front matter must be the first thing in the markdown file and must take the form of valid YAML set between triple-dashed lines. Here is a basic example:
1212

13+
<!-- more -->
14+
1315
```markdown
1416
---
1517
title: Blogging Like a Hacker

example/_posts/2019-2-26-markdown-slot.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ location: Hangzhou
1010

1111
VuePress implements a content distribution API for Markdown. With this feature, you can split your document into multiple fragments to facilitate flexible composition in the layout component.
1212

13+
<!-- more -->
14+
1315
## Why do I need Markdown Slot?
1416

1517
First, let's review the relationship between layout components and markdown files:

example/_posts/2019-5-6-writing-a-vuepress-theme-2.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,6 @@ Finally, don't forget that `this.$route` and `this.$router` are also available a
168168
`lastUpdated` is the UNIX timestamp of this file's last git commit, for more details, refer to [Last Updated](../theme/default-theme-config.md#last-updated).
169169
:::
170170

171-
## Content Excerpt
172-
173-
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.
174-
175171
## App Level Enhancements
176172

177173
Themes can enhance the Vue app that VuePress uses by exposing an `enhanceApp.js` file at the root of the theme. The file should `export default` a hook function which will receive an object containing some app-level values. You can use this hook to install additional Vue plugins, register global components, or add additional router hooks:

example/_posts/2019-5-6-writing-a-vuepress-theme-3.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,6 @@ Finally, don't forget that `this.$route` and `this.$router` are also available a
168168
`lastUpdated` is the UNIX timestamp of this file's last git commit, for more details, refer to [Last Updated](../theme/default-theme-config.md#last-updated).
169169
:::
170170

171-
## Content Excerpt
172-
173-
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.
174-
175171
## App Level Enhancements
176172

177173
Themes can enhance the Vue app that VuePress uses by exposing an `enhanceApp.js` file at the root of the theme. The file should `export default` a hook function which will receive an object containing some app-level values. You can use this hook to install additional Vue plugins, register global components, or add additional router hooks:

example/_posts/2019-5-6-writing-a-vuepress-theme-4.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,6 @@ Finally, don't forget that `this.$route` and `this.$router` are also available a
168168
`lastUpdated` is the UNIX timestamp of this file's last git commit, for more details, refer to [Last Updated](../theme/default-theme-config.md#last-updated).
169169
:::
170170

171-
## Content Excerpt
172-
173-
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.
174-
175171
## App Level Enhancements
176172

177173
Themes can enhance the Vue app that VuePress uses by exposing an `enhanceApp.js` file at the root of the theme. The file should `export default` a hook function which will receive an object containing some app-level values. You can use this hook to install additional Vue plugins, register global components, or add additional router hooks:

example/_posts/2019-5-6-writing-a-vuepress-theme.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ To write a theme, create a `.vuepress/theme` directory in your docs root, and th
2020

2121
From there it's the same as developing a normal Vue application. It is entirely up to you how to organize your theme.
2222

23+
<!-- more -->
24+
2325
## Content Outlet
2426

2527
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:
@@ -168,10 +170,6 @@ Finally, don't forget that `this.$route` and `this.$router` are also available a
168170
`lastUpdated` is the UNIX timestamp of this file's last git commit, for more details, refer to [Last Updated](../theme/default-theme-config.md#last-updated).
169171
:::
170172

171-
## Content Excerpt
172-
173-
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.
174-
175173
## App Level Enhancements
176174

177175
Themes can enhance the Vue app that VuePress uses by exposing an `enhanceApp.js` file at the root of the theme. The file should `export default` a hook function which will receive an object containing some app-level values. You can use this hook to install additional Vue plugins, register global components, or add additional router hooks:

global-components/BaseListLayout.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@
1414
<header class="ui-post-title" itemprop="name headline">
1515
<NavLink :link="page.path">{{ page.title }}</NavLink>
1616
</header>
17-
18-
<p class="ui-post-summary" itemprop="description">
17+
<!-- eslint-disable vue/no-v-html -->
18+
<p
19+
v-if="page.excerpt"
20+
class="ui-post-summary"
21+
itemprop="description"
22+
v-html="page.excerpt"
23+
/>
24+
<!-- eslint-enable vue/no-v-html -->
25+
<p v-else class="ui-post-summary" itemprop="description">
1926
{{ page.frontmatter.summary || page.summary }}
20-
<!-- <Content :page-key="page.key" slot-key="intro"/>-->
2127
</p>
2228

2329
<footer>

0 commit comments

Comments
 (0)