diff --git a/_config.yml b/_config.yml index fdad5137..6467e207 100755 --- a/_config.yml +++ b/_config.yml @@ -91,10 +91,10 @@ global: enable: false custom_message: # Custom message. If empty, the site title will be displayed # Whether to enable open graph - open_graph: true - og_settings: - image: /images/redefine-avatar.svg # default og:image - description: this is og description + open_graph: + enable: true + image: /images/redefine-og.webp # default og:image + description: Hexo Theme Redefine, Redefine Your Hexo Journey. # Google Analytics google_analytics: enable: false # Whether to enable Google Analytics diff --git a/layout/components/header/head.ejs b/layout/components/header/head.ejs index 01bd0985..21b6a985 100755 --- a/layout/components/header/head.ejs +++ b/layout/components/header/head.ejs @@ -31,14 +31,24 @@ - <% if (theme.global.open_graph) { %> + + <% checkDeprecation( + theme.global.open_graph === true, + 'open_graph', + "Using 'open_graph: true' is deprecated. Please update to the new format:\nglobal:\n open_graph:\n enable: true\n image: your_image_path\n description: your_description" + ) %> + <% if (theme.global.open_graph?.enable || theme.global.open_graph === true) { %> <% - let ogImage = page.og_image || theme.global.og_settings.image; - let ogDescription = page.og_description || theme.global.og_settings.description || page.description || config.description; + let ogImage = page.og_image || theme.global.open_graph?.image; + let ogDescription = page.og_description || theme.global.open_graph?.description || page.description || config.description; + let author = page.author || config.author || 'Redefine Team'; %> <%- open_graph({ image: ogImage, - description: ogDescription + author: author, + description: ogDescription, + twitter_card: 'summary', + twitter_image: ogImage, }) %> <% } %> <% if (theme.global.google_analytics.enable) { %> diff --git a/scripts/helpers/theme-helpers.js b/scripts/helpers/theme-helpers.js index e8ce64bf..18292a00 100755 --- a/scripts/helpers/theme-helpers.js +++ b/scripts/helpers/theme-helpers.js @@ -209,3 +209,19 @@ hexo.extend.helper.register("renderCSS", function (path) { hexo.extend.helper.register("getThemeVersion", function () { return themeVersion; }); + +hexo.extend.helper.register("checkDeprecation", function (condition, id, message) { + if (condition) { + // Use Set to ensure each warning is only logged once per Hexo process + if (!global.deprecationWarnings) { + global.deprecationWarnings = new Set(); + } + + if (!global.deprecationWarnings.has(id)) { + hexo.log.warn(`${message}`); + global.deprecationWarnings.add(id); + } + return true; + } + return false; +}); diff --git a/source/images/redefine-og.webp b/source/images/redefine-og.webp new file mode 100644 index 00000000..f2afcf24 Binary files /dev/null and b/source/images/redefine-og.webp differ