Skip to content

Commit

Permalink
fix(plugin-seo): only generate description when page has content
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Feb 21, 2024
1 parent f1cd0f6 commit 63471d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions plugins/plugin-seo/src/node/generateDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ export const generateDescription = (
if (!page.frontmatter.description && autoDescription) {
const pageText = getPageText(app, page, { length: 180, singleLine: true })

page.frontmatter.description =
pageText.length > 180 ? `${pageText.slice(0, 177)}...` : pageText
page.data.autoDesc = true
if (pageText.length) {
page.frontmatter.description =
pageText.length > 180 ? `${pageText.slice(0, 177)}...` : pageText
page.data.autoDesc = true
}
}
}
4 changes: 3 additions & 1 deletion tools/helper/src/node/page/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,7 @@ export const getPageText = (
}
}

return singleLine ? result.replace(/\n/g, ' ').replace(/\s+/g, ' ') : result
return (
singleLine ? result.replace(/\n/g, ' ').replace(/\s+/g, ' ') : result
).trim()
}

0 comments on commit 63471d3

Please sign in to comment.