test02/node_modules/@vuepress/plugin-seo/lib/node/generateDescription.js
罗佳鸿 6aa1ebe342
Some checks are pending
部署文档 / deploy-gh-pages (push) Waiting to run
first commit
2024-08-13 10:11:19 +08:00

19 lines
729 B
JavaScript

import { getPageExcerptContent, getText } from '@vuepress/helper';
export const generateDescription = (app, page, autoDescription = true) => {
// generate description
if (!page.frontmatter.description && autoDescription) {
const content = getPageExcerptContent(page.content)
? (page.data.excerpt ?? page.contentRendered)
: page.contentRendered;
const pageText = getText(content, app.options.base, {
length: 180,
singleLine: true,
});
if (pageText.length) {
page.frontmatter.description =
pageText.length > 180 ? `${pageText.slice(0, 177)}...` : pageText;
page.data.autoDesc = true;
}
}
};