Skip to content

Commit

Permalink
fix(open_graph): territory must be in uppercase
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Oct 28, 2019
1 parent 7704dcb commit 28949da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lib/plugins/helper/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ function openGraphHelper(options = {}) {
}

if (language) {
language = language.replace('-', '_');
if (language.length === 5) {
const territory = language.slice(-2);

if (language.length === 5) result += og('og:locale', language);
language = language.replace('-', '_').replace(territory, territory.toUpperCase());

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

images = images.map(path => {
Expand Down
8 changes: 4 additions & 4 deletions test/scripts/helpers/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ describe('open_graph', () => {
is_post: isPost
}, {language: 'es-cr'});

result.should.contain(meta({property: 'og:locale', content: 'es_cr'}));
result.should.contain(meta({property: 'og:locale', content: 'es_CR'}));
});

it('og:locale - page.lang', () => {
Expand All @@ -623,7 +623,7 @@ describe('open_graph', () => {
is_post: isPost
});

result.should.contain(meta({property: 'og:locale', content: 'es_mx'}));
result.should.contain(meta({property: 'og:locale', content: 'es_MX'}));
});

it('og:locale - page.language', () => {
Expand All @@ -633,7 +633,7 @@ describe('open_graph', () => {
is_post: isPost
});

result.should.contain(meta({property: 'og:locale', content: 'es_gt'}));
result.should.contain(meta({property: 'og:locale', content: 'es_GT'}));
});

it('og:locale - config.language', () => {
Expand All @@ -645,7 +645,7 @@ describe('open_graph', () => {
is_post: isPost
});

result.should.contain(meta({property: 'og:locale', content: 'es_pa'}));
result.should.contain(meta({property: 'og:locale', content: 'es_PA'}));
});

it('og:locale - no language set', () => {
Expand Down

0 comments on commit 28949da

Please sign in to comment.