Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(blog): normalize inline authors socials #10424

Merged
merged 10 commits into from
Aug 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,13 @@ describe('getBlogPostAuthors', () => {
expect(
getBlogPostAuthors({
frontMatter: {
authors: {name: 'Sébastien Lorber', title: 'maintainer'},
authors: {
name: 'Sébastien Lorber',
title: 'maintainer',
socials: {
github: 'slorber',
},
},
},
authorsMap: undefined,
baseUrl: '/',
Expand All @@ -282,6 +288,9 @@ describe('getBlogPostAuthors', () => {
name: 'Sébastien Lorber',
title: 'maintainer',
imageURL: undefined,
socials: {
github: 'https://github.com/slorber',
},
key: null,
page: null,
},
Expand All @@ -293,8 +302,19 @@ describe('getBlogPostAuthors', () => {
getBlogPostAuthors({
frontMatter: {
authors: [
{name: 'Sébastien Lorber', title: 'maintainer'},
{name: 'Yangshun Tay'},
{
name: 'Sébastien Lorber',
title: 'maintainer',
socials: {
github: 'slorber',
},
OzakIOne marked this conversation as resolved.
Show resolved Hide resolved
},
{
name: 'Yangshun Tay',
socials: {
github: 'https://github.com/yangshun',
},
},
],
},
authorsMap: undefined,
Expand All @@ -306,9 +326,20 @@ describe('getBlogPostAuthors', () => {
title: 'maintainer',
imageURL: undefined,
key: null,
socials: {
github: 'https://github.com/slorber',
},
page: null,
},
{name: 'Yangshun Tay', imageURL: undefined, key: null, page: null},
{
name: 'Yangshun Tay',
imageURL: undefined,
key: null,
page: null,
socials: {
github: 'https://github.com/yangshun',
},
},
]);
});

Expand All @@ -323,7 +354,12 @@ describe('getBlogPostAuthors', () => {
title: 'Yangshun title local override',
extra: 42,
},
{name: 'Alexey'},
{
name: 'Alexey',
socials: {
github: 'lex111',
},
},
],
},
authorsMap: {
Expand Down Expand Up @@ -358,7 +394,15 @@ describe('getBlogPostAuthors', () => {
imageURL: undefined,
page: null,
},
{name: 'Alexey', imageURL: undefined, key: null, page: null},
{
name: 'Alexey',
imageURL: undefined,
key: null,
page: null,
socials: {
github: 'https://github.com/lex111',
},
},
]);
});

Expand Down
10 changes: 9 additions & 1 deletion packages/docusaurus-plugin-content-blog/src/authors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import _ from 'lodash';
import {normalizeUrl} from '@docusaurus/utils';
import {normalizeSocials} from './authorsSocials';
import type {
Author,
AuthorsMap,
Expand Down Expand Up @@ -84,7 +85,14 @@ function getFrontMatterAuthors(params: AuthorsParam): Author[] {
// becoming a name and may end up unnoticed
return {key: authorInput};
}
return authorInput;
const normalizedSocials = normalizeSocials(authorInput.socials ?? {});

return {
...authorInput,
...(Object.keys(normalizedSocials).length > 0 && {
socials: normalizedSocials,
}),
OzakIOne marked this conversation as resolved.
Show resolved Hide resolved
};
}

return Array.isArray(frontMatter.authors)
Expand Down
Loading