Skip to content

Commit

Permalink
fix(open_graph): htmlTag escapes html by default
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Oct 7, 2019
1 parent d5fb012 commit 8bd3439
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions lib/plugins/helper/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@

const urlFn = require('url');
const moment = require('moment');
const { encodeURL, escapeHTML, htmlTag, stripHTML } = require('hexo-util');

function meta(name, content, escape) {
if (escape !== false && typeof content === 'string') {
content = escapeHTML(content);
}
const { encodeURL, htmlTag, stripHTML } = require('hexo-util');

function meta(name, content) {
return `${htmlTag('meta', {
name,
content
})}\n`;
}

function og(name, content, escape) {
if (escape !== false && typeof content === 'string') {
content = escapeHTML(content);
}

function og(name, content) {
return `${htmlTag('meta', {
property: name,
content
Expand Down Expand Up @@ -70,7 +62,7 @@ function openGraphHelper(options = {}) {
let result = '';

if (description) {
result += meta('description', description, false);
result += meta('description', description);
}

if (keywords) {
Expand All @@ -91,15 +83,15 @@ function openGraphHelper(options = {}) {
}

if (url) url = encodeURL(url);
result += og('og:url', url, false);
result += og('og:url', url);

result += og('og:site_name', siteName);
if (description) {
result += og('og:description', description, false);
result += og('og:description', description);
}

if (language) {
result += og('og:locale', language, false);
result += og('og:locale', language);
}

images = images.map(path => {
Expand All @@ -113,7 +105,7 @@ function openGraphHelper(options = {}) {
});

images.forEach(path => {
result += og('og:image', path, false);
result += og('og:image', path);
});

if (updated) {
Expand All @@ -125,7 +117,7 @@ function openGraphHelper(options = {}) {
result += meta('twitter:card', twitterCard);

if (images.length) {
result += meta('twitter:image', images[0], false);
result += meta('twitter:image', images[0]);
}

if (options.twitter_id) {
Expand All @@ -136,7 +128,7 @@ function openGraphHelper(options = {}) {
}

if (options.twitter_site) {
result += meta('twitter:site', options.twitter_site, false);
result += meta('twitter:site', options.twitter_site);
}

if (options.google_plus) {
Expand Down

0 comments on commit 8bd3439

Please sign in to comment.