From 8705007f6d14419b433f7a6c390c0826826ad57e Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 12 Aug 2026 15:37:58 +0800 Subject: [PATCH] feat(open_graph): support fediverse creator metadata --- lib/plugins/helper/open_graph.ts | 11 +++++++++++ test/scripts/helpers/open_graph.ts | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/plugins/helper/open_graph.ts b/lib/plugins/helper/open_graph.ts index 7580bd5f6..9d3b7d776 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 b01525d6a..6d382fd19 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: {},