mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2025-09-15 12:58:48 +08:00
Merge pull request #1695 from DeepChirp/structured_data
feat(structured_data): 为网站首页添加结构化数据
This commit is contained in:
commit
7353de6c2e
@ -1,34 +1,55 @@
|
||||
if theme.structured_data && page.layout === 'post'
|
||||
-
|
||||
// use json-ld to add structured data
|
||||
if theme.structured_data
|
||||
if page.layout === 'post'
|
||||
-
|
||||
// https://developers.google.com/search/docs/appearance/structured-data/article
|
||||
|
||||
const title = page.title
|
||||
const url = page.permalink
|
||||
const imageVal = page.cover_type === 'img' ? page.cover : theme.avatar.img
|
||||
const image = imageVal ? full_url_for(imageVal) : ''
|
||||
const datePublished = page.date.toISOString()
|
||||
const dateModified = (page.updated || page.date).toISOString()
|
||||
const author = page.copyright_author || config.author
|
||||
const authorHrefVal = page.copyright_author_href || theme.post_copyright.author_href || site.url
|
||||
const authorHref = full_url_for(authorHrefVal)
|
||||
const title = page.title
|
||||
const url = page.permalink
|
||||
const imageVal = page.cover_type === 'img' ? page.cover : theme.avatar.img
|
||||
const image = imageVal ? full_url_for(imageVal) : ''
|
||||
const datePublished = page.date.toISOString()
|
||||
const dateModified = (page.updated || page.date).toISOString()
|
||||
const author = page.copyright_author || config.author
|
||||
const authorHrefVal = page.copyright_author_href || theme.post_copyright.author_href || config.url
|
||||
const authorHref = full_url_for(authorHrefVal)
|
||||
|
||||
const jsonLd = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "BlogPosting",
|
||||
"headline": title,
|
||||
"url": url,
|
||||
"image": image,
|
||||
"datePublished": datePublished,
|
||||
"dateModified": dateModified,
|
||||
"author": [{
|
||||
"@type": "Person",
|
||||
"name": author,
|
||||
"url": authorHref
|
||||
}]
|
||||
}
|
||||
const jsonLd = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "BlogPosting",
|
||||
"headline": title,
|
||||
"url": url,
|
||||
"image": image,
|
||||
"datePublished": datePublished,
|
||||
"dateModified": dateModified,
|
||||
"author": [{
|
||||
"@type": "Person",
|
||||
"name": author,
|
||||
"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").
|
||||
!{jsonLdScript}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user