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

fix: remove markdown from content before slice #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,9 @@ module.exports = themeConfig => {
}
if (themeConfig.summary) {
pageCtx.summary =
removeMd(
strippedContent
.trim()
.replace(/^#+\s+(.*)/, '')
.slice(0, themeConfig.summaryLength)
) + ' ...'
removeMd(strippedContent.trim())
.replace(/^#+\s+(.*)/, '')
Comment on lines +140 to +141
Copy link
Member

@billyyyyy3320 billyyyyy3320 Oct 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, title will not be removed from summary.

Suggested change
removeMd(strippedContent.trim())
.replace(/^#+\s+(.*)/, '')
removeMd(strippedContent.trim() .replace(/^#+\s+(.*)/, ''))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the replace is made before removeMd, the content might end up with a broken markdown again. Can you explain why the replace regex is needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, It won't end up with a broken markdown. The replace regex is removing title (The first heading 1). We don't need title in summary.

For example, Given below Markdown source:

# Markdown Slot

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.

Without title
c

With title
b

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply, I didn't notice I haven't submit the pending comment

.slice(0, themeConfig.summaryLength) + ' ...'
pageCtx.frontmatter.description = pageCtx.summary
}
if (pageCtx.frontmatter.summary) {
Expand Down