diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts index 29c59d82b765..052437c3dec6 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts @@ -113,6 +113,66 @@ describe('getBlogPostAuthors', () => { baseUrl: '/', }), ).toEqual([{key: 'slorber', name: 'Sébastien Lorber'}]); + expect( + getBlogPostAuthors({ + frontMatter: { + authors: 'slorber', + }, + authorsMap: { + slorber: { + name: 'Sébastien Lorber', + imageURL: 'https://github.com/slorber.png', + }, + }, + baseUrl: '/', + }), + ).toEqual([ + { + key: 'slorber', + name: 'Sébastien Lorber', + imageURL: 'https://github.com/slorber.png', + }, + ]); + expect( + getBlogPostAuthors({ + frontMatter: { + authors: 'slorber', + }, + authorsMap: { + slorber: { + name: 'Sébastien Lorber', + imageURL: '/img/slorber.png', + }, + }, + baseUrl: '/', + }), + ).toEqual([ + { + key: 'slorber', + name: 'Sébastien Lorber', + imageURL: '/img/slorber.png', + }, + ]); + expect( + getBlogPostAuthors({ + frontMatter: { + authors: 'slorber', + }, + authorsMap: { + slorber: { + name: 'Sébastien Lorber', + imageURL: '/img/slorber.png', + }, + }, + baseUrl: '/baseUrl', + }), + ).toEqual([ + { + key: 'slorber', + name: 'Sébastien Lorber', + imageURL: '/baseUrl/img/slorber.png', + }, + ]); }); it('can read authors string[]', () => { diff --git a/packages/docusaurus-plugin-content-blog/src/authors.ts b/packages/docusaurus-plugin-content-blog/src/authors.ts index a46ecb8063e2..540341da7d73 100644 --- a/packages/docusaurus-plugin-content-blog/src/authors.ts +++ b/packages/docusaurus-plugin-content-blog/src/authors.ts @@ -74,16 +74,20 @@ type AuthorsParam = { // Legacy v1/early-v2 front matter fields // We may want to deprecate those in favor of using only frontMatter.authors -function getFrontMatterAuthorLegacy(params: AuthorsParam): Author | undefined { - const name = params.frontMatter.author; - const title = - params.frontMatter.author_title ?? params.frontMatter.authorTitle; - const url = params.frontMatter.author_url ?? params.frontMatter.authorURL; - let imageURL = - params.frontMatter.author_image_url ?? params.frontMatter.authorImageURL; - - if (params.baseUrl !== '/' && imageURL && !imageURL.startsWith('http')) { - imageURL = path.join(params.baseUrl, imageURL); +function getFrontMatterAuthorLegacy({ + baseUrl, + frontMatter, +}: { + baseUrl: string; + frontMatter: BlogPostFrontMatter; +}): Author | undefined { + const name = frontMatter.author; + const title = frontMatter.author_title ?? frontMatter.authorTitle; + const url = frontMatter.author_url ?? frontMatter.authorURL; + let imageURL = frontMatter.author_image_url ?? frontMatter.authorImageURL; + + if (baseUrl !== '/' && imageURL && !imageURL.startsWith('http')) { + imageURL = path.join(baseUrl, imageURL); } if (name || title || url || imageURL) {