diff --git a/lib/plugins/helper/open_graph.ts b/lib/plugins/helper/open_graph.ts index 7580bd5f..9d3b7d77 100644 --- a/lib/plugins/helper/open_graph.ts +++ b/lib/plugins/helper/open_graph.ts @@ -66,6 +66,7 @@ interface Options { updated?: Moment | Date | false; language?: string; author?: string; + fediverse_creator?: string | string[]; twitter_image?: string; twitter_id?: string; twitter_site?: string; @@ -167,6 +168,16 @@ function openGraphHelper(this: LocalsType, options: Options = {}) { }); } + if (options.fediverse_creator) { + const fediverseCreators = Array.isArray(options.fediverse_creator) + ? options.fediverse_creator + : [options.fediverse_creator]; + + fediverseCreators.filter(Boolean).forEach(creator => { + result += meta('fediverse:creator', creator); + }); + } + result += meta('twitter:card', twitterCard); if (options.twitter_image) { diff --git a/test/scripts/helpers/open_graph.ts b/test/scripts/helpers/open_graph.ts index b01525d6..6d382fd1 100644 --- a/test/scripts/helpers/open_graph.ts +++ b/test/scripts/helpers/open_graph.ts @@ -448,6 +448,29 @@ describe('open_graph', () => { result.should.have.string(meta({property: 'og:description', content: escaped})); }); + it('fediverse_creator - string', () => { + const result = openGraph.call({ + page: {}, + config: hexo.config, + is_post: isPost + }, {fediverse_creator: '@hexo@fosstodon.org'}); + + result.should.have.string(meta({name: 'fediverse:creator', content: '@hexo@fosstodon.org'})); + }); + + it('fediverse_creator - array', () => { + const result = openGraph.call({ + page: {}, + config: hexo.config, + is_post: isPost + }, {fediverse_creator: ['@hexo@fosstodon.org', '@hexo@mastodon.social']}); + + result.should.have.string([ + meta({name: 'fediverse:creator', content: '@hexo@fosstodon.org'}), + meta({name: 'fediverse:creator', content: '@hexo@mastodon.social'}) + ].join('\n')); + }); + it('twitter_card - options', () => { const result = openGraph.call({ page: {},