mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-10 21:17:07 +08:00
fix: 移除结构化数据中不合规范的微数据
This commit is contained in:
@@ -1027,8 +1027,6 @@ Open_Graph_meta:
|
|||||||
# https://developers.google.com/search/docs/guides/intro-structured-data
|
# https://developers.google.com/search/docs/guides/intro-structured-data
|
||||||
structured_data:
|
structured_data:
|
||||||
enable: true
|
enable: true
|
||||||
# Choose: json-ld / microdata
|
|
||||||
format: 'json-ld'
|
|
||||||
|
|
||||||
# Add the vendor prefixes to ensure compatibility
|
# Add the vendor prefixes to ensure compatibility
|
||||||
css_prefix: true
|
css_prefix: true
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
if theme.structured_data.enable && page.layout === 'post'
|
if theme.structured_data.enable && page.layout === 'post'
|
||||||
-
|
-
|
||||||
const format = theme.structured_data.format || 'json-ld'
|
// use json-ld to add structured data
|
||||||
|
|
||||||
const title = page.title
|
const title = page.title
|
||||||
const url = page.permalink
|
const url = page.permalink
|
||||||
@@ -12,7 +12,6 @@ if theme.structured_data.enable && page.layout === 'post'
|
|||||||
const authorHrefVal = page.copyright_author_href || theme.post_copyright.author_href || site.url;
|
const authorHrefVal = page.copyright_author_href || theme.post_copyright.author_href || site.url;
|
||||||
const authorHref = full_url_for(authorHrefVal);
|
const authorHref = full_url_for(authorHrefVal);
|
||||||
|
|
||||||
if (format === 'json-ld') {
|
|
||||||
const jsonLd = {
|
const jsonLd = {
|
||||||
"@context": "https://schema.org",
|
"@context": "https://schema.org",
|
||||||
"@type": "BlogPosting",
|
"@type": "BlogPosting",
|
||||||
@@ -29,30 +28,7 @@ if theme.structured_data.enable && page.layout === 'post'
|
|||||||
};
|
};
|
||||||
|
|
||||||
jsonLdScript = JSON.stringify(jsonLd, null, 2);
|
jsonLdScript = JSON.stringify(jsonLd, null, 2);
|
||||||
} else if (format === 'microdata') {
|
|
||||||
microdata = {
|
|
||||||
headline: title,
|
|
||||||
url: url,
|
|
||||||
image: image,
|
|
||||||
datePublished: datePublished,
|
|
||||||
dateModified: dateModified,
|
|
||||||
authorName: author,
|
|
||||||
authorUrl: authorHref
|
|
||||||
};
|
|
||||||
}
|
|
||||||
-
|
-
|
||||||
|
|
||||||
if (format === 'json-ld')
|
|
||||||
script(type="application/ld+json").
|
script(type="application/ld+json").
|
||||||
!{jsonLdScript}
|
!{jsonLdScript}
|
||||||
else if (format === 'microdata')
|
|
||||||
div(itemscope itemtype="https://schema.org/BlogPosting")
|
|
||||||
meta(itemprop="headline" content=microdata.headline)
|
|
||||||
link(itemprop="url" href=microdata.url)
|
|
||||||
if microdata.image
|
|
||||||
img(itemprop="image" src=microdata.image alt=microdata.headline)
|
|
||||||
meta(itemprop="datePublished" content=microdata.datePublished)
|
|
||||||
meta(itemprop="dateModified" content=microdata.dateModified)
|
|
||||||
div(itemprop="author" itemscope itemtype="https://schema.org/Person")
|
|
||||||
meta(itemprop="name" content=microdata.authorName)
|
|
||||||
link(itemprop="url" href=microdata.authorUrl)
|
|
||||||
@@ -568,8 +568,7 @@ hexo.extend.filter.register('before_generate', () => {
|
|||||||
option: null
|
option: null
|
||||||
},
|
},
|
||||||
structured_data: {
|
structured_data: {
|
||||||
enable: true,
|
enable: true
|
||||||
format: 'json-ld',
|
|
||||||
},
|
},
|
||||||
css_prefix: true,
|
css_prefix: true,
|
||||||
inject: {
|
inject: {
|
||||||
|
|||||||
Reference in New Issue
Block a user