Skip to content

Commit

Permalink
Merge pull request #1683 from yanni4night/master
Browse files Browse the repository at this point in the history
keywords supported in open_graph
  • Loading branch information
Xuanwo committed Jan 11, 2016
2 parents e4a5204 + c65fd26 commit a0888fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 9 additions & 1 deletion lib/plugins/helper/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function openGraphHelper(options) {
var content = page.content;
var images = options.image || options.images || page.photos || [];
var description = options.description || page.description || page.excerpt || content || config.description;
var keywords = page.tags;
var title = options.title || page.title || config.title;
var type = options.type || (this.is_post() ? 'article' : 'website');
var url = options.url || this.url;
Expand All @@ -43,7 +44,7 @@ function openGraphHelper(options) {

if (description) {
description = stripHTML(description).substring(0, 200)
.replace(/^\s+|\s+$/g, '') // Remove prefixing/trailing spaces
.trim() // Remove prefixing/trailing spaces
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/&/g, '&amp;')
Expand All @@ -63,6 +64,13 @@ function openGraphHelper(options) {
}

result += meta('description', description);
if (keywords && Array.isArray(keywords)) {
result += meta('keywords', keywords.map(function (tag) {
return tag.name;
}).filter(function (keyword) {
return !!keyword;
}).join());
}
result += og('og:type', type);
result += og('og:title', title);
result += og('og:url', url);
Expand Down
13 changes: 10 additions & 3 deletions test/scripts/helpers/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ describe('open_graph', function() {

it('default', function() {
var result = openGraph.call({
page: {},
config: hexo.config,
is_post: isPost
page: {
tags: [{
name: 'optimize'
}, {
name: 'web'
}]
},
config: hexo.config,
is_post: isPost
});

result.should.eql([
meta({name: 'description'}),
meta({name: 'keywords', content: 'optimize,web'}),
meta({property: 'og:type', content: 'website'}),
meta({property: 'og:title', content: hexo.config.title}),
meta({property: 'og:url'}),
Expand Down

0 comments on commit a0888fa

Please sign in to comment.