mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 05:57:05 +02:00
feat(content-blog): allow authors list to contain images only (#6416)
* feat(content-blog): allow authors list to contain images only * adjust styles * fix * fix * mention in docs * fix wording
This commit is contained in:
parent
d506bca12d
commit
4e69c052d6
7 changed files with 90 additions and 8 deletions
|
@ -353,15 +353,27 @@ describe('validateAuthorsMap', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('reject author without name', () => {
|
||||
test('accept author with only image', () => {
|
||||
const authorsMap: AuthorsMap = {
|
||||
slorber: {
|
||||
image_url: 'https://github.com/slorber.png',
|
||||
imageURL: 'https://github.com/slorber.png',
|
||||
url: 'https://github.com/slorber',
|
||||
},
|
||||
};
|
||||
expect(validateAuthorsMap(authorsMap)).toEqual(authorsMap);
|
||||
});
|
||||
|
||||
test('reject author without name or image', () => {
|
||||
const authorsMap: AuthorsMap = {
|
||||
slorber: {
|
||||
title: 'foo',
|
||||
},
|
||||
};
|
||||
expect(() =>
|
||||
validateAuthorsMap(authorsMap),
|
||||
).toThrowErrorMatchingInlineSnapshot(`"\\"slorber.name\\" is required"`);
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"\\"slorber\\" must contain at least one of [name, imageURL]"`,
|
||||
);
|
||||
});
|
||||
|
||||
test('reject undefined author', () => {
|
||||
|
|
|
@ -20,12 +20,13 @@ export type AuthorsMap = Record<string, Author>;
|
|||
const AuthorsMapSchema = Joi.object<AuthorsMap>().pattern(
|
||||
Joi.string(),
|
||||
Joi.object({
|
||||
name: Joi.string().required(),
|
||||
name: Joi.string(),
|
||||
url: URISchema,
|
||||
imageURL: URISchema,
|
||||
title: Joi.string(),
|
||||
})
|
||||
.rename('image_url', 'imageURL')
|
||||
.or('name', 'imageURL')
|
||||
.unknown()
|
||||
.required(),
|
||||
);
|
||||
|
@ -63,7 +64,6 @@ function getFrontMatterAuthorLegacy(
|
|||
const url = frontMatter.author_url ?? frontMatter.authorURL;
|
||||
const imageURL = frontMatter.author_image_url ?? frontMatter.authorImageURL;
|
||||
|
||||
// Shouldn't we require at least an author name?
|
||||
if (name || title || url || imageURL) {
|
||||
return {
|
||||
name,
|
||||
|
|
|
@ -21,7 +21,7 @@ const BlogPostFrontMatterAuthorSchema = Joi.object({
|
|||
url: URISchema,
|
||||
imageURL: Joi.string(),
|
||||
})
|
||||
.or('key', 'name')
|
||||
.or('key', 'name', 'imageURL')
|
||||
.rename('image_url', 'imageURL', {alias: true});
|
||||
|
||||
const FrontMatterAuthorErrorMessage =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue