This commit is contained in:
Jerry
2025-06-25 16:27:06 +08:00

View File

@@ -1,34 +1,55 @@
if theme.structured_data && page.layout === 'post' if theme.structured_data
- if page.layout === 'post'
// use json-ld to add structured data -
// https://developers.google.com/search/docs/appearance/structured-data/article
const title = page.title const title = page.title
const url = page.permalink const url = page.permalink
const imageVal = page.cover_type === 'img' ? page.cover : theme.avatar.img const imageVal = page.cover_type === 'img' ? page.cover : theme.avatar.img
const image = imageVal ? full_url_for(imageVal) : '' const image = imageVal ? full_url_for(imageVal) : ''
const datePublished = page.date.toISOString() const datePublished = page.date.toISOString()
const dateModified = (page.updated || page.date).toISOString() const dateModified = (page.updated || page.date).toISOString()
const author = page.copyright_author || config.author const author = page.copyright_author || config.author
const authorHrefVal = page.copyright_author_href || theme.post_copyright.author_href || site.url const authorHrefVal = page.copyright_author_href || theme.post_copyright.author_href || config.url
const authorHref = full_url_for(authorHrefVal) const authorHref = full_url_for(authorHrefVal)
const jsonLd = { const jsonLd = {
"@context": "https://schema.org", "@context": "https://schema.org",
"@type": "BlogPosting", "@type": "BlogPosting",
"headline": title, "headline": title,
"url": url, "url": url,
"image": image, "image": image,
"datePublished": datePublished, "datePublished": datePublished,
"dateModified": dateModified, "dateModified": dateModified,
"author": [{ "author": [{
"@type": "Person", "@type": "Person",
"name": author, "name": author,
"url": authorHref "url": authorHref
}] }]
} }
jsonLdScript = JSON.stringify(jsonLd, null, 2) jsonLdScript = JSON.stringify(jsonLd, null, 2)
- -
else if is_home() && (!page.current || page.current === 1)
-
// https://developers.google.com/search/docs/appearance/site-names#website
const baseUrl = config.url;
const currentPath = url_for('/');
const isRootOrSubdomain = currentPath.split('/').filter(Boolean).length === 0;
if (isRootOrSubdomain) {
const jsonLd = {
"@context": "https://schema.org",
"@type": "WebSite",
"name": config.title,
"url": full_url_for('/'),
}
jsonLdScript = JSON.stringify(jsonLd, null, 2)
}
-
script(type="application/ld+json"). script(type="application/ld+json").
!{jsonLdScript} !{jsonLdScript}