Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update Open Graph configuration and deprecate old format #473

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions layout/components/header/head.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,24 @@
<meta name="robots" content="index,follow">
<meta name="googlebot" content="index,follow">
<meta name="revisit-after" content="1 days">
<% 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) { %>
Expand Down
16 changes: 16 additions & 0 deletions scripts/helpers/theme-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Binary file added source/images/redefine-og.webp
Binary file not shown.
Loading