mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-08 12:07:06 +08:00
feat(structured_data): add alternateNames for backup
This commit is contained in:
@@ -1033,7 +1033,11 @@ Open_Graph_meta:
|
||||
|
||||
# Structured Data
|
||||
# https://developers.google.com/search/docs/guides/intro-structured-data
|
||||
structured_data: true
|
||||
structured_data:
|
||||
enable: true
|
||||
# Alternate name for the site, used in structured data
|
||||
# Format: ['name1', 'name2']
|
||||
alternate_name:
|
||||
|
||||
# Add the vendor prefixes to ensure compatibility
|
||||
css_prefix: true
|
||||
|
||||
@@ -40,10 +40,22 @@ if theme.structured_data
|
||||
const isRootOrSubdomain = currentPath.split('/').filter(Boolean).length === 0;
|
||||
|
||||
if (isRootOrSubdomain) {
|
||||
const domain = new URL(config.url).hostname;
|
||||
const alternateNames = theme.structured_data.alternate_name || [];
|
||||
|
||||
if (config.subtitle) {
|
||||
alternateNames.push(config.subtitle);
|
||||
}
|
||||
|
||||
if (domain) {
|
||||
alternateNames.push(domain);
|
||||
}
|
||||
|
||||
const jsonLd = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "WebSite",
|
||||
"name": config.title,
|
||||
"alternateName": alternateNames,
|
||||
"url": full_url_for('/'),
|
||||
}
|
||||
|
||||
|
||||
@@ -574,7 +574,10 @@ hexo.extend.filter.register('before_generate', () => {
|
||||
enable: true,
|
||||
option: null
|
||||
},
|
||||
structured_data: true,
|
||||
structured_data: {
|
||||
enable: true,
|
||||
alternate_name: null
|
||||
},
|
||||
css_prefix: true,
|
||||
inject: {
|
||||
head: null,
|
||||
|
||||
Reference in New Issue
Block a user