Skip to content

Commit

Permalink
refactor: remove page excerpt
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `excerpt` has been removed from page object and page data
  • Loading branch information
meteorlxy committed Dec 9, 2022
1 parent fe047fe commit a27bc24
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 130 deletions.
12 changes: 0 additions & 12 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -508,17 +508,6 @@ You should not configure it unless you understand what it is for.

- Type: `FrontmatterPluginOptions | false`

- Default:

```ts
const defaultOptions = {
grayMatterOptions: {
excerpt: true,
excerpt_separator: '<!-- more -->',
},
}
```

- Details:

Options for [@mdit-vue/plugin-frontmatter](https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-frontmatter).
Expand All @@ -528,7 +517,6 @@ const defaultOptions = {
- Also see:
- [Guide > Page > Frontmatter](../guide/page.md#frontmatter)
- [Node API > Page Properties > frontmatter](./node-api.md#frontmatter)
- [Node API > Page Properties > excerpt](./node-api.md#excerpt)

::: danger
You should not configure it unless you understand what it is for.
Expand Down
25 changes: 0 additions & 25 deletions docs/reference/node-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,30 +432,6 @@ Hello, world.
- Also see:
- [Frontmatter](./frontmatter.md)

### excerpt

- Type: `string`

- Details:

Excerpt of the page.

If a Markdown file contains a `<!-- more -->` comment, any content above the comment will be extracted and rendered as excerpt.

If you are building a custom theme for blogging, it would be helpful to generate a post list with excerpts.

- Example:

```md
Lines above `<!-- more -->` comment would be used as excerpt.

It's recommended to wrap the comment with empty lines to avoid rendering issue.

<!-- more -->

Lines below `<!-- more -->` comment would not be used as excerpt.
```

### headers

- Type: `PageHeader[]`
Expand Down Expand Up @@ -487,7 +463,6 @@ interface PageData {
title: string
lang: string
frontmatter: PageFrontmatter
excerpt: string
headers: PageHeader[]
}
```
Expand Down
12 changes: 0 additions & 12 deletions docs/zh/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,17 +507,6 @@ const defaultOptions = {

- 类型: `FrontmatterPluginOptions | false`

- 默认值:

```ts
const defaultOptions = {
grayMatterOptions: {
excerpt: true,
excerpt_separator: '<!-- more -->',
},
}
```

- 详情:

[@mdit-vue/plugin-frontmatter](https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-frontmatter) 插件的配置项。
Expand All @@ -527,7 +516,6 @@ const defaultOptions = {
- 参考:
- [指南 > 页面 > Frontmatter](../guide/page.md#frontmatter)
- [Node API > Page 属性 > frontmatter](./node-api.md#frontmatter)
- [Node API > Page 属性 > excerpt](./node-api.md#excerpt)

::: danger
除非你了解它的用途,否则你不应该设置该配置项。
Expand Down
25 changes: 0 additions & 25 deletions docs/zh/reference/node-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,30 +428,6 @@ export default {
- 参考:
- [Frontmatter](./frontmatter.md)

### excerpt

- 类型: `string`

- 详情:

该 Page 的摘要。

如果一个 Markdown 文件中包含一个 `<!-- more -->` 注释,那么该注释上方的内容都会被作为摘要提取并渲染。

如果你在创建一个用于博客的自定义主题,那么它可以帮助你创建一个包含摘要的文章列表。

- 示例:

```md
在 `<!-- more -->` 注释上方的内容会被当作摘要。

建议你在该注释前后添加空行,以避免渲染问题。

<!-- more -->

在 `<!-- more -->` 注释下方的内容不会被当作摘要。
```

### headers

- 类型: `PageHeader[]`
Expand Down Expand Up @@ -483,7 +459,6 @@ interface PageData {
title: string
lang: string
frontmatter: PageFrontmatter
excerpt: string
headers: PageHeader[]
}
```
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/composables/pageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const pageDataEmpty = readonly({
title: '',
lang: '',
frontmatter: {},
excerpt: '',
headers: [],
} as PageData) as PageData

Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/page/createPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const createPage = async (
const {
contentRendered,
deps,
excerpt,
frontmatter,
headers,
links,
Expand Down Expand Up @@ -107,7 +106,6 @@ export const createPage = async (
title,
lang,
frontmatter,
excerpt,
headers,
},

Expand All @@ -117,7 +115,6 @@ export const createPage = async (
title,
lang,
frontmatter,
excerpt,
headers,

// extra fields
Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/page/renderPageContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const renderPageContent = async ({
}): Promise<{
contentRendered: string
deps: string[]
excerpt: string
frontmatter: PageFrontmatter
headers: MarkdownHeader[]
links: MarkdownLink[]
Expand All @@ -42,7 +41,6 @@ export const renderPageContent = async ({

/* istanbul ignore next */
const {
excerpt = '',
frontmatter = {},
headers = [],
importedFiles = [],
Expand All @@ -61,7 +59,6 @@ export const renderPageContent = async ({
return {
contentRendered,
deps: importedFiles,
excerpt,
frontmatter,
headers,
links,
Expand Down
2 changes: 0 additions & 2 deletions packages/core/tests/page/createPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ describe('core > page > createPage', () => {
expect(page.data.lang).toBe('en-US')
expect(page.data.title).toBe('')
expect(page.data.frontmatter).toEqual({})
expect(page.data.excerpt).toBe('')
expect(page.data.headers).toEqual([])

// base fields
Expand All @@ -43,7 +42,6 @@ describe('core > page > createPage', () => {
expect(page.lang).toBe('en-US')
expect(page.title).toBe('')
expect(page.frontmatter).toEqual({})
expect(page.excerpt).toBe('')
expect(page.headers).toEqual([])

// extra fields
Expand Down
39 changes: 0 additions & 39 deletions packages/core/tests/page/renderPageContent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const msg = 'msg'
expect(resolved).toEqual({
contentRendered: '<p>foobar</p>\n',
deps: [],
excerpt: '',
frontmatter: {},
headers: [],
links: [],
Expand Down Expand Up @@ -152,42 +151,4 @@ title: title in markdown frontmatter
})
})
})

describe('page excerpt', () => {
it('should render page excerpt correctly', async () => {
const resolved = await renderPageContent({
app,
content: `\
---
foo: foo
bar: 1
baz: true
---
excerpt
<!-- more -->
foobar
`,
filePath: null,
filePathRelative: null,
options: {},
})

expect(resolved.excerpt).toEqual('<p>excerpt</p>\n')
})

it('should extract empty page excerpt', async () => {
const resolved = await renderPageContent({
app,
content: '',
filePath: null,
filePathRelative: null,
options: {},
})

expect(resolved.excerpt).toEqual('')
})
})
})
5 changes: 2 additions & 3 deletions packages/markdown/src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,12 @@ export const createMarkdown = ({
md.use<EmojiPluginOptions>(emojiPlugin, emoji)
}

// extract frontmatter and excerpt into env
// extract frontmatter into env
if (frontmatter !== false) {
md.use<FrontmatterPluginOptions>(frontmatterPlugin, {
...frontmatter,
grayMatterOptions: {
excerpt: true,
excerpt_separator: '<!-- more -->',
excerpt: false,
...frontmatter?.grayMatterOptions,
},
})
Expand Down
5 changes: 0 additions & 5 deletions packages/shared/src/types/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ export type PageBase<
*/
frontmatter: PageFrontmatter<ExtraPageFrontmatter>

/**
* Excerpt of the page
*/
excerpt: string

/**
* Headers of the page
*/
Expand Down

0 comments on commit a27bc24

Please sign in to comment.