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:
Joshua Chen 2022-01-20 22:08:18 +08:00 committed by GitHub
parent d506bca12d
commit 4e69c052d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 90 additions and 8 deletions

View file

@ -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', () => {

View file

@ -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,

View file

@ -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 =