Skip to content

Commit

Permalink
feat(markdown): don't create excerpt if there is no <!--more-->
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwertovsky committed Jan 9, 2023
1 parent 30c26e3 commit 93d2e17
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion src/runtime/markdown-parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ function useExcerpt (content: string, delimiter = /<!--\s*?more\s*?-->/i) {
if (idx !== -1) {
return content.slice(0, idx)
}
return content
return
}
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()
})
})
}

0 comments on commit 93d2e17

Please sign in to comment.