fuc-new/doc/node_modules/@vuepress/plugin-seo/lib/node/getJSONLDInfo.js
hellcat 6adbc04d4b 1
2025-10-03 17:17:08 +08:00

29 lines
1.2 KiB
JavaScript

import { getDate } from '@vuepress/helper';
import { getCover, getImages, getSEOAuthor } from './utils/index.js';
export const getJSONLDInfo = (page, app, { isArticle, author: globalAuthor, fallBackImage, hostname, }) => {
const { title, frontmatter: { author: pageAuthor, description, time, date = time }, data: { git = {} }, } = page;
const author = getSEOAuthor(pageAuthor || globalAuthor);
const datePublished = getDate(date)?.toISOString();
const dateModified = git.updatedTime
? new Date(git.updatedTime).toISOString()
: null;
const cover = getCover(page, app, hostname);
const images = getImages(page, app, hostname);
return isArticle(page)
? {
'@context': 'https://schema.org',
'@type': 'Article',
'headline': title,
'image': images.length ? images : [cover || fallBackImage],
datePublished,
dateModified,
'author': author.map((item) => ({ '@type': 'Person', ...item })),
}
: {
'@context': 'https://schema.org',
'@type': 'WebPage',
'name': title,
...(description ? { description } : {}),
};
};