Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(markdown): don't create excerpt if there is no <!--more--> #1801

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/content/3.guide/1.writing/2.markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ Full amount of content beyond the more divider.

Description property will contain the excerpt content unless defined within the Front Matter props.

If there is no `<!--more-->` divider in the text then excerpt is undefined.

Example variables will be injected into the document:

```json
Expand Down
1 change: 0 additions & 1 deletion src/runtime/markdown-parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,4 @@ function useExcerpt (content: string, delimiter = /<!--\s*?more\s*?-->/i) {
if (idx !== -1) {
return content.slice(0, idx)
}
return content
}
17 changes: 17 additions & 0 deletions test/features/parser-markdown-excerpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,22 @@ export const testMarkdownParserExcerpt = () => {
}
`)
})

test('When no <!--more--> then excerpt is undefined', async () => {
const parsed = await $fetch('/api/parse', {
method: 'POST',
body: {
id: 'content:index.md',
content: [
'# Index',
'First paragraph',
'',
'Second paragraph'
].join('\n')
}
})

expect(parsed.excerpt).not.toBeDefined()
})
})
}