Skip to content

Commit

Permalink
fix(og:local): only convert territory to uppercase
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Nov 2, 2019
1 parent 28949da commit 48d2c52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/plugins/helper/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ function openGraphHelper(options = {}) {
if (language) {
if (language.length === 5) {
const territory = language.slice(-2);
const territoryRegex = new RegExp(territory.concat('$'), 'i');

language = language.replace('-', '_').replace(territory, territory.toUpperCase());
language = language.replace('-', '_').replace(territoryRegex, territory.toUpperCase());

result += og('og:locale', language);
}
Expand Down
12 changes: 12 additions & 0 deletions test/scripts/helpers/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,18 @@ describe('open_graph', () => {
result.should.contain(meta({property: 'og:locale', content: 'es_PA'}));
});

it('og:locale - convert territory to uppercase', () => {
hexo.config.language = 'fr-fr';

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

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

it('og:locale - no language set', () => {
const result = openGraph.call({
page: {},
Expand Down

0 comments on commit 48d2c52

Please sign in to comment.