Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into dev
  • Loading branch information
jerryc127 committed Nov 15, 2024
2 parents b7771e5 + 74c555f commit f7483d5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,10 @@ Open_Graph_meta:
# fb_admins:
# fb_app_id:

# Structured Data
# https://developers.google.com/search/docs/guides/intro-structured-data
structured_data: true

# Add the vendor prefixes to ensure compatibility
css_prefix: true

Expand Down
3 changes: 3 additions & 0 deletions layout/includes/head.pug
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ meta(name="theme-color" content=themeColor)
//- Open_Graph
include ./head/Open_Graph.pug

//- Structured Data
include ./head/structured_data.pug

!=favicon_tag(theme.favicon || config.favicon)
link(rel="canonical" href=urlNoIndex(null,config.pretty_urls.trailing_index,config.pretty_urls.trailing_html))

Expand Down
34 changes: 34 additions & 0 deletions layout/includes/head/structured_data.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
if theme.structured_data && page.layout === 'post'
-
// use json-ld to add structured data
const title = page.title
const url = page.permalink
const imageVal = page.cover_type === 'img' ? page.cover : theme.avatar.img
const image = imageVal ? full_url_for(imageVal) : ''
const datePublished = page.date.toISOString()
const dateModified = (page.updated || page.date).toISOString()
const author = page.copyright_author || config.author
const authorHrefVal = page.copyright_author_href || theme.post_copyright.author_href || site.url;
const authorHref = full_url_for(authorHrefVal);
const jsonLd = {
"@context": "https://schema.org",
"@type": "BlogPosting",
"headline": title,
"url": url,
"image": image,
"datePublished": datePublished,
"dateModified": dateModified,
"author": [{
"@type": "Person",
"name": author,
"url": authorHref
}]
};
jsonLdScript = JSON.stringify(jsonLd, null, 2);
-
script(type="application/ld+json").
!{jsonLdScript}
1 change: 1 addition & 0 deletions scripts/events/merge_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ hexo.extend.filter.register('before_generate', () => {
enable: true,
option: null
},
structured_data: true,
css_prefix: true,
inject: {
head: null,
Expand Down
2 changes: 1 addition & 1 deletion scripts/filters/random_cover.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict'

hexo.extend.filter.register('before_post_render', data => {
const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/i
const imgTestReg = /\.(png|jpe?g|gif|svg|webp|avif)(\?.*)?$/i
let { cover: coverVal, top_img: topImg } = data

// Add path to top_img and cover if post_asset_folder is enabled
Expand Down

0 comments on commit f7483d5

Please sign in to comment.