Skip to content

Commit

Permalink
Merge pull request #20 from markleetw/add-publisher-to-strutured-data
Browse files Browse the repository at this point in the history
Add "publisher" to strutured data
  • Loading branch information
ppoffice committed Feb 20, 2021
2 parents e055329 + 06c1662 commit 7a54834
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/schema/misc/structured_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
"description": "Page author (article:author) (optional)\nYou should leave this blank for most of the time",
"nullable": true
},
"publisher": {
"type": "string",
"description": "Page publisher (optional)\nYou should leave this blank for most of the time",
"nullable": true
},
"publisher_logo": {
"type": "string",
"description": "Page publisher logo (optional)\nYou should leave this blank for most of the time",
"nullable": true
},
"image": {
"type": ["string", "array"],
"description": "Page images (optional)\nYou should leave this blank for most of the time",
Expand Down
25 changes: 22 additions & 3 deletions src/view/misc/structured_data.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ const { stripHTML, escapeHTML } = require('hexo-util');
* title="Page title"
* url="/page/url"
* author="Page author name"
* publisher="Page publisher name"
* description="Page description"
* images={[ '/path/to/image' ]}
* date="Page publish date"
* updated="Page update date" />
*/
module.exports = class extends Component {
render() {
const { title, url, author } = this.props;
let { description, images, date, updated } = this.props;
const { title, url, author, publisher } = this.props;
let { description, images, date, updated, publisherLogo } = this.props;

if (description) {
description = escapeHTML(stripHTML(description).substring(0, 200).trim()).replace(/\n/g, ' ');
Expand All @@ -42,7 +43,17 @@ module.exports = class extends Component {
}
return path;
})
.filter((url) => url.endsWith('.jpg') || url.endsWith('.png') || url.endsWith('.gif'));
.filter(
(url) =>
url.endsWith('.jpg') ||
url.endsWith('.png') ||
url.endsWith('.gif') ||
url.endsWith('.webp'),
);

if (!urlFn.parse(publisherLogo).host) {
publisherLogo = urlFn.resolve(url, publisherLogo);
}

if (date && (moment.isMoment(date) || moment.isDate(date)) && !isNaN(date.valueOf())) {
date = date.toISOString();
Expand Down Expand Up @@ -71,6 +82,14 @@ module.exports = class extends Component {
'@type': 'Person',
name: author,
},
publisher: {
'@type': 'Organization',
name: publisher,
logo: {
'@type': 'ImageObject',
url: publisherLogo,
},
},
description: description,
};

Expand Down

0 comments on commit 7a54834

Please sign in to comment.