Skip to content

Commit

Permalink
Reimplement OGP with Hexo's open_graph() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWillCom committed Sep 21, 2024
1 parent 8fbbb28 commit 8ebca4c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-lemons-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'hexo-theme-cupertino': minor
---

Reimplement [OGP](https://ogp.me/) with Hexo's `open_graph()` helper. The configuration options `og_enabled`, `og_image` and `og` are now deprecated.
6 changes: 0 additions & 6 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ favicon: /favicon.png
# path to manifest.json
manifest: /manifest.json

# [Open Graph Protocol](https://ogp.me/)
og_enabled: true
og_image: /favicon.png
og:
# customized og properties, which can replace the defaults

# show excerpt on post list
show_excerpt: false

Expand Down
32 changes: 2 additions & 30 deletions layout/_partial/head.ejs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<head<% if (theme.og_enabled) { %> prefix="og: https://ogp.me/ns#"<% } %>>
<head prefix="og: https://ogp.me/ns#">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="light dark">
Expand Down Expand Up @@ -37,35 +37,7 @@
<link rel='manifest' href='<%= theme.manifest %>'>
<% } %>

<% if (theme.og_enabled) { %>
<%
var og = {};
og['title'] = (title ? title + ' - ' : '') + config.title;
og['type'] = is_post() ? 'article' : 'website';
og['url'] = url;
og['image'] = page.cover_image ? page.cover_image : theme.og_image;
if (is_post()) {
og['article:published_time'] = page.date.toISOString();
og['article:author'] = config.author;
}
if (theme['og']) {
for (const i in theme.og) {
og[i] = theme.og[i];
}
}
if (page['og']) {
for (const i in page.og) {
og[i] = page.og[i];
}
}
%>
<% for (const i in og) { %>
<meta property="og:<%= i %>" content="<%= og[i] %>" />
<% } %>
<% } %>
<%- open_graph() %>

<% if (theme.simple_icons) { %>
<%- css(getCdnUrl('simple-icons-font', 'v13', 'font/simple-icons.min.css')) %>
Expand Down

0 comments on commit 8ebca4c

Please sign in to comment.