Skip to content

Commit

Permalink
include og:locale
Browse files Browse the repository at this point in the history
The og:locale attribute will be set according to the options, the page language or finally the site config. When no language is set anywhere, the og:locale attribute is not set.
  • Loading branch information
tilsammans committed Jun 30, 2017
1 parent 5a28258 commit 8f4c220
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/plugins/helper/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function openGraphHelper(options) {
var siteName = options.site_name || config.title;
var twitterCard = options.twitter_card || 'summary';
var updated = options.updated !== false ? (options.updated || page.updated) : false;
var language = options.language || page.lang || page.language || config.language;
var result = '';

if (!Array.isArray(images)) images = [images];
Expand Down Expand Up @@ -96,6 +97,9 @@ function openGraphHelper(options) {
if (description) {
result += og('og:description', description, false);
}
if (language) {
result += og('og:locale', language, false);
}

images = images.map(function(path) {
if (!urlFn.parse(path).host) {
Expand Down
52 changes: 52 additions & 0 deletions test/scripts/helpers/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,56 @@ describe('open_graph', () => {

result.should.contain(meta({name: 'keywords', content: keywords}));
});

it('og:locale - options.language', () => {
var result = openGraph.call({
page: {},
config: hexo.config,
is_post: isPost
}, {language: 'es-cr'});

result.should.contain(meta({property: 'og:locale', content: 'es-cr'}));
});

it('og:locale - page.lang', () => {
var result = openGraph.call({
page: { lang: 'es-mx' },
config: hexo.config,
is_post: isPost
});

result.should.contain(meta({property: 'og:locale', content: 'es-mx'}));
});

it('og:locale - page.language', () => {
var result = openGraph.call({
page: { language: 'es-gt' },
config: hexo.config,
is_post: isPost
});

result.should.contain(meta({property: 'og:locale', content: 'es-gt'}));
});

it('og:locale - config.language', () => {
hexo.config.language = 'es-pa';

var result = openGraph.call({
page: {},
config: hexo.config,
is_post: isPost
});

result.should.contain(meta({property: 'og:locale', content: 'es-pa'}));
});

it('og:locale - no language set', () => {
var result = openGraph.call({
page: {},
config: hexo.config,
is_post: isPost
});

result.should.not.contain(meta({property: 'og:locale'}));
})
});

0 comments on commit 8f4c220

Please sign in to comment.