Skip to content

Commit 9a9dcad

Browse files
fix(open_graph): sort the tags
* See: #5458
1 parent 4b325f3 commit 9a9dcad

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/plugins/helper/open_graph.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function openGraphHelper(this: LocalsType, options: Options = {}) {
162162

163163
keywords.map(tag => {
164164
return tag.name ? tag.name : tag;
165-
}).filter(Boolean).forEach(keyword => {
165+
}).filter(Boolean).sort().forEach(keyword => {
166166
result += og('article:tag', keyword);
167167
});
168168
}

test/scripts/helpers/open_graph.ts

+15
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,21 @@ describe('open_graph', () => {
590590
result.should.have.string(meta({property: 'article:tag', content: keywords[1]}));
591591
});
592592

593+
// See https://github.com/hexojs/hexo/issues/5458
594+
it('keywords - page tags sorted', () => {
595+
const ctx = {
596+
page: { tags: ['web', 'optimize'] },
597+
config: hexo.config,
598+
is_post: isPost
599+
};
600+
601+
const result = openGraph.call(ctx);
602+
const keywords = ['web', 'optimize'].sort();
603+
604+
result.should.have.string(meta({ property: 'article:tag', content: keywords[0] }));
605+
result.should.have.string(meta({ property: 'article:tag', content: keywords[1] }));
606+
});
607+
593608
it('keywords - config keywords array', () => {
594609
hexo.config.keywords = ['optimize', 'web'];
595610
const ctx = {

0 commit comments

Comments
 (0)