From 1eb2af6ee68356f4400aaf6043908c38a50ee840 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Mon, 17 Jun 2024 17:08:30 +0200 Subject: [PATCH 01/22] feat(blog): warn duplicate and inline authors --- .../src/authors.ts | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-plugin-content-blog/src/authors.ts b/packages/docusaurus-plugin-content-blog/src/authors.ts index c5fdad61ddfb..291e4c9ea334 100644 --- a/packages/docusaurus-plugin-content-blog/src/authors.ts +++ b/packages/docusaurus-plugin-content-blog/src/authors.ts @@ -7,6 +7,7 @@ import {getDataFileData, normalizeUrl} from '@docusaurus/utils'; import {Joi, URISchema} from '@docusaurus/utils-validation'; +import logger from '@docusaurus/logger'; import type {BlogContentPaths} from './types'; import type { Author, @@ -123,6 +124,11 @@ function normalizeFrontMatterAuthors( // we only support keys, otherwise, a typo in a key would fallback to // becoming a name and may end up unnoticed return {key: authorInput}; + } else if (typeof authorInput === 'object' && !('key' in authorInput)) { + return { + ...authorInput, + inline: true, + }; } return authorInput; } @@ -171,7 +177,7 @@ ${Object.keys(authorsMap) function fixAuthorImageBaseURL( authors: Author[], {baseUrl}: {baseUrl: string}, -) { +): Author[] { return authors.map((author) => ({ ...author, imageURL: normalizeImageUrl({imageURL: author.imageURL, baseUrl}), @@ -196,5 +202,33 @@ Don't mix 'authors' with other existing 'author_*' front matter. Choose one or t return [authorLegacy]; } + const inlineAuthors = updatedAuthors.filter((author) => author.inline); + + const duplicateList = updatedAuthors.filter( + (author, index, self) => + index !== self.findIndex((t) => t.name === author.name), + ); + + // TODO need title check otherwise reports weird cases + if (inlineAuthors.length > 0 && params.frontMatter.title) { + logger.warn( + `Inline authors found in blog [${ + params.frontMatter.title + }] ${inlineAuthors.map((author) => author.name).join(', ')}`, + ); + } + + // TODO need title check otherwise reports weird cases + if (duplicateList.length > 0 && params.frontMatter.title) { + console.log('duplicateList', duplicateList); + logger.error( + `Duplicate authors found in blog post ${params.frontMatter.title} [${ + params.frontMatter.slug + }] front matter: ${duplicateList + .map((author) => author.name) + .join(', ')}`, + ); + } + return updatedAuthors; } From 373ab745bd803702b31953aa8bbb2a1763d169d6 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Mon, 17 Jun 2024 17:32:19 +0200 Subject: [PATCH 02/22] fix tests --- .../src/__tests__/authors.test.ts | 16 +++++++++++++--- .../src/__tests__/index.test.ts | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) 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 052437c3dec6..7efe566f5fa7 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts @@ -218,8 +218,17 @@ describe('getBlogPostAuthors', () => { baseUrl: '/', }), ).toEqual([ - {name: 'Sébastien Lorber', title: 'maintainer'}, - {name: 'Yangshun Tay'}, + { + name: 'Sébastien Lorber', + title: 'maintainer', + imageURL: undefined, + inline: true, + }, + { + name: 'Yangshun Tay', + imageURL: undefined, + inline: true, + }, ]); }); @@ -250,8 +259,9 @@ describe('getBlogPostAuthors', () => { name: 'Yangshun Tay', title: 'Yangshun title local override', extra: 42, + imageURL: undefined, }, - {name: 'Alexey'}, + {name: 'Alexey', inline: true, imageURL: undefined}, ]); }); diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts index 5280a72c18c8..18669c0794f8 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts @@ -220,9 +220,11 @@ describe('blog plugin', () => { authors: [ { name: 'Yangshun Tay (translated)', + inline: true, }, { email: 'lorber.sebastien@gmail.com', + imageURL: undefined, key: 'slorber', name: 'Sébastien Lorber (translated)', title: 'Docusaurus maintainer (translated)', From 5833974d5e93436fb1df0e864c320fc3f8f9b6f7 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Mon, 17 Jun 2024 17:46:35 +0200 Subject: [PATCH 03/22] fix test --- .../src/__tests__/authors.test.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 7efe566f5fa7..0a6031805a44 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts @@ -202,7 +202,14 @@ describe('getBlogPostAuthors', () => { authorsMap: undefined, baseUrl: '/', }), - ).toEqual([{name: 'Sébastien Lorber', title: 'maintainer'}]); + ).toEqual([ + { + name: 'Sébastien Lorber', + title: 'maintainer', + imageURL: undefined, + inline: true, + }, + ]); }); it('can read authors Author[]', () => { From 8d71167022d5c8ee154f33a514fccf43c72d02c3 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:15:28 +0200 Subject: [PATCH 04/22] feat: tests --- .../src/__tests__/authors.test.ts | 498 +++++++++++------- .../src/__tests__/feed.test.ts | 5 + .../src/authors.ts | 84 ++- .../src/blogUtils.ts | 6 +- .../src/options.ts | 4 + .../src/plugin-content-blog.d.ts | 2 + website/_dogfooding/dogfooding.config.ts | 1 + website/docusaurus.config.ts | 1 + 8 files changed, 390 insertions(+), 211 deletions(-) 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 0a6031805a44..19ecc38f08a1 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts @@ -11,88 +11,123 @@ import { getAuthorsMap, getBlogPostAuthors, validateAuthorsMap, + reportDuplicateAuthors, + reportInlineAuthors, } from '../authors'; +import type {Author} from '@docusaurus/plugin-content-blog'; describe('getBlogPostAuthors', () => { it('can read no authors', () => { expect( - getBlogPostAuthors({ - frontMatter: {}, - authorsMap: undefined, - baseUrl: '/', - }), + getBlogPostAuthors( + { + frontMatter: {}, + authorsMap: undefined, + baseUrl: '/', + }, + 'ignore', + '', + ), ).toEqual([]); expect( - getBlogPostAuthors({ - frontMatter: { - authors: [], + getBlogPostAuthors( + { + frontMatter: { + authors: [], + }, + authorsMap: undefined, + baseUrl: '/', }, - authorsMap: undefined, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toEqual([]); }); it('can read author from legacy front matter', () => { expect( - getBlogPostAuthors({ - frontMatter: { - author: 'Sébastien Lorber', + getBlogPostAuthors( + { + frontMatter: { + author: 'Sébastien Lorber', + }, + authorsMap: undefined, + baseUrl: '/', }, - authorsMap: undefined, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toEqual([{name: 'Sébastien Lorber'}]); expect( - getBlogPostAuthors({ - frontMatter: { - authorTitle: 'maintainer', + getBlogPostAuthors( + { + frontMatter: { + authorTitle: 'maintainer', + }, + authorsMap: undefined, + baseUrl: '/', }, - authorsMap: undefined, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toEqual([{title: 'maintainer'}]); expect( - getBlogPostAuthors({ - frontMatter: { - authorImageURL: 'https://github.com/slorber.png', + getBlogPostAuthors( + { + frontMatter: { + authorImageURL: 'https://github.com/slorber.png', + }, + authorsMap: undefined, + baseUrl: '/', }, - authorsMap: undefined, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toEqual([{imageURL: 'https://github.com/slorber.png'}]); expect( - getBlogPostAuthors({ - frontMatter: { - authorImageURL: '/img/slorber.png', + getBlogPostAuthors( + { + frontMatter: { + authorImageURL: '/img/slorber.png', + }, + authorsMap: undefined, + baseUrl: '/', }, - authorsMap: undefined, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toEqual([{imageURL: '/img/slorber.png'}]); expect( - getBlogPostAuthors({ - frontMatter: { - authorImageURL: '/img/slorber.png', + getBlogPostAuthors( + { + frontMatter: { + authorImageURL: '/img/slorber.png', + }, + authorsMap: undefined, + baseUrl: '/baseURL', }, - authorsMap: undefined, - baseUrl: '/baseURL', - }), + 'ignore', + '', + ), ).toEqual([{imageURL: '/baseURL/img/slorber.png'}]); expect( - getBlogPostAuthors({ - frontMatter: { - author: 'Sébastien Lorber', - author_title: 'maintainer1', - authorTitle: 'maintainer2', - author_image_url: 'https://github.com/slorber1.png', - authorImageURL: 'https://github.com/slorber2.png', - author_url: 'https://github.com/slorber1', - authorURL: 'https://github.com/slorber2', + getBlogPostAuthors( + { + frontMatter: { + author: 'Sébastien Lorber', + author_title: 'maintainer1', + authorTitle: 'maintainer2', + author_image_url: 'https://github.com/slorber1.png', + authorImageURL: 'https://github.com/slorber2.png', + author_url: 'https://github.com/slorber1', + authorURL: 'https://github.com/slorber2', + }, + authorsMap: undefined, + baseUrl: '/', }, - authorsMap: undefined, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toEqual([ { name: 'Sébastien Lorber', @@ -105,27 +140,35 @@ describe('getBlogPostAuthors', () => { it('can read authors string', () => { expect( - getBlogPostAuthors({ - frontMatter: { - authors: 'slorber', + getBlogPostAuthors( + { + frontMatter: { + authors: 'slorber', + }, + authorsMap: {slorber: {name: 'Sébastien Lorber'}}, + baseUrl: '/', }, - authorsMap: {slorber: {name: 'Sébastien Lorber'}}, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toEqual([{key: 'slorber', name: 'Sébastien Lorber'}]); expect( - getBlogPostAuthors({ - frontMatter: { - authors: 'slorber', - }, - authorsMap: { - slorber: { - name: 'Sébastien Lorber', - imageURL: 'https://github.com/slorber.png', + getBlogPostAuthors( + { + frontMatter: { + authors: 'slorber', + }, + authorsMap: { + slorber: { + name: 'Sébastien Lorber', + imageURL: 'https://github.com/slorber.png', + }, }, + baseUrl: '/', }, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toEqual([ { key: 'slorber', @@ -134,18 +177,22 @@ describe('getBlogPostAuthors', () => { }, ]); expect( - getBlogPostAuthors({ - frontMatter: { - authors: 'slorber', - }, - authorsMap: { - slorber: { - name: 'Sébastien Lorber', - imageURL: '/img/slorber.png', + getBlogPostAuthors( + { + frontMatter: { + authors: 'slorber', }, + authorsMap: { + slorber: { + name: 'Sébastien Lorber', + imageURL: '/img/slorber.png', + }, + }, + baseUrl: '/', }, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toEqual([ { key: 'slorber', @@ -154,18 +201,22 @@ describe('getBlogPostAuthors', () => { }, ]); expect( - getBlogPostAuthors({ - frontMatter: { - authors: 'slorber', - }, - authorsMap: { - slorber: { - name: 'Sébastien Lorber', - imageURL: '/img/slorber.png', + getBlogPostAuthors( + { + frontMatter: { + authors: 'slorber', + }, + authorsMap: { + slorber: { + name: 'Sébastien Lorber', + imageURL: '/img/slorber.png', + }, }, + baseUrl: '/baseUrl', }, - baseUrl: '/baseUrl', - }), + 'ignore', + '', + ), ).toEqual([ { key: 'slorber', @@ -177,16 +228,20 @@ describe('getBlogPostAuthors', () => { it('can read authors string[]', () => { expect( - getBlogPostAuthors({ - frontMatter: { - authors: ['slorber', 'yangshun'], - }, - authorsMap: { - slorber: {name: 'Sébastien Lorber', title: 'maintainer'}, - yangshun: {name: 'Yangshun Tay'}, + getBlogPostAuthors( + { + frontMatter: { + authors: ['slorber', 'yangshun'], + }, + authorsMap: { + slorber: {name: 'Sébastien Lorber', title: 'maintainer'}, + yangshun: {name: 'Yangshun Tay'}, + }, + baseUrl: '/', }, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toEqual([ {key: 'slorber', name: 'Sébastien Lorber', title: 'maintainer'}, {key: 'yangshun', name: 'Yangshun Tay'}, @@ -195,13 +250,17 @@ describe('getBlogPostAuthors', () => { it('can read authors Author', () => { expect( - getBlogPostAuthors({ - frontMatter: { - authors: {name: 'Sébastien Lorber', title: 'maintainer'}, + getBlogPostAuthors( + { + frontMatter: { + authors: {name: 'Sébastien Lorber', title: 'maintainer'}, + }, + authorsMap: undefined, + baseUrl: '/', }, - authorsMap: undefined, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toEqual([ { name: 'Sébastien Lorber', @@ -214,16 +273,20 @@ describe('getBlogPostAuthors', () => { it('can read authors Author[]', () => { expect( - getBlogPostAuthors({ - frontMatter: { - authors: [ - {name: 'Sébastien Lorber', title: 'maintainer'}, - {name: 'Yangshun Tay'}, - ], + getBlogPostAuthors( + { + frontMatter: { + authors: [ + {name: 'Sébastien Lorber', title: 'maintainer'}, + {name: 'Yangshun Tay'}, + ], + }, + authorsMap: undefined, + baseUrl: '/', }, - authorsMap: undefined, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toEqual([ { name: 'Sébastien Lorber', @@ -241,24 +304,28 @@ describe('getBlogPostAuthors', () => { it('can read authors complex (string | Author)[] setup with keys and local overrides', () => { expect( - getBlogPostAuthors({ - frontMatter: { - authors: [ - 'slorber', - { - key: 'yangshun', - title: 'Yangshun title local override', - extra: 42, - }, - {name: 'Alexey'}, - ], - }, - authorsMap: { - slorber: {name: 'Sébastien Lorber', title: 'maintainer'}, - yangshun: {name: 'Yangshun Tay', title: 'Yangshun title original'}, + getBlogPostAuthors( + { + frontMatter: { + authors: [ + 'slorber', + { + key: 'yangshun', + title: 'Yangshun title local override', + extra: 42, + }, + {name: 'Alexey'}, + ], + }, + authorsMap: { + slorber: {name: 'Sébastien Lorber', title: 'maintainer'}, + yangshun: {name: 'Yangshun Tay', title: 'Yangshun title original'}, + }, + baseUrl: '/', }, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toEqual([ {key: 'slorber', name: 'Sébastien Lorber', title: 'maintainer'}, { @@ -274,13 +341,17 @@ describe('getBlogPostAuthors', () => { it('throw when using author key with no authorsMap', () => { expect(() => - getBlogPostAuthors({ - frontMatter: { - authors: 'slorber', + getBlogPostAuthors( + { + frontMatter: { + authors: 'slorber', + }, + authorsMap: undefined, + baseUrl: '/', }, - authorsMap: undefined, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toThrowErrorMatchingInlineSnapshot(` "Can't reference blog post authors by a key (such as 'slorber') because no authors map file could be loaded. Please double-check your blog plugin config (in particular 'authorsMapPath'), ensure the file exists at the configured path, is not empty, and is valid!" @@ -289,13 +360,17 @@ describe('getBlogPostAuthors', () => { it('throw when using author key with empty authorsMap', () => { expect(() => - getBlogPostAuthors({ - frontMatter: { - authors: 'slorber', + getBlogPostAuthors( + { + frontMatter: { + authors: 'slorber', + }, + authorsMap: {}, + baseUrl: '/', }, - authorsMap: {}, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toThrowErrorMatchingInlineSnapshot(` "Can't reference blog post authors by a key (such as 'slorber') because no authors map file could be loaded. Please double-check your blog plugin config (in particular 'authorsMapPath'), ensure the file exists at the configured path, is not empty, and is valid!" @@ -304,17 +379,21 @@ describe('getBlogPostAuthors', () => { it('throw when using bad author key in string', () => { expect(() => - getBlogPostAuthors({ - frontMatter: { - authors: 'slorber', - }, + getBlogPostAuthors( + { + frontMatter: { + authors: 'slorber', + }, - authorsMap: { - yangshun: {name: 'Yangshun Tay'}, - jmarcey: {name: 'Joel Marcey'}, + authorsMap: { + yangshun: {name: 'Yangshun Tay'}, + jmarcey: {name: 'Joel Marcey'}, + }, + baseUrl: '/', }, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toThrowErrorMatchingInlineSnapshot(` "Blog author with key "slorber" not found in the authors map file. Valid author keys are: @@ -325,17 +404,21 @@ describe('getBlogPostAuthors', () => { it('throw when using bad author key in string[]', () => { expect(() => - getBlogPostAuthors({ - frontMatter: { - authors: ['yangshun', 'jmarcey', 'slorber'], - }, + getBlogPostAuthors( + { + frontMatter: { + authors: ['yangshun', 'jmarcey', 'slorber'], + }, - authorsMap: { - yangshun: {name: 'Yangshun Tay'}, - jmarcey: {name: 'Joel Marcey'}, + authorsMap: { + yangshun: {name: 'Yangshun Tay'}, + jmarcey: {name: 'Joel Marcey'}, + }, + baseUrl: '/', }, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toThrowErrorMatchingInlineSnapshot(` "Blog author with key "slorber" not found in the authors map file. Valid author keys are: @@ -346,17 +429,21 @@ describe('getBlogPostAuthors', () => { it('throw when using bad author key in Author[].key', () => { expect(() => - getBlogPostAuthors({ - frontMatter: { - authors: [{key: 'yangshun'}, {key: 'jmarcey'}, {key: 'slorber'}], - }, + getBlogPostAuthors( + { + frontMatter: { + authors: [{key: 'yangshun'}, {key: 'jmarcey'}, {key: 'slorber'}], + }, - authorsMap: { - yangshun: {name: 'Yangshun Tay'}, - jmarcey: {name: 'Joel Marcey'}, + authorsMap: { + yangshun: {name: 'Yangshun Tay'}, + jmarcey: {name: 'Joel Marcey'}, + }, + baseUrl: '/', }, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toThrowErrorMatchingInlineSnapshot(` "Blog author with key "slorber" not found in the authors map file. Valid author keys are: @@ -367,28 +454,36 @@ describe('getBlogPostAuthors', () => { it('throw when mixing legacy/new authors front matter', () => { expect(() => - getBlogPostAuthors({ - frontMatter: { - authors: [{name: 'Sébastien Lorber'}], - author: 'Yangshun Tay', + getBlogPostAuthors( + { + frontMatter: { + authors: [{name: 'Sébastien Lorber'}], + author: 'Yangshun Tay', + }, + authorsMap: undefined, + baseUrl: '/', }, - authorsMap: undefined, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toThrowErrorMatchingInlineSnapshot(` "To declare blog post authors, use the 'authors' front matter in priority. Don't mix 'authors' with other existing 'author_*' front matter. Choose one or the other, not both at the same time." `); expect(() => - getBlogPostAuthors({ - frontMatter: { - authors: [{key: 'slorber'}], - author_title: 'legacy title', + getBlogPostAuthors( + { + frontMatter: { + authors: [{key: 'slorber'}], + author_title: 'legacy title', + }, + authorsMap: {slorber: {name: 'Sébastien Lorber'}}, + baseUrl: '/', }, - authorsMap: {slorber: {name: 'Sébastien Lorber'}}, - baseUrl: '/', - }), + 'ignore', + '', + ), ).toThrowErrorMatchingInlineSnapshot(` "To declare blog post authors, use the 'authors' front matter in priority. Don't mix 'authors' with other existing 'author_*' front matter. Choose one or the other, not both at the same time." @@ -546,3 +641,40 @@ describe('validateAuthorsMap', () => { ); }); }); + +// bun run jest --watch -t "ozaki" +describe('ozaki duplicate authors', () => { + it('no duplicate authors', () => { + const authors: Author[] = [ + { + name: 'Sébastien Lorber', + title: 'maintainer', + }, + ]; + const output = reportDuplicateAuthors({ + authors, + blogSourceRelative: '', + onInlineAuthors: 'throw', + }); + + expect(output).toBeUndefined(); + }); +}); + +describe('ozaki inline authors', () => { + it('no inline authors', () => { + const authors: Author[] = [ + { + name: 'Sébastien Lorber', + title: 'maintainer', + }, + ]; + const output = reportInlineAuthors({ + onInlineAuthors: 'throw', + authors, + blogSourceRelative: '', + }); + + expect(output).toBeUndefined(); + }); +}); diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts index 8c79310890af..3fbd4dbf27fd 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts @@ -101,6 +101,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { defaultReadingTime({content}), truncateMarker: //, onInlineTags: 'ignore', + onInlineAuthors: 'ignore', } as PluginOptions, ); @@ -143,6 +144,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { defaultReadingTime({content}), truncateMarker: //, onInlineTags: 'ignore', + onInlineAuthors: 'ignore', } as PluginOptions, ); @@ -197,6 +199,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { defaultReadingTime({content}), truncateMarker: //, onInlineTags: 'ignore', + onInlineAuthors: 'ignore', } as PluginOptions, ); @@ -242,6 +245,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { defaultReadingTime({content}), truncateMarker: //, onInlineTags: 'ignore', + onInlineAuthors: 'ignore', } as PluginOptions, ); @@ -287,6 +291,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { defaultReadingTime({content}), truncateMarker: //, onInlineTags: 'ignore', + onInlineAuthors: 'ignore', } as PluginOptions, ); diff --git a/packages/docusaurus-plugin-content-blog/src/authors.ts b/packages/docusaurus-plugin-content-blog/src/authors.ts index 291e4c9ea334..6068fddf8084 100644 --- a/packages/docusaurus-plugin-content-blog/src/authors.ts +++ b/packages/docusaurus-plugin-content-blog/src/authors.ts @@ -8,6 +8,7 @@ import {getDataFileData, normalizeUrl} from '@docusaurus/utils'; import {Joi, URISchema} from '@docusaurus/utils-validation'; import logger from '@docusaurus/logger'; +import type {ReportingSeverity} from '@docusaurus/types'; import type {BlogContentPaths} from './types'; import type { Author, @@ -184,7 +185,52 @@ function fixAuthorImageBaseURL( })); } -export function getBlogPostAuthors(params: AuthorsParam): Author[] { +export function reportInlineAuthors({ + authors, + blogSourceRelative, + onInlineAuthors, +}: { + authors: Author[]; + blogSourceRelative: string; + onInlineAuthors: ReportingSeverity; +}): void { + const inlineAuthors = authors.filter((author) => author.inline); + if (inlineAuthors.length > 0 && onInlineAuthors !== 'ignore') { + logger.report(onInlineAuthors)( + `Inline authors found in blog ${blogSourceRelative} ${inlineAuthors + .map((author) => author.name ?? author.imageURL) + .join(', ')}`, + ); + } +} + +export function reportDuplicateAuthors({ + authors, + blogSourceRelative, + onInlineAuthors, +}: { + authors: Author[]; + blogSourceRelative: string; + onInlineAuthors: ReportingSeverity; +}): void { + const duplicateList = authors.filter( + (author, index, self) => + index !== self.findIndex((t) => t.name === author.name), + ); + if (duplicateList.length > 0) { + logger.report(onInlineAuthors)( + `Duplicate authors found in blog post ${blogSourceRelative} front matter: ${duplicateList + .map((author) => author.name) + .join(', ')}`, + ); + } +} + +export function getBlogPostAuthors( + params: AuthorsParam, + onInlineAuthors: ReportingSeverity, + blogSourceRelative: string, +): Author[] { const authorLegacy = getFrontMatterAuthorLegacy(params); const authors = getFrontMatterAuthors(params); @@ -202,33 +248,17 @@ Don't mix 'authors' with other existing 'author_*' front matter. Choose one or t return [authorLegacy]; } - const inlineAuthors = updatedAuthors.filter((author) => author.inline); - - const duplicateList = updatedAuthors.filter( - (author, index, self) => - index !== self.findIndex((t) => t.name === author.name), - ); - - // TODO need title check otherwise reports weird cases - if (inlineAuthors.length > 0 && params.frontMatter.title) { - logger.warn( - `Inline authors found in blog [${ - params.frontMatter.title - }] ${inlineAuthors.map((author) => author.name).join(', ')}`, - ); - } + reportInlineAuthors({ + authors: updatedAuthors, + blogSourceRelative, + onInlineAuthors, + }); - // TODO need title check otherwise reports weird cases - if (duplicateList.length > 0 && params.frontMatter.title) { - console.log('duplicateList', duplicateList); - logger.error( - `Duplicate authors found in blog post ${params.frontMatter.title} [${ - params.frontMatter.slug - }] front matter: ${duplicateList - .map((author) => author.name) - .join(', ')}`, - ); - } + reportDuplicateAuthors({ + authors: updatedAuthors, + blogSourceRelative, + onInlineAuthors, + }); return updatedAuthors; } diff --git a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts index d7a777ff77b6..967741229764 100644 --- a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts +++ b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts @@ -317,7 +317,11 @@ async function processBlogSourceFile( routeBasePath, tagsRouteBasePath, ]); - const authors = getBlogPostAuthors({authorsMap, frontMatter, baseUrl}); + const authors = getBlogPostAuthors( + {authorsMap, frontMatter, baseUrl}, + options.onInlineAuthors, + blogSourceRelative, + ); const tags = normalizeTags({ options, diff --git a/packages/docusaurus-plugin-content-blog/src/options.ts b/packages/docusaurus-plugin-content-blog/src/options.ts index 5835c32fc18f..0be0ce21f970 100644 --- a/packages/docusaurus-plugin-content-blog/src/options.ts +++ b/packages/docusaurus-plugin-content-blog/src/options.ts @@ -56,6 +56,7 @@ export const DEFAULT_OPTIONS: PluginOptions = { processBlogPosts: async () => undefined, onInlineTags: 'warn', tags: undefined, + onInlineAuthors: 'warn', }; const PluginOptionSchema = Joi.object({ @@ -153,6 +154,9 @@ const PluginOptionSchema = Joi.object({ .disallow('') .allow(null, false) .default(() => DEFAULT_OPTIONS.tags), + onInlineAuthors: Joi.string() + .equal('ignore', 'log', 'warn', 'throw') + .default(DEFAULT_OPTIONS.onInlineAuthors), }).default(DEFAULT_OPTIONS); export function validateOptions({ diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index f4d4f135c061..ff2d7cb1c9ce 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -442,6 +442,8 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the * (filter, modify, delete, etc...). */ processBlogPosts: ProcessBlogPostsFn; + /** The behavior of Docusaurus when it found inline authors. */ + onInlineAuthors: 'ignore' | 'log' | 'warn' | 'throw'; }; /** diff --git a/website/_dogfooding/dogfooding.config.ts b/website/_dogfooding/dogfooding.config.ts index d751ced7ec0a..6d8bb062e256 100644 --- a/website/_dogfooding/dogfooding.config.ts +++ b/website/_dogfooding/dogfooding.config.ts @@ -85,6 +85,7 @@ export const dogfoodingPluginInstances: PluginConfig[] = [ : defaultReadingTime({content, options: {wordsPerMinute: 5}}), onInlineTags: 'warn', tags: 'tags.yml', + onInlineAuthors: 'throw', } satisfies BlogOptions, ], diff --git a/website/docusaurus.config.ts b/website/docusaurus.config.ts index 093f70ec5a73..70d7fd33b78f 100644 --- a/website/docusaurus.config.ts +++ b/website/docusaurus.config.ts @@ -291,6 +291,7 @@ export default async function createConfigAsync() { copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, language: defaultLocale, }, + onInlineAuthors: 'warn', }, ], [ From 83bf8141f7c61375f94efbca0d45f4917e98c5e4 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Fri, 21 Jun 2024 16:59:30 +0200 Subject: [PATCH 05/22] refactor --- .../src/__tests__/authors.test.ts | 283 ++++++++++-------- .../src/authors.ts | 60 ++-- .../src/blogUtils.ts | 11 +- website/_dogfooding/dogfooding.config.ts | 2 +- 4 files changed, 200 insertions(+), 156 deletions(-) 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 19ecc38f08a1..94fc2fe34d99 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts @@ -19,100 +19,101 @@ import type {Author} from '@docusaurus/plugin-content-blog'; describe('getBlogPostAuthors', () => { it('can read no authors', () => { expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: {}, authorsMap: undefined, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([]); expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: [], }, authorsMap: undefined, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([]); }); it('can read author from legacy front matter', () => { expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { author: 'Sébastien Lorber', }, authorsMap: undefined, baseUrl: '/', }, - 'ignore', - '', - ), + + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([{name: 'Sébastien Lorber'}]); expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authorTitle: 'maintainer', }, authorsMap: undefined, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([{title: 'maintainer'}]); expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authorImageURL: 'https://github.com/slorber.png', }, authorsMap: undefined, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([{imageURL: 'https://github.com/slorber.png'}]); expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authorImageURL: '/img/slorber.png', }, authorsMap: undefined, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([{imageURL: '/img/slorber.png'}]); expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authorImageURL: '/img/slorber.png', }, authorsMap: undefined, baseUrl: '/baseURL', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([{imageURL: '/baseURL/img/slorber.png'}]); expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { author: 'Sébastien Lorber', author_title: 'maintainer1', @@ -125,9 +126,9 @@ describe('getBlogPostAuthors', () => { authorsMap: undefined, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([ { name: 'Sébastien Lorber', @@ -140,21 +141,21 @@ describe('getBlogPostAuthors', () => { it('can read authors string', () => { expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: 'slorber', }, authorsMap: {slorber: {name: 'Sébastien Lorber'}}, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([{key: 'slorber', name: 'Sébastien Lorber'}]); expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: 'slorber', }, @@ -166,9 +167,9 @@ describe('getBlogPostAuthors', () => { }, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([ { key: 'slorber', @@ -177,8 +178,8 @@ describe('getBlogPostAuthors', () => { }, ]); expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: 'slorber', }, @@ -190,9 +191,9 @@ describe('getBlogPostAuthors', () => { }, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([ { key: 'slorber', @@ -201,8 +202,8 @@ describe('getBlogPostAuthors', () => { }, ]); expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: 'slorber', }, @@ -214,9 +215,9 @@ describe('getBlogPostAuthors', () => { }, baseUrl: '/baseUrl', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([ { key: 'slorber', @@ -228,8 +229,8 @@ describe('getBlogPostAuthors', () => { it('can read authors string[]', () => { expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: ['slorber', 'yangshun'], }, @@ -239,9 +240,9 @@ describe('getBlogPostAuthors', () => { }, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([ {key: 'slorber', name: 'Sébastien Lorber', title: 'maintainer'}, {key: 'yangshun', name: 'Yangshun Tay'}, @@ -250,17 +251,17 @@ describe('getBlogPostAuthors', () => { it('can read authors Author', () => { expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: {name: 'Sébastien Lorber', title: 'maintainer'}, }, authorsMap: undefined, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([ { name: 'Sébastien Lorber', @@ -273,8 +274,8 @@ describe('getBlogPostAuthors', () => { it('can read authors Author[]', () => { expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: [ {name: 'Sébastien Lorber', title: 'maintainer'}, @@ -284,9 +285,9 @@ describe('getBlogPostAuthors', () => { authorsMap: undefined, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([ { name: 'Sébastien Lorber', @@ -304,8 +305,8 @@ describe('getBlogPostAuthors', () => { it('can read authors complex (string | Author)[] setup with keys and local overrides', () => { expect( - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: [ 'slorber', @@ -319,13 +320,16 @@ describe('getBlogPostAuthors', () => { }, authorsMap: { slorber: {name: 'Sébastien Lorber', title: 'maintainer'}, - yangshun: {name: 'Yangshun Tay', title: 'Yangshun title original'}, + yangshun: { + name: 'Yangshun Tay', + title: 'Yangshun title original', + }, }, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toEqual([ {key: 'slorber', name: 'Sébastien Lorber', title: 'maintainer'}, { @@ -341,17 +345,17 @@ describe('getBlogPostAuthors', () => { it('throw when using author key with no authorsMap', () => { expect(() => - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: 'slorber', }, authorsMap: undefined, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toThrowErrorMatchingInlineSnapshot(` "Can't reference blog post authors by a key (such as 'slorber') because no authors map file could be loaded. Please double-check your blog plugin config (in particular 'authorsMapPath'), ensure the file exists at the configured path, is not empty, and is valid!" @@ -360,17 +364,17 @@ describe('getBlogPostAuthors', () => { it('throw when using author key with empty authorsMap', () => { expect(() => - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: 'slorber', }, authorsMap: {}, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toThrowErrorMatchingInlineSnapshot(` "Can't reference blog post authors by a key (such as 'slorber') because no authors map file could be loaded. Please double-check your blog plugin config (in particular 'authorsMapPath'), ensure the file exists at the configured path, is not empty, and is valid!" @@ -379,8 +383,8 @@ describe('getBlogPostAuthors', () => { it('throw when using bad author key in string', () => { expect(() => - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: 'slorber', }, @@ -391,9 +395,9 @@ describe('getBlogPostAuthors', () => { }, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toThrowErrorMatchingInlineSnapshot(` "Blog author with key "slorber" not found in the authors map file. Valid author keys are: @@ -404,8 +408,8 @@ describe('getBlogPostAuthors', () => { it('throw when using bad author key in string[]', () => { expect(() => - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: ['yangshun', 'jmarcey', 'slorber'], }, @@ -416,9 +420,9 @@ describe('getBlogPostAuthors', () => { }, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toThrowErrorMatchingInlineSnapshot(` "Blog author with key "slorber" not found in the authors map file. Valid author keys are: @@ -429,8 +433,8 @@ describe('getBlogPostAuthors', () => { it('throw when using bad author key in Author[].key', () => { expect(() => - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: [{key: 'yangshun'}, {key: 'jmarcey'}, {key: 'slorber'}], }, @@ -441,9 +445,9 @@ describe('getBlogPostAuthors', () => { }, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toThrowErrorMatchingInlineSnapshot(` "Blog author with key "slorber" not found in the authors map file. Valid author keys are: @@ -454,8 +458,8 @@ describe('getBlogPostAuthors', () => { it('throw when mixing legacy/new authors front matter', () => { expect(() => - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: [{name: 'Sébastien Lorber'}], author: 'Yangshun Tay', @@ -463,17 +467,17 @@ describe('getBlogPostAuthors', () => { authorsMap: undefined, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toThrowErrorMatchingInlineSnapshot(` "To declare blog post authors, use the 'authors' front matter in priority. Don't mix 'authors' with other existing 'author_*' front matter. Choose one or the other, not both at the same time." `); expect(() => - getBlogPostAuthors( - { + getBlogPostAuthors({ + params: { frontMatter: { authors: [{key: 'slorber'}], author_title: 'legacy title', @@ -481,9 +485,9 @@ describe('getBlogPostAuthors', () => { authorsMap: {slorber: {name: 'Sébastien Lorber'}}, baseUrl: '/', }, - 'ignore', - '', - ), + options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, + blogSourceRelative: '', + }), ).toThrowErrorMatchingInlineSnapshot(` "To declare blog post authors, use the 'authors' front matter in priority. Don't mix 'authors' with other existing 'author_*' front matter. Choose one or the other, not both at the same time." @@ -642,39 +646,56 @@ describe('validateAuthorsMap', () => { }); }); +// TODO remove ozaki // bun run jest --watch -t "ozaki" describe('ozaki duplicate authors', () => { - it('no duplicate authors', () => { + const blogSourceRelative = 'doc.md'; + + it('basic duplicate authors', () => { const authors: Author[] = [ { name: 'Sébastien Lorber', - title: 'maintainer', + }, + { + name: 'Sébastien Lorber', }, ]; - const output = reportDuplicateAuthors({ - authors, - blogSourceRelative: '', - onInlineAuthors: 'throw', - }); - expect(output).toBeUndefined(); + expect(() => + reportDuplicateAuthors({ + authors, + blogSourceRelative, + onInlineAuthors: 'throw', + }), + ).toThrowErrorMatchingInlineSnapshot( + `"Duplicate authors found in blog post doc.md front matter: Sébastien Lorber"`, + ); }); }); +// TODO remove ozaki +// bun run jest --watch -t "ozaki" describe('ozaki inline authors', () => { - it('no inline authors', () => { + const authorsMap = 'authors.yml'; + const blogSourceRelative = 'doc.md'; + + it('basic inline authors', () => { const authors: Author[] = [ { name: 'Sébastien Lorber', title: 'maintainer', + inline: true, }, ]; - const output = reportInlineAuthors({ - onInlineAuthors: 'throw', - authors, - blogSourceRelative: '', - }); - expect(output).toBeUndefined(); + expect(() => + reportInlineAuthors({ + options: {authorsMapPath: authorsMap, onInlineAuthors: 'throw'}, + authors, + blogSourceRelative, + }), + ).toThrowErrorMatchingInlineSnapshot( + `"Authors used in doc.md are not defined in authors.yml"`, + ); }); }); diff --git a/packages/docusaurus-plugin-content-blog/src/authors.ts b/packages/docusaurus-plugin-content-blog/src/authors.ts index 6068fddf8084..1d81f9618c55 100644 --- a/packages/docusaurus-plugin-content-blog/src/authors.ts +++ b/packages/docusaurus-plugin-content-blog/src/authors.ts @@ -188,18 +188,21 @@ function fixAuthorImageBaseURL( export function reportInlineAuthors({ authors, blogSourceRelative, - onInlineAuthors, + options, }: { authors: Author[]; blogSourceRelative: string; - onInlineAuthors: ReportingSeverity; + options: {onInlineAuthors: ReportingSeverity; authorsMapPath: string}; }): void { + if (options.onInlineAuthors === 'ignore') { + return; + } + const inlineAuthors = authors.filter((author) => author.inline); - if (inlineAuthors.length > 0 && onInlineAuthors !== 'ignore') { - logger.report(onInlineAuthors)( - `Inline authors found in blog ${blogSourceRelative} ${inlineAuthors - .map((author) => author.name ?? author.imageURL) - .join(', ')}`, + + if (inlineAuthors.length > 0) { + logger.report(options.onInlineAuthors)( + `Authors used in ${blogSourceRelative} are not defined in ${options.authorsMapPath}`, ); } } @@ -213,24 +216,41 @@ export function reportDuplicateAuthors({ blogSourceRelative: string; onInlineAuthors: ReportingSeverity; }): void { - const duplicateList = authors.filter( - (author, index, self) => - index !== self.findIndex((t) => t.name === author.name), - ); + if (onInlineAuthors === 'ignore') { + return; + } + + const seen = new Set(); + const duplicateList = authors.filter(({name, email, imageURL}) => { + const identifier = name || email || imageURL; + if (!identifier) { + return false; + } + if (seen.has(identifier)) { + return true; + } + seen.add(identifier); + return false; + }); + if (duplicateList.length > 0) { logger.report(onInlineAuthors)( - `Duplicate authors found in blog post ${blogSourceRelative} front matter: ${duplicateList - .map((author) => author.name) + `Duplicate authors found in blog post ${blogSourceRelative} front matter: ${duplicateList + .map(({name, email, imageURL}) => name || email || imageURL) .join(', ')}`, ); } } -export function getBlogPostAuthors( - params: AuthorsParam, - onInlineAuthors: ReportingSeverity, - blogSourceRelative: string, -): Author[] { +export function getBlogPostAuthors({ + params, + options, + blogSourceRelative, +}: { + params: AuthorsParam; + options: {onInlineAuthors: ReportingSeverity; authorsMapPath: string}; + blogSourceRelative: string; +}): Author[] { const authorLegacy = getFrontMatterAuthorLegacy(params); const authors = getFrontMatterAuthors(params); @@ -251,13 +271,13 @@ Don't mix 'authors' with other existing 'author_*' front matter. Choose one or t reportInlineAuthors({ authors: updatedAuthors, blogSourceRelative, - onInlineAuthors, + options, }); reportDuplicateAuthors({ authors: updatedAuthors, blogSourceRelative, - onInlineAuthors, + onInlineAuthors: options.onInlineAuthors, }); return updatedAuthors; diff --git a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts index 967741229764..fe5f52c7e807 100644 --- a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts +++ b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts @@ -317,11 +317,14 @@ async function processBlogSourceFile( routeBasePath, tagsRouteBasePath, ]); - const authors = getBlogPostAuthors( - {authorsMap, frontMatter, baseUrl}, - options.onInlineAuthors, + const authors = getBlogPostAuthors({ + params: {authorsMap, frontMatter, baseUrl}, + options: { + onInlineAuthors: options.onInlineAuthors, + authorsMapPath: options.authorsMapPath, + }, blogSourceRelative, - ); + }); const tags = normalizeTags({ options, diff --git a/website/_dogfooding/dogfooding.config.ts b/website/_dogfooding/dogfooding.config.ts index 6d8bb062e256..241ba0744383 100644 --- a/website/_dogfooding/dogfooding.config.ts +++ b/website/_dogfooding/dogfooding.config.ts @@ -85,7 +85,7 @@ export const dogfoodingPluginInstances: PluginConfig[] = [ : defaultReadingTime({content, options: {wordsPerMinute: 5}}), onInlineTags: 'warn', tags: 'tags.yml', - onInlineAuthors: 'throw', + onInlineAuthors: 'warn', } satisfies BlogOptions, ], From 7f59a6ee0ec982a7be93d2e8b1317052f417d7c7 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Fri, 21 Jun 2024 17:28:42 +0200 Subject: [PATCH 06/22] feat: tests --- .../src/__tests__/authors.test.ts | 117 +++++++++++++++++- 1 file changed, 115 insertions(+), 2 deletions(-) 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 94fc2fe34d99..697e18ed0231 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts @@ -651,7 +651,7 @@ describe('validateAuthorsMap', () => { describe('ozaki duplicate authors', () => { const blogSourceRelative = 'doc.md'; - it('basic duplicate authors', () => { + it('one duplicated name authors', () => { const authors: Author[] = [ { name: 'Sébastien Lorber', @@ -671,6 +671,116 @@ describe('ozaki duplicate authors', () => { `"Duplicate authors found in blog post doc.md front matter: Sébastien Lorber"`, ); }); + + it('multiple duplicated name authors', () => { + const authors: Author[] = [ + { + name: 'Sébastien Lorber', + }, + { + name: 'Sébastien Lorber', + }, + { + name: 'Ozaki', + }, + { + name: 'Ozaki', + }, + ]; + + expect(() => + reportDuplicateAuthors({ + authors, + blogSourceRelative, + onInlineAuthors: 'throw', + }), + ).toThrowErrorMatchingInlineSnapshot( + `"Duplicate authors found in blog post doc.md front matter: Sébastien Lorber, Ozaki"`, + ); + }); + + it('multiple duplicated image authors', () => { + const authors: Author[] = [ + { + imageURL: 'https://github.com/slorber.png', + }, + { + imageURL: 'https://github.com/slorber.png', + }, + { + imageURL: 'https://github.com/ozakione.png', + }, + { + imageURL: 'https://github.com/ozakione.png', + }, + ]; + + expect(() => + reportDuplicateAuthors({ + authors, + blogSourceRelative, + onInlineAuthors: 'throw', + }), + ).toThrowErrorMatchingInlineSnapshot( + `"Duplicate authors found in blog post doc.md front matter: https://github.com/slorber.png, https://github.com/ozakione.png"`, + ); + }); + + it('multiple duplicated mixed authors', () => { + const authors: Author[] = [ + { + name: 'Sébastien', + imageURL: 'https://github.com/slorber.png', + }, + { + name: 'Lorber', + imageURL: 'https://github.com/slorber.png', + }, + { + name: 'Ozaki', + imageURL: 'https://github.com/ozakione.png', + }, + { + name: 'one', + imageURL: 'https://github.com/ozakione.png', + }, + ]; + + expect(() => + reportDuplicateAuthors({ + authors, + blogSourceRelative, + onInlineAuthors: 'throw', + }), + ).not.toThrow(); + }); + + it('multiple duplicated mixed authors 2', () => { + const authors: Author[] = [ + { + name: 'Sébastien', + imageURL: 'https://github.com/slorber.png', + }, + { + imageURL: 'https://github.com/slorber.png', + }, + { + name: 'Ozaki', + imageURL: 'https://github.com/ozakione.png', + }, + { + imageURL: 'https://github.com/ozakione.png', + }, + ]; + + expect(() => + reportDuplicateAuthors({ + authors, + blogSourceRelative, + onInlineAuthors: 'throw', + }), + ).not.toThrow(); + }); }); // TODO remove ozaki @@ -683,7 +793,10 @@ describe('ozaki inline authors', () => { const authors: Author[] = [ { name: 'Sébastien Lorber', - title: 'maintainer', + inline: true, + }, + { + imageURL: 'https://github.com/slorber.png', inline: true, }, ]; From 4e338122b791e205dd5518a67f7a54e0111db9d0 Mon Sep 17 00:00:00 2001 From: OzakIOne Date: Fri, 21 Jun 2024 15:33:15 +0000 Subject: [PATCH 07/22] refactor: apply lint autofix --- project-words.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/project-words.txt b/project-words.txt index 0125953ec975..bd919a614ff4 100644 --- a/project-words.txt +++ b/project-words.txt @@ -235,6 +235,7 @@ outerbounds Outerbounds overrideable ozaki +Ozaki pageview palenight Palenight From dde8cde698db993a4a2235ca46e2cf6d0fb0f90f Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Fri, 21 Jun 2024 17:58:08 +0200 Subject: [PATCH 08/22] ignore inline on duplicate check --- .../src/__tests__/authors.test.ts | 10 +++++----- packages/docusaurus-plugin-content-blog/src/authors.ts | 10 ++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) 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 697e18ed0231..6e84bd5013f4 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts @@ -681,10 +681,10 @@ describe('ozaki duplicate authors', () => { name: 'Sébastien Lorber', }, { - name: 'Ozaki', + name: 'ozaki', }, { - name: 'Ozaki', + name: 'ozaki', }, ]; @@ -695,7 +695,7 @@ describe('ozaki duplicate authors', () => { onInlineAuthors: 'throw', }), ).toThrowErrorMatchingInlineSnapshot( - `"Duplicate authors found in blog post doc.md front matter: Sébastien Lorber, Ozaki"`, + `"Duplicate authors found in blog post doc.md front matter: Sébastien Lorber, ozaki"`, ); }); @@ -737,7 +737,7 @@ describe('ozaki duplicate authors', () => { imageURL: 'https://github.com/slorber.png', }, { - name: 'Ozaki', + name: 'ozaki', imageURL: 'https://github.com/ozakione.png', }, { @@ -765,7 +765,7 @@ describe('ozaki duplicate authors', () => { imageURL: 'https://github.com/slorber.png', }, { - name: 'Ozaki', + name: 'ozaki', imageURL: 'https://github.com/ozakione.png', }, { diff --git a/packages/docusaurus-plugin-content-blog/src/authors.ts b/packages/docusaurus-plugin-content-blog/src/authors.ts index 1d81f9618c55..6269ea419bed 100644 --- a/packages/docusaurus-plugin-content-blog/src/authors.ts +++ b/packages/docusaurus-plugin-content-blog/src/authors.ts @@ -221,8 +221,10 @@ export function reportDuplicateAuthors({ } const seen = new Set(); - const duplicateList = authors.filter(({name, email, imageURL}) => { - const identifier = name || email || imageURL; + const duplicateList = authors.filter(({name, imageURL}) => { + // TODO check with the string that is used in the authors map + // TODO check with the key if author is overwriten + const identifier = name || imageURL; if (!identifier) { return false; } @@ -236,7 +238,7 @@ export function reportDuplicateAuthors({ if (duplicateList.length > 0) { logger.report(onInlineAuthors)( `Duplicate authors found in blog post ${blogSourceRelative} front matter: ${duplicateList - .map(({name, email, imageURL}) => name || email || imageURL) + .map(({name, imageURL}) => name || imageURL) .join(', ')}`, ); } @@ -275,7 +277,7 @@ Don't mix 'authors' with other existing 'author_*' front matter. Choose one or t }); reportDuplicateAuthors({ - authors: updatedAuthors, + authors: updatedAuthors.filter((author) => !author.inline), blogSourceRelative, onInlineAuthors: options.onInlineAuthors, }); From ea1d1b7f6768525ca0142eb276efa7eb9b4e32ce Mon Sep 17 00:00:00 2001 From: OzakIOne Date: Fri, 21 Jun 2024 16:02:51 +0000 Subject: [PATCH 09/22] refactor: apply lint autofix --- project-words.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project-words.txt b/project-words.txt index bd919a614ff4..6fa656558a0d 100644 --- a/project-words.txt +++ b/project-words.txt @@ -234,8 +234,8 @@ O’Shannessy outerbounds Outerbounds overrideable +overwriten ozaki -Ozaki pageview palenight Palenight From 4795cd05e6c197167d73bd089a7f657c4224f406 Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 26 Jun 2024 16:12:56 +0200 Subject: [PATCH 10/22] remove typo --- packages/docusaurus-plugin-content-blog/src/authors.ts | 2 +- project-words.txt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/authors.ts b/packages/docusaurus-plugin-content-blog/src/authors.ts index 6269ea419bed..43888d277e14 100644 --- a/packages/docusaurus-plugin-content-blog/src/authors.ts +++ b/packages/docusaurus-plugin-content-blog/src/authors.ts @@ -223,7 +223,7 @@ export function reportDuplicateAuthors({ const seen = new Set(); const duplicateList = authors.filter(({name, imageURL}) => { // TODO check with the string that is used in the authors map - // TODO check with the key if author is overwriten + // TODO check with the key if author is overwritten const identifier = name || imageURL; if (!identifier) { return false; diff --git a/project-words.txt b/project-words.txt index 6fa656558a0d..0125953ec975 100644 --- a/project-words.txt +++ b/project-words.txt @@ -234,7 +234,6 @@ O’Shannessy outerbounds Outerbounds overrideable -overwriten ozaki pageview palenight From 61d165f9eb70ac2563d4959a9fdc76445668b143 Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 26 Jun 2024 16:14:10 +0200 Subject: [PATCH 11/22] remove typo --- .../docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts | 2 +- packages/docusaurus-utils/src/tags.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index ff2d7cb1c9ce..dc9fba320b43 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -442,7 +442,7 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the * (filter, modify, delete, etc...). */ processBlogPosts: ProcessBlogPostsFn; - /** The behavior of Docusaurus when it found inline authors. */ + /** The behavior of Docusaurus when it finds inline authors. */ onInlineAuthors: 'ignore' | 'log' | 'warn' | 'throw'; }; diff --git a/packages/docusaurus-utils/src/tags.ts b/packages/docusaurus-utils/src/tags.ts index 1da758f9cd5d..fd06bf2fea25 100644 --- a/packages/docusaurus-utils/src/tags.ts +++ b/packages/docusaurus-utils/src/tags.ts @@ -28,7 +28,7 @@ export type TagsPluginOptions = { // TODO allow option tags later? | TagsFile; /** Path to the tags file. */ tags: string | false | null | undefined; - /** The behavior of Docusaurus when it found inline tags. */ + /** The behavior of Docusaurus when it finds inline tags. */ onInlineTags: 'ignore' | 'log' | 'warn' | 'throw'; }; From aff176cb9f9e8fecfddb1771d632161d65bf46b7 Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 26 Jun 2024 16:49:58 +0200 Subject: [PATCH 12/22] refactor authors duplicate algo --- .../src/authors.ts | 122 ++++++++---------- .../src/blogUtils.ts | 18 ++- .../src/plugin-content-blog.d.ts | 2 + 3 files changed, 68 insertions(+), 74 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/authors.ts b/packages/docusaurus-plugin-content-blog/src/authors.ts index 43888d277e14..b7abe6cf22b3 100644 --- a/packages/docusaurus-plugin-content-blog/src/authors.ts +++ b/packages/docusaurus-plugin-content-blog/src/authors.ts @@ -5,16 +5,17 @@ * LICENSE file in the root directory of this source tree. */ +import _ from 'lodash'; import {getDataFileData, normalizeUrl} from '@docusaurus/utils'; import {Joi, URISchema} from '@docusaurus/utils-validation'; import logger from '@docusaurus/logger'; -import type {ReportingSeverity} from '@docusaurus/types'; import type {BlogContentPaths} from './types'; import type { Author, BlogPostFrontMatter, BlogPostFrontMatterAuthor, BlogPostFrontMatterAuthors, + PluginOptions, } from '@docusaurus/plugin-content-blog'; export type AuthorsMap = {[authorKey: string]: Author}; @@ -128,7 +129,6 @@ function normalizeFrontMatterAuthors( } else if (typeof authorInput === 'object' && !('key' in authorInput)) { return { ...authorInput, - inline: true, }; } return authorInput; @@ -159,7 +159,7 @@ ${Object.keys(authorsMap) .map((validKey) => `- ${validKey}`) .join('\n')}`); } - return author; + return {...author, key}; } return undefined; } @@ -185,74 +185,74 @@ function fixAuthorImageBaseURL( })); } -export function reportInlineAuthors({ +export function reportAuthorsProblems({ authors, blogSourceRelative, - options, + options: {onInlineAuthors, authorsMapPath}, }: { authors: Author[]; blogSourceRelative: string; - options: {onInlineAuthors: ReportingSeverity; authorsMapPath: string}; + options: Pick; }): void { - if (options.onInlineAuthors === 'ignore') { - return; + reportInlineAuthors(); + reportDuplicateAuthors(); + + function reportInlineAuthors(): void { + if (onInlineAuthors === 'ignore') { + return; + } + const inlineAuthors = authors.filter((author) => author.inline); + if (inlineAuthors.length > 0) { + logger.report(onInlineAuthors)( + `Authors used in ${blogSourceRelative} are not defined in ${authorsMapPath}`, + ); + } } - const inlineAuthors = authors.filter((author) => author.inline); + function reportDuplicateAuthors(): void { + if (onInlineAuthors === 'ignore') { + return; + } - if (inlineAuthors.length > 0) { - logger.report(options.onInlineAuthors)( - `Authors used in ${blogSourceRelative} are not defined in ${options.authorsMapPath}`, - ); - } -} + const result = _(authors) + // for now we only check for predefined authors duplicates + .filter((author) => !!author.key) + .groupBy((author) => author.key) + .pickBy((authorsByKey) => authorsByKey.length > 1) + .flatMap((authorsByKey) => [authorsByKey[0]!]) + .value(); -export function reportDuplicateAuthors({ - authors, - blogSourceRelative, - onInlineAuthors, -}: { - authors: Author[]; - blogSourceRelative: string; - onInlineAuthors: ReportingSeverity; -}): void { - if (onInlineAuthors === 'ignore') { - return; - } + console.log({result}); + + // for now we only check for predefined authors duplicates + const predefinedAuthors = authors.filter((author) => !author.inline); - const seen = new Set(); - const duplicateList = authors.filter(({name, imageURL}) => { - // TODO check with the string that is used in the authors map - // TODO check with the key if author is overwritten - const identifier = name || imageURL; - if (!identifier) { + const seen = new Set(); + const duplicateList = predefinedAuthors.filter(({name, imageURL}) => { + // TODO check with the string that is used in the authors map + // TODO check with the key if author is overwritten + const identifier = name || imageURL; + if (!identifier) { + return false; + } + if (seen.has(identifier)) { + return true; + } + seen.add(identifier); return false; - } - if (seen.has(identifier)) { - return true; - } - seen.add(identifier); - return false; - }); + }); - if (duplicateList.length > 0) { - logger.report(onInlineAuthors)( - `Duplicate authors found in blog post ${blogSourceRelative} front matter: ${duplicateList - .map(({name, imageURL}) => name || imageURL) - .join(', ')}`, - ); + if (duplicateList.length > 0) { + logger.report(onInlineAuthors)( + `Duplicate authors found in blog post ${blogSourceRelative} front matter: ${duplicateList + .map(({name, imageURL}) => name || imageURL) + .join(', ')}`, + ); + } } } -export function getBlogPostAuthors({ - params, - options, - blogSourceRelative, -}: { - params: AuthorsParam; - options: {onInlineAuthors: ReportingSeverity; authorsMapPath: string}; - blogSourceRelative: string; -}): Author[] { +export function getBlogPostAuthors(params: AuthorsParam): Author[] { const authorLegacy = getFrontMatterAuthorLegacy(params); const authors = getFrontMatterAuthors(params); @@ -270,17 +270,5 @@ Don't mix 'authors' with other existing 'author_*' front matter. Choose one or t return [authorLegacy]; } - reportInlineAuthors({ - authors: updatedAuthors, - blogSourceRelative, - options, - }); - - reportDuplicateAuthors({ - authors: updatedAuthors.filter((author) => !author.inline), - blogSourceRelative, - onInlineAuthors: options.onInlineAuthors, - }); - return updatedAuthors; } diff --git a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts index fe5f52c7e807..b158533832fe 100644 --- a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts +++ b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts @@ -29,7 +29,12 @@ import { } from '@docusaurus/utils'; import {getTagsFile} from '@docusaurus/utils-validation'; import {validateBlogPostFrontMatter} from './frontMatter'; -import {type AuthorsMap, getAuthorsMap, getBlogPostAuthors} from './authors'; +import { + type AuthorsMap, + getAuthorsMap, + getBlogPostAuthors, + reportAuthorsProblems, +} from './authors'; import type {TagsFile} from '@docusaurus/utils'; import type {LoadContext, ParseFrontMatter} from '@docusaurus/types'; import type { @@ -317,13 +322,12 @@ async function processBlogSourceFile( routeBasePath, tagsRouteBasePath, ]); - const authors = getBlogPostAuthors({ - params: {authorsMap, frontMatter, baseUrl}, - options: { - onInlineAuthors: options.onInlineAuthors, - authorsMapPath: options.authorsMapPath, - }, + + const authors = getBlogPostAuthors({authorsMap, frontMatter, baseUrl}); + reportAuthorsProblems({ + authors, blogSourceRelative, + options, }); const tags = normalizeTags({ diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index dc9fba320b43..d3dbb699ec48 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -44,6 +44,8 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the }; export type Author = { + key?: string; // TODO temporary, need refactor + /** * If `name` doesn't exist, an `imageURL` is expected. */ From 534a7e9700c6c1cb784c8eb14afca8faff3f1545 Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 26 Jun 2024 16:52:50 +0200 Subject: [PATCH 13/22] remove inline attribute in favor of key --- packages/docusaurus-plugin-content-blog/src/authors.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/authors.ts b/packages/docusaurus-plugin-content-blog/src/authors.ts index b7abe6cf22b3..b07f71ec26e3 100644 --- a/packages/docusaurus-plugin-content-blog/src/authors.ts +++ b/packages/docusaurus-plugin-content-blog/src/authors.ts @@ -126,10 +126,6 @@ function normalizeFrontMatterAuthors( // we only support keys, otherwise, a typo in a key would fallback to // becoming a name and may end up unnoticed return {key: authorInput}; - } else if (typeof authorInput === 'object' && !('key' in authorInput)) { - return { - ...authorInput, - }; } return authorInput; } @@ -201,7 +197,7 @@ export function reportAuthorsProblems({ if (onInlineAuthors === 'ignore') { return; } - const inlineAuthors = authors.filter((author) => author.inline); + const inlineAuthors = authors.filter((author) => !author.key); if (inlineAuthors.length > 0) { logger.report(onInlineAuthors)( `Authors used in ${blogSourceRelative} are not defined in ${authorsMapPath}`, @@ -225,7 +221,7 @@ export function reportAuthorsProblems({ console.log({result}); // for now we only check for predefined authors duplicates - const predefinedAuthors = authors.filter((author) => !author.inline); + const predefinedAuthors = authors.filter((author) => !!author.key); const seen = new Set(); const duplicateList = predefinedAuthors.filter(({name, imageURL}) => { From 564f2b521ef3d6b9ff8f45270a4bb6d185a47344 Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 26 Jun 2024 18:44:43 +0200 Subject: [PATCH 14/22] extract and refactor logic to authorsProblems.ts --- .../src/__tests__/authors.test.ts | 546 +++++------------- .../src/__tests__/authorsProblems.test.ts | 133 +++++ .../src/authors.ts | 72 +-- .../src/authorsProblems.ts | 60 ++ 4 files changed, 334 insertions(+), 477 deletions(-) create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/authorsProblems.test.ts create mode 100644 packages/docusaurus-plugin-content-blog/src/authorsProblems.ts 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 6e84bd5013f4..d67f5dc41024 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts @@ -5,41 +5,30 @@ * LICENSE file in the root directory of this source tree. */ -import path from 'path'; +import * as path from 'path'; import { type AuthorsMap, getAuthorsMap, getBlogPostAuthors, validateAuthorsMap, - reportDuplicateAuthors, - reportInlineAuthors, } from '../authors'; -import type {Author} from '@docusaurus/plugin-content-blog'; describe('getBlogPostAuthors', () => { it('can read no authors', () => { expect( getBlogPostAuthors({ - params: { - frontMatter: {}, - authorsMap: undefined, - baseUrl: '/', - }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + frontMatter: {}, + authorsMap: undefined, + baseUrl: '/', }), ).toEqual([]); expect( getBlogPostAuthors({ - params: { - frontMatter: { - authors: [], - }, - authorsMap: undefined, - baseUrl: '/', + frontMatter: { + authors: [], }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + authorsMap: undefined, + baseUrl: '/', }), ).toEqual([]); }); @@ -47,87 +36,62 @@ describe('getBlogPostAuthors', () => { it('can read author from legacy front matter', () => { expect( getBlogPostAuthors({ - params: { - frontMatter: { - author: 'Sébastien Lorber', - }, - authorsMap: undefined, - baseUrl: '/', + frontMatter: { + author: 'Sébastien Lorber', }, - - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + authorsMap: undefined, + baseUrl: '/', }), ).toEqual([{name: 'Sébastien Lorber'}]); expect( getBlogPostAuthors({ - params: { - frontMatter: { - authorTitle: 'maintainer', - }, - authorsMap: undefined, - baseUrl: '/', + frontMatter: { + authorTitle: 'maintainer', }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + authorsMap: undefined, + baseUrl: '/', }), ).toEqual([{title: 'maintainer'}]); expect( getBlogPostAuthors({ - params: { - frontMatter: { - authorImageURL: 'https://github.com/slorber.png', - }, - authorsMap: undefined, - baseUrl: '/', + frontMatter: { + authorImageURL: 'https://github.com/slorber.png', }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + authorsMap: undefined, + baseUrl: '/', }), ).toEqual([{imageURL: 'https://github.com/slorber.png'}]); expect( getBlogPostAuthors({ - params: { - frontMatter: { - authorImageURL: '/img/slorber.png', - }, - authorsMap: undefined, - baseUrl: '/', + frontMatter: { + authorImageURL: '/img/slorber.png', }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + authorsMap: undefined, + baseUrl: '/', }), ).toEqual([{imageURL: '/img/slorber.png'}]); expect( getBlogPostAuthors({ - params: { - frontMatter: { - authorImageURL: '/img/slorber.png', - }, - authorsMap: undefined, - baseUrl: '/baseURL', + frontMatter: { + authorImageURL: '/img/slorber.png', }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + authorsMap: undefined, + baseUrl: '/baseURL', }), ).toEqual([{imageURL: '/baseURL/img/slorber.png'}]); expect( getBlogPostAuthors({ - params: { - frontMatter: { - author: 'Sébastien Lorber', - author_title: 'maintainer1', - authorTitle: 'maintainer2', - author_image_url: 'https://github.com/slorber1.png', - authorImageURL: 'https://github.com/slorber2.png', - author_url: 'https://github.com/slorber1', - authorURL: 'https://github.com/slorber2', - }, - authorsMap: undefined, - baseUrl: '/', + frontMatter: { + author: 'Sébastien Lorber', + author_title: 'maintainer1', + authorTitle: 'maintainer2', + author_image_url: 'https://github.com/slorber1.png', + authorImageURL: 'https://github.com/slorber2.png', + author_url: 'https://github.com/slorber1', + authorURL: 'https://github.com/slorber2', }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + authorsMap: undefined, + baseUrl: '/', }), ).toEqual([ { @@ -142,33 +106,25 @@ describe('getBlogPostAuthors', () => { it('can read authors string', () => { expect( getBlogPostAuthors({ - params: { - frontMatter: { - authors: 'slorber', - }, - authorsMap: {slorber: {name: 'Sébastien Lorber'}}, - baseUrl: '/', + frontMatter: { + authors: 'slorber', }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + authorsMap: {slorber: {name: 'Sébastien Lorber'}}, + baseUrl: '/', }), ).toEqual([{key: 'slorber', name: 'Sébastien Lorber'}]); expect( getBlogPostAuthors({ - params: { - frontMatter: { - authors: 'slorber', - }, - authorsMap: { - slorber: { - name: 'Sébastien Lorber', - imageURL: 'https://github.com/slorber.png', - }, + frontMatter: { + authors: 'slorber', + }, + authorsMap: { + slorber: { + name: 'Sébastien Lorber', + imageURL: 'https://github.com/slorber.png', }, - baseUrl: '/', }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + baseUrl: '/', }), ).toEqual([ { @@ -179,20 +135,16 @@ describe('getBlogPostAuthors', () => { ]); expect( getBlogPostAuthors({ - params: { - frontMatter: { - authors: 'slorber', - }, - authorsMap: { - slorber: { - name: 'Sébastien Lorber', - imageURL: '/img/slorber.png', - }, + frontMatter: { + authors: 'slorber', + }, + authorsMap: { + slorber: { + name: 'Sébastien Lorber', + imageURL: '/img/slorber.png', }, - baseUrl: '/', }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + baseUrl: '/', }), ).toEqual([ { @@ -203,20 +155,16 @@ describe('getBlogPostAuthors', () => { ]); expect( getBlogPostAuthors({ - params: { - frontMatter: { - authors: 'slorber', - }, - authorsMap: { - slorber: { - name: 'Sébastien Lorber', - imageURL: '/img/slorber.png', - }, + frontMatter: { + authors: 'slorber', + }, + authorsMap: { + slorber: { + name: 'Sébastien Lorber', + imageURL: '/img/slorber.png', }, - baseUrl: '/baseUrl', }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + baseUrl: '/baseUrl', }), ).toEqual([ { @@ -230,18 +178,14 @@ describe('getBlogPostAuthors', () => { it('can read authors string[]', () => { expect( getBlogPostAuthors({ - params: { - frontMatter: { - authors: ['slorber', 'yangshun'], - }, - authorsMap: { - slorber: {name: 'Sébastien Lorber', title: 'maintainer'}, - yangshun: {name: 'Yangshun Tay'}, - }, - baseUrl: '/', + frontMatter: { + authors: ['slorber', 'yangshun'], + }, + authorsMap: { + slorber: {name: 'Sébastien Lorber', title: 'maintainer'}, + yangshun: {name: 'Yangshun Tay'}, }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + baseUrl: '/', }), ).toEqual([ {key: 'slorber', name: 'Sébastien Lorber', title: 'maintainer'}, @@ -252,22 +196,17 @@ describe('getBlogPostAuthors', () => { it('can read authors Author', () => { expect( getBlogPostAuthors({ - params: { - frontMatter: { - authors: {name: 'Sébastien Lorber', title: 'maintainer'}, - }, - authorsMap: undefined, - baseUrl: '/', + frontMatter: { + authors: {name: 'Sébastien Lorber', title: 'maintainer'}, }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + authorsMap: undefined, + baseUrl: '/', }), ).toEqual([ { name: 'Sébastien Lorber', title: 'maintainer', imageURL: undefined, - inline: true, }, ]); }); @@ -275,30 +214,24 @@ describe('getBlogPostAuthors', () => { it('can read authors Author[]', () => { expect( getBlogPostAuthors({ - params: { - frontMatter: { - authors: [ - {name: 'Sébastien Lorber', title: 'maintainer'}, - {name: 'Yangshun Tay'}, - ], - }, - authorsMap: undefined, - baseUrl: '/', + frontMatter: { + authors: [ + {name: 'Sébastien Lorber', title: 'maintainer'}, + {name: 'Yangshun Tay'}, + ], }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + authorsMap: undefined, + baseUrl: '/', }), ).toEqual([ { name: 'Sébastien Lorber', title: 'maintainer', imageURL: undefined, - inline: true, }, { name: 'Yangshun Tay', imageURL: undefined, - inline: true, }, ]); }); @@ -306,29 +239,25 @@ describe('getBlogPostAuthors', () => { it('can read authors complex (string | Author)[] setup with keys and local overrides', () => { expect( getBlogPostAuthors({ - params: { - frontMatter: { - authors: [ - 'slorber', - { - key: 'yangshun', - title: 'Yangshun title local override', - extra: 42, - }, - {name: 'Alexey'}, - ], - }, - authorsMap: { - slorber: {name: 'Sébastien Lorber', title: 'maintainer'}, - yangshun: { - name: 'Yangshun Tay', - title: 'Yangshun title original', + frontMatter: { + authors: [ + 'slorber', + { + key: 'yangshun', + title: 'Yangshun title local override', + extra: 42, }, + {name: 'Alexey'}, + ], + }, + authorsMap: { + slorber: {name: 'Sébastien Lorber', title: 'maintainer'}, + yangshun: { + name: 'Yangshun Tay', + title: 'Yangshun title original', }, - baseUrl: '/', }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + baseUrl: '/', }), ).toEqual([ {key: 'slorber', name: 'Sébastien Lorber', title: 'maintainer'}, @@ -339,22 +268,18 @@ describe('getBlogPostAuthors', () => { extra: 42, imageURL: undefined, }, - {name: 'Alexey', inline: true, imageURL: undefined}, + {name: 'Alexey', imageURL: undefined}, ]); }); it('throw when using author key with no authorsMap', () => { expect(() => getBlogPostAuthors({ - params: { - frontMatter: { - authors: 'slorber', - }, - authorsMap: undefined, - baseUrl: '/', + frontMatter: { + authors: 'slorber', }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + authorsMap: undefined, + baseUrl: '/', }), ).toThrowErrorMatchingInlineSnapshot(` "Can't reference blog post authors by a key (such as 'slorber') because no authors map file could be loaded. @@ -365,15 +290,11 @@ describe('getBlogPostAuthors', () => { it('throw when using author key with empty authorsMap', () => { expect(() => getBlogPostAuthors({ - params: { - frontMatter: { - authors: 'slorber', - }, - authorsMap: {}, - baseUrl: '/', + frontMatter: { + authors: 'slorber', }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + authorsMap: {}, + baseUrl: '/', }), ).toThrowErrorMatchingInlineSnapshot(` "Can't reference blog post authors by a key (such as 'slorber') because no authors map file could be loaded. @@ -384,19 +305,15 @@ describe('getBlogPostAuthors', () => { it('throw when using bad author key in string', () => { expect(() => getBlogPostAuthors({ - params: { - frontMatter: { - authors: 'slorber', - }, + frontMatter: { + authors: 'slorber', + }, - authorsMap: { - yangshun: {name: 'Yangshun Tay'}, - jmarcey: {name: 'Joel Marcey'}, - }, - baseUrl: '/', + authorsMap: { + yangshun: {name: 'Yangshun Tay'}, + jmarcey: {name: 'Joel Marcey'}, }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + baseUrl: '/', }), ).toThrowErrorMatchingInlineSnapshot(` "Blog author with key "slorber" not found in the authors map file. @@ -409,19 +326,15 @@ describe('getBlogPostAuthors', () => { it('throw when using bad author key in string[]', () => { expect(() => getBlogPostAuthors({ - params: { - frontMatter: { - authors: ['yangshun', 'jmarcey', 'slorber'], - }, + frontMatter: { + authors: ['yangshun', 'jmarcey', 'slorber'], + }, - authorsMap: { - yangshun: {name: 'Yangshun Tay'}, - jmarcey: {name: 'Joel Marcey'}, - }, - baseUrl: '/', + authorsMap: { + yangshun: {name: 'Yangshun Tay'}, + jmarcey: {name: 'Joel Marcey'}, }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + baseUrl: '/', }), ).toThrowErrorMatchingInlineSnapshot(` "Blog author with key "slorber" not found in the authors map file. @@ -434,19 +347,15 @@ describe('getBlogPostAuthors', () => { it('throw when using bad author key in Author[].key', () => { expect(() => getBlogPostAuthors({ - params: { - frontMatter: { - authors: [{key: 'yangshun'}, {key: 'jmarcey'}, {key: 'slorber'}], - }, + frontMatter: { + authors: [{key: 'yangshun'}, {key: 'jmarcey'}, {key: 'slorber'}], + }, - authorsMap: { - yangshun: {name: 'Yangshun Tay'}, - jmarcey: {name: 'Joel Marcey'}, - }, - baseUrl: '/', + authorsMap: { + yangshun: {name: 'Yangshun Tay'}, + jmarcey: {name: 'Joel Marcey'}, }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + baseUrl: '/', }), ).toThrowErrorMatchingInlineSnapshot(` "Blog author with key "slorber" not found in the authors map file. @@ -459,16 +368,12 @@ describe('getBlogPostAuthors', () => { it('throw when mixing legacy/new authors front matter', () => { expect(() => getBlogPostAuthors({ - params: { - frontMatter: { - authors: [{name: 'Sébastien Lorber'}], - author: 'Yangshun Tay', - }, - authorsMap: undefined, - baseUrl: '/', + frontMatter: { + authors: [{name: 'Sébastien Lorber'}], + author: 'Yangshun Tay', }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + authorsMap: undefined, + baseUrl: '/', }), ).toThrowErrorMatchingInlineSnapshot(` "To declare blog post authors, use the 'authors' front matter in priority. @@ -477,16 +382,12 @@ describe('getBlogPostAuthors', () => { expect(() => getBlogPostAuthors({ - params: { - frontMatter: { - authors: [{key: 'slorber'}], - author_title: 'legacy title', - }, - authorsMap: {slorber: {name: 'Sébastien Lorber'}}, - baseUrl: '/', + frontMatter: { + authors: [{key: 'slorber'}], + author_title: 'legacy title', }, - options: {onInlineAuthors: 'ignore', authorsMapPath: ''}, - blogSourceRelative: '', + authorsMap: {slorber: {name: 'Sébastien Lorber'}}, + baseUrl: '/', }), ).toThrowErrorMatchingInlineSnapshot(` "To declare blog post authors, use the 'authors' front matter in priority. @@ -645,170 +546,3 @@ describe('validateAuthorsMap', () => { ); }); }); - -// TODO remove ozaki -// bun run jest --watch -t "ozaki" -describe('ozaki duplicate authors', () => { - const blogSourceRelative = 'doc.md'; - - it('one duplicated name authors', () => { - const authors: Author[] = [ - { - name: 'Sébastien Lorber', - }, - { - name: 'Sébastien Lorber', - }, - ]; - - expect(() => - reportDuplicateAuthors({ - authors, - blogSourceRelative, - onInlineAuthors: 'throw', - }), - ).toThrowErrorMatchingInlineSnapshot( - `"Duplicate authors found in blog post doc.md front matter: Sébastien Lorber"`, - ); - }); - - it('multiple duplicated name authors', () => { - const authors: Author[] = [ - { - name: 'Sébastien Lorber', - }, - { - name: 'Sébastien Lorber', - }, - { - name: 'ozaki', - }, - { - name: 'ozaki', - }, - ]; - - expect(() => - reportDuplicateAuthors({ - authors, - blogSourceRelative, - onInlineAuthors: 'throw', - }), - ).toThrowErrorMatchingInlineSnapshot( - `"Duplicate authors found in blog post doc.md front matter: Sébastien Lorber, ozaki"`, - ); - }); - - it('multiple duplicated image authors', () => { - const authors: Author[] = [ - { - imageURL: 'https://github.com/slorber.png', - }, - { - imageURL: 'https://github.com/slorber.png', - }, - { - imageURL: 'https://github.com/ozakione.png', - }, - { - imageURL: 'https://github.com/ozakione.png', - }, - ]; - - expect(() => - reportDuplicateAuthors({ - authors, - blogSourceRelative, - onInlineAuthors: 'throw', - }), - ).toThrowErrorMatchingInlineSnapshot( - `"Duplicate authors found in blog post doc.md front matter: https://github.com/slorber.png, https://github.com/ozakione.png"`, - ); - }); - - it('multiple duplicated mixed authors', () => { - const authors: Author[] = [ - { - name: 'Sébastien', - imageURL: 'https://github.com/slorber.png', - }, - { - name: 'Lorber', - imageURL: 'https://github.com/slorber.png', - }, - { - name: 'ozaki', - imageURL: 'https://github.com/ozakione.png', - }, - { - name: 'one', - imageURL: 'https://github.com/ozakione.png', - }, - ]; - - expect(() => - reportDuplicateAuthors({ - authors, - blogSourceRelative, - onInlineAuthors: 'throw', - }), - ).not.toThrow(); - }); - - it('multiple duplicated mixed authors 2', () => { - const authors: Author[] = [ - { - name: 'Sébastien', - imageURL: 'https://github.com/slorber.png', - }, - { - imageURL: 'https://github.com/slorber.png', - }, - { - name: 'ozaki', - imageURL: 'https://github.com/ozakione.png', - }, - { - imageURL: 'https://github.com/ozakione.png', - }, - ]; - - expect(() => - reportDuplicateAuthors({ - authors, - blogSourceRelative, - onInlineAuthors: 'throw', - }), - ).not.toThrow(); - }); -}); - -// TODO remove ozaki -// bun run jest --watch -t "ozaki" -describe('ozaki inline authors', () => { - const authorsMap = 'authors.yml'; - const blogSourceRelative = 'doc.md'; - - it('basic inline authors', () => { - const authors: Author[] = [ - { - name: 'Sébastien Lorber', - inline: true, - }, - { - imageURL: 'https://github.com/slorber.png', - inline: true, - }, - ]; - - expect(() => - reportInlineAuthors({ - options: {authorsMapPath: authorsMap, onInlineAuthors: 'throw'}, - authors, - blogSourceRelative, - }), - ).toThrowErrorMatchingInlineSnapshot( - `"Authors used in doc.md are not defined in authors.yml"`, - ); - }); -}); diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/authorsProblems.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/authorsProblems.test.ts new file mode 100644 index 000000000000..b9718ce85fd7 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/authorsProblems.test.ts @@ -0,0 +1,133 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import {reportAuthorsProblems} from '../authorsProblems'; +import type {Author} from '@docusaurus/plugin-content-blog'; + +describe('reportAuthorsProblems', () => { + const blogSourceRelative = 'doc.md'; + + type Options = Parameters[0]['options']; + + describe('duplicate authors', () => { + const options: Options = { + onInlineAuthors: 'ignore', + authorsMapPath: 'authors.yml', + }; + + function testReport({authors}: {authors: Author[]}) { + reportAuthorsProblems({ + authors, + options, + blogSourceRelative, + }); + } + + it('allows duplicated inline authors', () => { + const authors: Author[] = [ + { + name: 'Sébastien Lorber', + }, + { + name: 'Sébastien Lorber', + }, + ]; + + expect(() => + testReport({ + authors, + }), + ).not.toThrow(); + }); + + it('rejects duplicated key authors', () => { + const authors: Author[] = [ + { + key: 'slorber', + name: 'Sébastien Lorber 1', + title: 'some title', + }, + { + key: 'slorber', + name: 'Sébastien Lorber 2', + imageURL: '/slorber.png', + }, + ]; + + expect(() => + testReport({ + authors, + }), + ).toThrowErrorMatchingInlineSnapshot(` + "Duplicate blog authors found in blog post doc.md front matter: + - {"key":"slorber","name":"Sébastien Lorber 2","imageURL":"/slorber.png"}" + `); + }); + }); + + describe('inline authors', () => { + const options: Options = { + onInlineAuthors: 'throw', + authorsMapPath: 'authors.yml', + }; + + function testReport({authors}: {authors: Author[]}) { + reportAuthorsProblems({ + authors, + options, + blogSourceRelative, + }); + } + + it('allows predefined authors', () => { + const authors: Author[] = [ + { + key: 'slorber', + name: 'Sébastien Lorber', + }, + { + key: 'ozaki', + name: 'Clément Couriol', + }, + ]; + + expect(() => + testReport({ + authors, + }), + ).not.toThrow(); + }); + + it('rejects inline authors', () => { + const authors: Author[] = [ + { + key: 'slorber', + name: 'Sébastien Lorber', + }, + {name: 'Inline author 1'}, + { + key: 'ozaki', + name: 'Clément Couriol', + }, + {imageURL: '/inline-author2.png'}, + ]; + + expect(() => + testReport({ + authors, + }), + ).toThrowErrorMatchingInlineSnapshot(` + "Some blog authors used in doc.md are not defined in authors.yml: + - {"name":"Inline author 1"} + - {"imageURL":"/inline-author2.png"} + + Note: if you want to allow inline blog authors, ignore this warning by setting onInlineAuthors: 'ignore' in your blog plugin options. + " + `); + }); + }); +}); diff --git a/packages/docusaurus-plugin-content-blog/src/authors.ts b/packages/docusaurus-plugin-content-blog/src/authors.ts index b07f71ec26e3..d114f48acfd2 100644 --- a/packages/docusaurus-plugin-content-blog/src/authors.ts +++ b/packages/docusaurus-plugin-content-blog/src/authors.ts @@ -5,17 +5,14 @@ * LICENSE file in the root directory of this source tree. */ -import _ from 'lodash'; import {getDataFileData, normalizeUrl} from '@docusaurus/utils'; import {Joi, URISchema} from '@docusaurus/utils-validation'; -import logger from '@docusaurus/logger'; import type {BlogContentPaths} from './types'; import type { Author, BlogPostFrontMatter, BlogPostFrontMatterAuthor, BlogPostFrontMatterAuthors, - PluginOptions, } from '@docusaurus/plugin-content-blog'; export type AuthorsMap = {[authorKey: string]: Author}; @@ -155,7 +152,7 @@ ${Object.keys(authorsMap) .map((validKey) => `- ${validKey}`) .join('\n')}`); } - return {...author, key}; + return author; } return undefined; } @@ -181,73 +178,6 @@ function fixAuthorImageBaseURL( })); } -export function reportAuthorsProblems({ - authors, - blogSourceRelative, - options: {onInlineAuthors, authorsMapPath}, -}: { - authors: Author[]; - blogSourceRelative: string; - options: Pick; -}): void { - reportInlineAuthors(); - reportDuplicateAuthors(); - - function reportInlineAuthors(): void { - if (onInlineAuthors === 'ignore') { - return; - } - const inlineAuthors = authors.filter((author) => !author.key); - if (inlineAuthors.length > 0) { - logger.report(onInlineAuthors)( - `Authors used in ${blogSourceRelative} are not defined in ${authorsMapPath}`, - ); - } - } - - function reportDuplicateAuthors(): void { - if (onInlineAuthors === 'ignore') { - return; - } - - const result = _(authors) - // for now we only check for predefined authors duplicates - .filter((author) => !!author.key) - .groupBy((author) => author.key) - .pickBy((authorsByKey) => authorsByKey.length > 1) - .flatMap((authorsByKey) => [authorsByKey[0]!]) - .value(); - - console.log({result}); - - // for now we only check for predefined authors duplicates - const predefinedAuthors = authors.filter((author) => !!author.key); - - const seen = new Set(); - const duplicateList = predefinedAuthors.filter(({name, imageURL}) => { - // TODO check with the string that is used in the authors map - // TODO check with the key if author is overwritten - const identifier = name || imageURL; - if (!identifier) { - return false; - } - if (seen.has(identifier)) { - return true; - } - seen.add(identifier); - return false; - }); - - if (duplicateList.length > 0) { - logger.report(onInlineAuthors)( - `Duplicate authors found in blog post ${blogSourceRelative} front matter: ${duplicateList - .map(({name, imageURL}) => name || imageURL) - .join(', ')}`, - ); - } - } -} - export function getBlogPostAuthors(params: AuthorsParam): Author[] { const authorLegacy = getFrontMatterAuthorLegacy(params); const authors = getFrontMatterAuthors(params); diff --git a/packages/docusaurus-plugin-content-blog/src/authorsProblems.ts b/packages/docusaurus-plugin-content-blog/src/authorsProblems.ts new file mode 100644 index 000000000000..53b599ab0895 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/authorsProblems.ts @@ -0,0 +1,60 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import _ from 'lodash'; +import logger from '@docusaurus/logger'; +import type {Author, PluginOptions} from '@docusaurus/plugin-content-blog'; + +export function reportAuthorsProblems({ + authors, + blogSourceRelative, + options: {onInlineAuthors, authorsMapPath}, +}: { + authors: Author[]; + blogSourceRelative: string; + options: Pick; +}): void { + reportInlineAuthors(); + reportDuplicateAuthors(); + + function reportInlineAuthors(): void { + if (onInlineAuthors === 'ignore') { + return; + } + const inlineAuthors = authors.filter((author) => !author.key); + if (inlineAuthors.length > 0) { + logger.report(onInlineAuthors)( + `Some blog authors used in ${blogSourceRelative} are not defined in ${authorsMapPath}: +- ${inlineAuthors.map(authorToString).join('\n- ')} + +Note: if you want to allow inline blog authors, ignore this warning by setting onInlineAuthors: 'ignore' in your blog plugin options. +`, + ); + } + } + + function reportDuplicateAuthors(): void { + const duplicateAuthors = _(authors) + // for now we only check for predefined authors duplicates + .filter((author) => !!author.key) + .groupBy((author) => author.key) + .pickBy((authorsByKey) => authorsByKey.length > 1) + // We only keep the "test" of all the duplicate groups + // The first author of a group is not really a duplicate... + .flatMap(([, ...rest]) => rest) + .value(); + + if (duplicateAuthors.length > 0) { + throw new Error(`Duplicate blog authors found in blog post ${blogSourceRelative} front matter: +- ${duplicateAuthors.map(authorToString).join('\n- ')}`); + } + } +} + +function authorToString(author: Author) { + return JSON.stringify(author); +} From 9a487bc0839ef5bfa9c3fb0425f5b0e2a6c97481 Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 26 Jun 2024 18:58:47 +0200 Subject: [PATCH 15/22] improve tests for reportAuthorProblems --- .../src/__tests__/authorsProblems.test.ts | 249 +++++++++++------- .../src/authorsProblems.ts | 68 +++-- .../src/blogUtils.ts | 8 +- 3 files changed, 189 insertions(+), 136 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/authorsProblems.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/authorsProblems.test.ts index b9718ce85fd7..12abaaef3d53 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/authorsProblems.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/authorsProblems.test.ts @@ -5,129 +5,174 @@ * LICENSE file in the root directory of this source tree. */ -import {reportAuthorsProblems} from '../authorsProblems'; +import {jest} from '@jest/globals'; +import {reportDuplicateAuthors, reportInlineAuthors} from '../authorsProblems'; import type {Author} from '@docusaurus/plugin-content-blog'; -describe('reportAuthorsProblems', () => { - const blogSourceRelative = 'doc.md'; +const blogSourceRelative = 'doc.md'; - type Options = Parameters[0]['options']; - - describe('duplicate authors', () => { - const options: Options = { - onInlineAuthors: 'ignore', - authorsMapPath: 'authors.yml', - }; - - function testReport({authors}: {authors: Author[]}) { - reportAuthorsProblems({ - authors, - options, - blogSourceRelative, - }); - } - - it('allows duplicated inline authors', () => { - const authors: Author[] = [ - { - name: 'Sébastien Lorber', - }, - { - name: 'Sébastien Lorber', - }, - ]; - - expect(() => - testReport({ - authors, - }), - ).not.toThrow(); +describe('duplicate authors', () => { + function testReport({authors}: {authors: Author[]}) { + reportDuplicateAuthors({ + authors, + blogSourceRelative, }); + } + + it('allows duplicated inline authors', () => { + const authors: Author[] = [ + { + name: 'Sébastien Lorber', + }, + { + name: 'Sébastien Lorber', + }, + ]; + + expect(() => + testReport({ + authors, + }), + ).not.toThrow(); + }); - it('rejects duplicated key authors', () => { - const authors: Author[] = [ - { - key: 'slorber', - name: 'Sébastien Lorber 1', - title: 'some title', - }, - { - key: 'slorber', - name: 'Sébastien Lorber 2', - imageURL: '/slorber.png', - }, - ]; - - expect(() => - testReport({ - authors, - }), - ).toThrowErrorMatchingInlineSnapshot(` + it('rejects duplicated key authors', () => { + const authors: Author[] = [ + { + key: 'slorber', + name: 'Sébastien Lorber 1', + title: 'some title', + }, + { + key: 'slorber', + name: 'Sébastien Lorber 2', + imageURL: '/slorber.png', + }, + ]; + + expect(() => + testReport({ + authors, + }), + ).toThrowErrorMatchingInlineSnapshot(` "Duplicate blog authors found in blog post doc.md front matter: - {"key":"slorber","name":"Sébastien Lorber 2","imageURL":"/slorber.png"}" `); - }); }); +}); - describe('inline authors', () => { - const options: Options = { +describe('inline authors', () => { + type Options = Parameters[0]['options']; + + function testReport({ + authors, + options = {}, + }: { + authors: Author[]; + options?: Partial; + }) { + const defaultOptions: Options = { onInlineAuthors: 'throw', authorsMapPath: 'authors.yml', }; - function testReport({authors}: {authors: Author[]}) { - reportAuthorsProblems({ - authors, - options, - blogSourceRelative, - }); - } - - it('allows predefined authors', () => { - const authors: Author[] = [ - { - key: 'slorber', - name: 'Sébastien Lorber', - }, - { - key: 'ozaki', - name: 'Clément Couriol', - }, - ]; - - expect(() => - testReport({ - authors, - }), - ).not.toThrow(); + reportInlineAuthors({ + authors, + options: { + ...defaultOptions, + ...options, + }, + blogSourceRelative, }); + } + + it('allows predefined authors', () => { + const authors: Author[] = [ + { + key: 'slorber', + name: 'Sébastien Lorber', + }, + { + key: 'ozaki', + name: 'Clément Couriol', + }, + ]; + + expect(() => + testReport({ + authors, + }), + ).not.toThrow(); + }); - it('rejects inline authors', () => { - const authors: Author[] = [ - { - key: 'slorber', - name: 'Sébastien Lorber', - }, - {name: 'Inline author 1'}, - { - key: 'ozaki', - name: 'Clément Couriol', - }, - {imageURL: '/inline-author2.png'}, - ]; - - expect(() => - testReport({ - authors, - }), - ).toThrowErrorMatchingInlineSnapshot(` + it('rejects inline authors', () => { + const authors: Author[] = [ + { + key: 'slorber', + name: 'Sébastien Lorber', + }, + {name: 'Inline author 1'}, + { + key: 'ozaki', + name: 'Clément Couriol', + }, + {imageURL: '/inline-author2.png'}, + ]; + + expect(() => + testReport({ + authors, + }), + ).toThrowErrorMatchingInlineSnapshot(` "Some blog authors used in doc.md are not defined in authors.yml: - {"name":"Inline author 1"} - {"imageURL":"/inline-author2.png"} - Note: if you want to allow inline blog authors, ignore this warning by setting onInlineAuthors: 'ignore' in your blog plugin options. + Note that we recommend to declare authors once in a authors.yml file and reference them by key in blog posts front matter to avoid author info duplication. + But if you want to allow inline blog authors, you can disable this message by setting onInlineAuthors: 'ignore' in your blog plugin options. + More info at https://docusaurus.io/docs/blog " `); - }); + }); + + it('warn inline authors', () => { + const authors: Author[] = [ + { + key: 'slorber', + name: 'Sébastien Lorber', + }, + {name: 'Inline author 1'}, + { + key: 'ozaki', + name: 'Clément Couriol', + }, + {imageURL: '/inline-author2.png'}, + ]; + + const consoleMock = jest + .spyOn(console, 'warn') + .mockImplementation(() => {}); + + expect(() => + testReport({ + authors, + options: { + onInlineAuthors: 'warn', + }, + }), + ).not.toThrow(); + expect(consoleMock).toHaveBeenCalledTimes(1); + expect(consoleMock.mock.calls[0]).toMatchInlineSnapshot(` + [ + "[WARNING] Some blog authors used in doc.md are not defined in authors.yml: + - {"name":"Inline author 1"} + - {"imageURL":"/inline-author2.png"} + + Note that we recommend to declare authors once in a authors.yml file and reference them by key in blog posts front matter to avoid author info duplication. + But if you want to allow inline blog authors, you can disable this message by setting onInlineAuthors: 'ignore' in your blog plugin options. + More info at https://docusaurus.io/docs/blog + ", + ] + `); }); }); diff --git a/packages/docusaurus-plugin-content-blog/src/authorsProblems.ts b/packages/docusaurus-plugin-content-blog/src/authorsProblems.ts index 53b599ab0895..581ab25f2e18 100644 --- a/packages/docusaurus-plugin-content-blog/src/authorsProblems.ts +++ b/packages/docusaurus-plugin-content-blog/src/authorsProblems.ts @@ -9,7 +9,16 @@ import _ from 'lodash'; import logger from '@docusaurus/logger'; import type {Author, PluginOptions} from '@docusaurus/plugin-content-blog'; -export function reportAuthorsProblems({ +export function reportAuthorsProblems(params: { + authors: Author[]; + blogSourceRelative: string; + options: Pick; +}): void { + reportInlineAuthors(params); + reportDuplicateAuthors(params); +} + +export function reportInlineAuthors({ authors, blogSourceRelative, options: {onInlineAuthors, authorsMapPath}, @@ -18,40 +27,43 @@ export function reportAuthorsProblems({ blogSourceRelative: string; options: Pick; }): void { - reportInlineAuthors(); - reportDuplicateAuthors(); - - function reportInlineAuthors(): void { - if (onInlineAuthors === 'ignore') { - return; - } - const inlineAuthors = authors.filter((author) => !author.key); - if (inlineAuthors.length > 0) { - logger.report(onInlineAuthors)( - `Some blog authors used in ${blogSourceRelative} are not defined in ${authorsMapPath}: + if (onInlineAuthors === 'ignore') { + return; + } + const inlineAuthors = authors.filter((author) => !author.key); + if (inlineAuthors.length > 0) { + logger.report(onInlineAuthors)( + `Some blog authors used in ${blogSourceRelative} are not defined in ${authorsMapPath}: - ${inlineAuthors.map(authorToString).join('\n- ')} -Note: if you want to allow inline blog authors, ignore this warning by setting onInlineAuthors: 'ignore' in your blog plugin options. +Note that we recommend to declare authors once in a ${authorsMapPath} file and reference them by key in blog posts front matter to avoid author info duplication. +But if you want to allow inline blog authors, you can disable this message by setting onInlineAuthors: 'ignore' in your blog plugin options. +More info at https://docusaurus.io/docs/blog `, - ); - } + ); } +} - function reportDuplicateAuthors(): void { - const duplicateAuthors = _(authors) - // for now we only check for predefined authors duplicates - .filter((author) => !!author.key) - .groupBy((author) => author.key) - .pickBy((authorsByKey) => authorsByKey.length > 1) - // We only keep the "test" of all the duplicate groups - // The first author of a group is not really a duplicate... - .flatMap(([, ...rest]) => rest) - .value(); +export function reportDuplicateAuthors({ + authors, + blogSourceRelative, +}: { + authors: Author[]; + blogSourceRelative: string; +}): void { + const duplicateAuthors = _(authors) + // for now we only check for predefined authors duplicates + .filter((author) => !!author.key) + .groupBy((author) => author.key) + .pickBy((authorsByKey) => authorsByKey.length > 1) + // We only keep the "test" of all the duplicate groups + // The first author of a group is not really a duplicate... + .flatMap(([, ...rest]) => rest) + .value(); - if (duplicateAuthors.length > 0) { - throw new Error(`Duplicate blog authors found in blog post ${blogSourceRelative} front matter: + if (duplicateAuthors.length > 0) { + throw new Error(`Duplicate blog authors found in blog post ${blogSourceRelative} front matter: - ${duplicateAuthors.map(authorToString).join('\n- ')}`); - } } } diff --git a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts index b158533832fe..68f429cc8c0c 100644 --- a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts +++ b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts @@ -29,12 +29,8 @@ import { } from '@docusaurus/utils'; import {getTagsFile} from '@docusaurus/utils-validation'; import {validateBlogPostFrontMatter} from './frontMatter'; -import { - type AuthorsMap, - getAuthorsMap, - getBlogPostAuthors, - reportAuthorsProblems, -} from './authors'; +import {type AuthorsMap, getAuthorsMap, getBlogPostAuthors} from './authors'; +import {reportAuthorsProblems} from './authorsProblems'; import type {TagsFile} from '@docusaurus/utils'; import type {LoadContext, ParseFrontMatter} from '@docusaurus/types'; import type { From 4586ade91b55db812a9e84ea6dc0aee7a82f9380 Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 26 Jun 2024 19:03:15 +0200 Subject: [PATCH 16/22] fix website blog author warnings --- website/_dogfooding/dogfooding.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/_dogfooding/dogfooding.config.ts b/website/_dogfooding/dogfooding.config.ts index 241ba0744383..e311c980914e 100644 --- a/website/_dogfooding/dogfooding.config.ts +++ b/website/_dogfooding/dogfooding.config.ts @@ -84,8 +84,8 @@ export const dogfoodingPluginInstances: PluginConfig[] = [ ? undefined : defaultReadingTime({content, options: {wordsPerMinute: 5}}), onInlineTags: 'warn', + onInlineAuthors: 'ignore', tags: 'tags.yml', - onInlineAuthors: 'warn', } satisfies BlogOptions, ], From 22ea2795009d0bd43f68a4858ff52dfe0ed60e71 Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 26 Jun 2024 19:04:45 +0200 Subject: [PATCH 17/22] fix website blog author warnings --- website/_dogfooding/_docs tests/standalone.mdx | 3 +-- website/_dogfooding/_docs tests/tags.yml | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/website/_dogfooding/_docs tests/standalone.mdx b/website/_dogfooding/_docs tests/standalone.mdx index c81811feae53..01edc102880f 100644 --- a/website/_dogfooding/_docs tests/standalone.mdx +++ b/website/_dogfooding/_docs tests/standalone.mdx @@ -1,8 +1,7 @@ --- tags: - b - - label: d - permalink: d-custom-permalink + - d --- # Standalone doc diff --git a/website/_dogfooding/_docs tests/tags.yml b/website/_dogfooding/_docs tests/tags.yml index 548ba5e7d862..9c4b9c73c18f 100644 --- a/website/_dogfooding/_docs tests/tags.yml +++ b/website/_dogfooding/_docs tests/tags.yml @@ -4,6 +4,7 @@ b: label: 'Label for tag b' c: permalink: '/permalink-for-tag-c' +d: e: label: 'Label for tag e' description: 'Description for tag e' From 4ef50962da298b90636e3ed73304b831ffd8fd51 Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 26 Jun 2024 19:13:25 +0200 Subject: [PATCH 18/22] fix website blog author warnings + polish --- .../src/__tests__/authorsProblems.test.ts | 28 +++++++++---------- .../src/authorsProblems.ts | 8 +++--- ...-How-I-Converted-Profilo-To-Docusaurus.mdx | 5 +--- .../blog/2018/09-11-Towards-Docusaurus-2.mdx | 6 +--- .../index.mdx | 9 +----- website/blog/authors.yml | 20 +++++++++++++ 6 files changed, 41 insertions(+), 35 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/authorsProblems.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/authorsProblems.test.ts index 12abaaef3d53..84296df1c931 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/authorsProblems.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/authorsProblems.test.ts @@ -55,9 +55,9 @@ describe('duplicate authors', () => { authors, }), ).toThrowErrorMatchingInlineSnapshot(` - "Duplicate blog authors found in blog post doc.md front matter: - - {"key":"slorber","name":"Sébastien Lorber 2","imageURL":"/slorber.png"}" - `); + "Duplicate blog post authors were found in blog post "doc.md" front matter: + - {"key":"slorber","name":"Sébastien Lorber 2","imageURL":"/slorber.png"}" + `); }); }); @@ -124,15 +124,15 @@ describe('inline authors', () => { authors, }), ).toThrowErrorMatchingInlineSnapshot(` - "Some blog authors used in doc.md are not defined in authors.yml: - - {"name":"Inline author 1"} - - {"imageURL":"/inline-author2.png"} - - Note that we recommend to declare authors once in a authors.yml file and reference them by key in blog posts front matter to avoid author info duplication. - But if you want to allow inline blog authors, you can disable this message by setting onInlineAuthors: 'ignore' in your blog plugin options. - More info at https://docusaurus.io/docs/blog - " - `); + "Some blog authors used in "doc.md" are not defined in "authors.yml": + - {"name":"Inline author 1"} + - {"imageURL":"/inline-author2.png"} + + Note that we recommend to declare authors once in a "authors.yml" file and reference them by key in blog posts front matter to avoid author info duplication. + But if you want to allow inline blog authors, you can disable this message by setting onInlineAuthors: 'ignore' in your blog plugin options. + More info at https://docusaurus.io/docs/blog + " + `); }); it('warn inline authors', () => { @@ -164,11 +164,11 @@ describe('inline authors', () => { expect(consoleMock).toHaveBeenCalledTimes(1); expect(consoleMock.mock.calls[0]).toMatchInlineSnapshot(` [ - "[WARNING] Some blog authors used in doc.md are not defined in authors.yml: + "[WARNING] Some blog authors used in "doc.md" are not defined in "authors.yml": - {"name":"Inline author 1"} - {"imageURL":"/inline-author2.png"} - Note that we recommend to declare authors once in a authors.yml file and reference them by key in blog posts front matter to avoid author info duplication. + Note that we recommend to declare authors once in a "authors.yml" file and reference them by key in blog posts front matter to avoid author info duplication. But if you want to allow inline blog authors, you can disable this message by setting onInlineAuthors: 'ignore' in your blog plugin options. More info at https://docusaurus.io/docs/blog ", diff --git a/packages/docusaurus-plugin-content-blog/src/authorsProblems.ts b/packages/docusaurus-plugin-content-blog/src/authorsProblems.ts index 581ab25f2e18..fecc7b5ce06c 100644 --- a/packages/docusaurus-plugin-content-blog/src/authorsProblems.ts +++ b/packages/docusaurus-plugin-content-blog/src/authorsProblems.ts @@ -33,12 +33,12 @@ export function reportInlineAuthors({ const inlineAuthors = authors.filter((author) => !author.key); if (inlineAuthors.length > 0) { logger.report(onInlineAuthors)( - `Some blog authors used in ${blogSourceRelative} are not defined in ${authorsMapPath}: + logger.interpolate`Some blog authors used in path=${blogSourceRelative} are not defined in path=${authorsMapPath}: - ${inlineAuthors.map(authorToString).join('\n- ')} -Note that we recommend to declare authors once in a ${authorsMapPath} file and reference them by key in blog posts front matter to avoid author info duplication. +Note that we recommend to declare authors once in a path=${authorsMapPath} file and reference them by key in blog posts front matter to avoid author info duplication. But if you want to allow inline blog authors, you can disable this message by setting onInlineAuthors: 'ignore' in your blog plugin options. -More info at https://docusaurus.io/docs/blog +More info at url=${'https://docusaurus.io/docs/blog'} `, ); } @@ -62,7 +62,7 @@ export function reportDuplicateAuthors({ .value(); if (duplicateAuthors.length > 0) { - throw new Error(`Duplicate blog authors found in blog post ${blogSourceRelative} front matter: + throw new Error(logger.interpolate`Duplicate blog post authors were found in blog post path=${blogSourceRelative} front matter: - ${duplicateAuthors.map(authorToString).join('\n- ')}`); } } diff --git a/website/blog/2018/04-30-How-I-Converted-Profilo-To-Docusaurus.mdx b/website/blog/2018/04-30-How-I-Converted-Profilo-To-Docusaurus.mdx index bd2fa2e4044d..2c2eb734dc89 100644 --- a/website/blog/2018/04-30-How-I-Converted-Profilo-To-Docusaurus.mdx +++ b/website/blog/2018/04-30-How-I-Converted-Profilo-To-Docusaurus.mdx @@ -1,9 +1,6 @@ --- title: How I Converted Profilo to Docusaurus in Under 2 Hours -author: Christine Abernathy -authorURL: http://twitter.com/abernathyca -authorImageURL: https://github.com/caabernathy.png -authorTwitter: abernathyca +authors: [abernathyca] tags: [profilo, adoption] --- diff --git a/website/blog/2018/09-11-Towards-Docusaurus-2.mdx b/website/blog/2018/09-11-Towards-Docusaurus-2.mdx index 5496e46ae93a..584d969f0f5b 100644 --- a/website/blog/2018/09-11-Towards-Docusaurus-2.mdx +++ b/website/blog/2018/09-11-Towards-Docusaurus-2.mdx @@ -1,10 +1,6 @@ --- title: Towards Docusaurus 2 -author: Endilie Yacop Sucipto -authorTitle: Maintainer of Docusaurus -authorURL: https://github.com/endiliey -authorImageURL: https://github.com/endiliey.png -authorTwitter: endiliey +authors: endiliey tags: [new, adoption] --- diff --git a/website/blog/2021/11-21-algolia-docsearch-migration/index.mdx b/website/blog/2021/11-21-algolia-docsearch-migration/index.mdx index 823f10a1659d..0c169bd357c4 100644 --- a/website/blog/2021/11-21-algolia-docsearch-migration/index.mdx +++ b/website/blog/2021/11-21-algolia-docsearch-migration/index.mdx @@ -1,13 +1,6 @@ --- title: DocSearch migration -authors: - - name: Clément Vannicatte - title: Software Engineer @ Algolia - url: https://github.com/shortcuts - image_url: https://github.com/shortcuts.png - twitter: sh0rtcts - - key: slorber - +authors: [shortcuts, slorber] tags: [search] image: ./img/social-card.png --- diff --git a/website/blog/authors.yml b/website/blog/authors.yml index 5b84346cda7c..7fb45d8003ec 100644 --- a/website/blog/authors.yml +++ b/website/blog/authors.yml @@ -43,3 +43,23 @@ Josh-Cena: url: https://joshcena.com/ image_url: https://github.com/josh-cena.png email: sidachen2003@gmail.com + +endiliey: + name: Endilie Yacop Sucipto + title: Maintainer of Docusaurus + url: https://github.com/endiliey + image_url: https://github.com/endiliey.png + twitter: endiliey + +abernathyca: + name: Christine Abernathy + url: http://twitter.com/abernathyca + image_url: https://github.com/caabernathy.png + twitter: abernathyca + +shortcuts: + name: Clément Vannicatte + title: Software Engineer @ Algolia + url: https://github.com/shortcuts + image_url: https://github.com/shortcuts.png + twitter: sh0rtcts From 042eaaf6abacca724783f69ff3d08eeea299ac70 Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 26 Jun 2024 19:18:12 +0200 Subject: [PATCH 19/22] revert useless tests changes --- .../src/__tests__/authors.test.ts | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) 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 d67f5dc41024..6cc386a0165e 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts @@ -206,7 +206,6 @@ describe('getBlogPostAuthors', () => { { name: 'Sébastien Lorber', title: 'maintainer', - imageURL: undefined, }, ]); }); @@ -224,15 +223,8 @@ describe('getBlogPostAuthors', () => { baseUrl: '/', }), ).toEqual([ - { - name: 'Sébastien Lorber', - title: 'maintainer', - imageURL: undefined, - }, - { - name: 'Yangshun Tay', - imageURL: undefined, - }, + {name: 'Sébastien Lorber', title: 'maintainer'}, + {name: 'Yangshun Tay'}, ]); }); @@ -252,10 +244,7 @@ describe('getBlogPostAuthors', () => { }, authorsMap: { slorber: {name: 'Sébastien Lorber', title: 'maintainer'}, - yangshun: { - name: 'Yangshun Tay', - title: 'Yangshun title original', - }, + yangshun: {name: 'Yangshun Tay', title: 'Yangshun title original'}, }, baseUrl: '/', }), @@ -266,9 +255,8 @@ describe('getBlogPostAuthors', () => { name: 'Yangshun Tay', title: 'Yangshun title local override', extra: 42, - imageURL: undefined, }, - {name: 'Alexey', imageURL: undefined}, + {name: 'Alexey'}, ]); }); From 9cbabbe59b795f7f51ee4fab0a0b11b3b2f4a6a6 Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 26 Jun 2024 19:18:40 +0200 Subject: [PATCH 20/22] revert useless tests changes --- .../src/__tests__/authors.test.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) 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 6cc386a0165e..bb55d7b4c4ad 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/authors.test.ts @@ -202,12 +202,7 @@ describe('getBlogPostAuthors', () => { authorsMap: undefined, baseUrl: '/', }), - ).toEqual([ - { - name: 'Sébastien Lorber', - title: 'maintainer', - }, - ]); + ).toEqual([{name: 'Sébastien Lorber', title: 'maintainer'}]); }); it('can read authors Author[]', () => { From e4af303daf9dbd1dcef921dcb3ae7a4982513ee3 Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 26 Jun 2024 19:19:47 +0200 Subject: [PATCH 21/22] revert useless diff --- packages/docusaurus-plugin-content-blog/src/authors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docusaurus-plugin-content-blog/src/authors.ts b/packages/docusaurus-plugin-content-blog/src/authors.ts index d114f48acfd2..c5fdad61ddfb 100644 --- a/packages/docusaurus-plugin-content-blog/src/authors.ts +++ b/packages/docusaurus-plugin-content-blog/src/authors.ts @@ -171,7 +171,7 @@ ${Object.keys(authorsMap) function fixAuthorImageBaseURL( authors: Author[], {baseUrl}: {baseUrl: string}, -): Author[] { +) { return authors.map((author) => ({ ...author, imageURL: normalizeImageUrl({imageURL: author.imageURL, baseUrl}), From 489c3e052fe9505863e522924c716925e4c2a977 Mon Sep 17 00:00:00 2001 From: sebastien Date: Wed, 26 Jun 2024 19:27:09 +0200 Subject: [PATCH 22/22] fix tests --- .../docusaurus-plugin-content-blog/src/__tests__/index.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts index 18669c0794f8..5280a72c18c8 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts @@ -220,11 +220,9 @@ describe('blog plugin', () => { authors: [ { name: 'Yangshun Tay (translated)', - inline: true, }, { email: 'lorber.sebastien@gmail.com', - imageURL: undefined, key: 'slorber', name: 'Sébastien Lorber (translated)', title: 'Docusaurus maintainer (translated)',