Skip to content

Commit

Permalink
feat(markdown): don't create excerpt if there is no <!--more--> (#1801
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Qwertovsky committed Jan 13, 2023
1 parent 0aa922c commit 2ba0776
Show file tree
Hide file tree
Showing 3 changed files with 19 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
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()
})
})
}

0 comments on commit 2ba0776

Please sign in to comment.