mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-20 12:37:01 +02:00
feat(plugin-blog): multi-authors support + authors.yml global configuration (#5396)
* Complete function Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * A lot of blank lines Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * More lenient validation Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Remove or Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Simpler logic Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Expand docs Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Better docs Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Dogfood Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * More writeup Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Polish Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Polish Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Move mergeAuthorMap to authors.ts Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Unbreak relative assets * Update docs * Clarify in docs * simplify feed authors * rename authorMap -> authorsMap * mergeAuthorsMap -> getBlogPostAuthors * website => 5 blog posts per page * improve authors map file * Extract new theme authors components + display in row * add comment for meta array syntaxes * blog => getPathsToWatch should watch authorsMap file * remove useless v1 blog FBID frontmatter * keep older frontmatter syntax for now * revert blog frontmatter * Better console message * better blog authors frontmatter impl * add multi authors to beta blog post + fix some authors margins * fix React key * Refactor: mdx loader should support a more flexible assets system (poc, not documented yet) * better display of blog post authors: adapt layout to authors count + add line clamp * smaller local image * fix blog feed tests * fix blog frontmatter tests + improve validation schema * add more frontmatter tests * add tests for getAuthorsMapFilePath * tests for validateAuthorsMapFile * add tests for readAuthorsMapFile * test getAuthorsMap * exhaustive tests for getBlogPostAuthors * fix remaining tests * missing blog plugin author tests * fix windows tests * improve blog multi-author's doc * Use new format in init template Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Improve error message Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * update feed snapshot * blog authors: limit to 2 cols + fix margins for no authors * minor doc improvements * better init template blog posts, demonstrating Blog features * replace the legacy blog author frontmatter in remaining places * Prefer using clsx Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * cleanup getColClassName * remove blog author name/title line-clamping Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
8779c8ff4a
commit
493225a3c6
79 changed files with 1871 additions and 285 deletions
|
@ -11,6 +11,8 @@ import {
|
|||
} from '../blogFrontMatter';
|
||||
import escapeStringRegexp from 'escape-string-regexp';
|
||||
|
||||
// TODO this abstraction reduce verbosity but it makes it harder to debug
|
||||
// It would be preferable to just expose helper methods
|
||||
function testField(params: {
|
||||
fieldName: keyof BlogPostFrontMatter;
|
||||
validFrontMatters: BlogPostFrontMatter[];
|
||||
|
@ -99,7 +101,30 @@ describe('validateBlogPostFrontMatter id', () => {
|
|||
testField({
|
||||
fieldName: 'id',
|
||||
validFrontMatters: [{id: '123'}, {id: 'id'}],
|
||||
invalidFrontMatters: [[{id: ''}, 'is not allowed to be empty']],
|
||||
invalidFrontMatters: [[{id: ''}, 'not allowed to be empty']],
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateBlogPostFrontMatter handles legacy/new author frontmatter', () => {
|
||||
test('allow legacy author frontmatter', () => {
|
||||
const frontMatter: BlogPostFrontMatter = {
|
||||
author: 'Sebastien',
|
||||
author_url: 'https://sebastienlorber.com',
|
||||
author_title: 'maintainer',
|
||||
author_image_url: 'https://github.com/slorber.png',
|
||||
};
|
||||
expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
|
||||
});
|
||||
|
||||
test('allow new authors frontmatter', () => {
|
||||
const frontMatter: BlogPostFrontMatter = {
|
||||
authors: [
|
||||
'slorber',
|
||||
{name: 'Yangshun'},
|
||||
{key: 'JMarcey', title: 'creator', random: '42'},
|
||||
],
|
||||
};
|
||||
expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -107,21 +132,24 @@ describe('validateBlogPostFrontMatter author', () => {
|
|||
testField({
|
||||
fieldName: 'author',
|
||||
validFrontMatters: [{author: '123'}, {author: 'author'}],
|
||||
invalidFrontMatters: [[{author: ''}, 'is not allowed to be empty']],
|
||||
invalidFrontMatters: [[{author: ''}, 'not allowed to be empty']],
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateBlogPostFrontMatter author_title', () => {
|
||||
testField({
|
||||
fieldName: 'author_title',
|
||||
validFrontMatters: [{author_title: '123'}, {author_title: 'author_title'}],
|
||||
invalidFrontMatters: [[{author_title: ''}, 'is not allowed to be empty']],
|
||||
validFrontMatters: [
|
||||
{author: '123', author_title: '123'},
|
||||
{author: '123', author_title: 'author_title'},
|
||||
],
|
||||
invalidFrontMatters: [[{author_title: ''}, 'not allowed to be empty']],
|
||||
});
|
||||
|
||||
testField({
|
||||
fieldName: 'authorTitle',
|
||||
validFrontMatters: [{authorTitle: '123'}, {authorTitle: 'authorTitle'}],
|
||||
invalidFrontMatters: [[{authorTitle: ''}, 'is not allowed to be empty']],
|
||||
invalidFrontMatters: [[{authorTitle: ''}, 'not allowed to be empty']],
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -136,7 +164,7 @@ describe('validateBlogPostFrontMatter author_url', () => {
|
|||
invalidFrontMatters: [
|
||||
[
|
||||
{author_url: ''},
|
||||
'"author_url" does not match any of the allowed types',
|
||||
'"author_url" does not look like a valid url (value=\'\')',
|
||||
],
|
||||
],
|
||||
});
|
||||
|
@ -150,7 +178,10 @@ describe('validateBlogPostFrontMatter author_url', () => {
|
|||
],
|
||||
|
||||
invalidFrontMatters: [
|
||||
[{authorURL: ''}, '"authorURL" does not match any of the allowed types'],
|
||||
[
|
||||
{authorURL: ''},
|
||||
'"authorURL" does not look like a valid url (value=\'\')',
|
||||
],
|
||||
],
|
||||
});
|
||||
});
|
||||
|
@ -166,7 +197,7 @@ describe('validateBlogPostFrontMatter author_image_url', () => {
|
|||
invalidFrontMatters: [
|
||||
[
|
||||
{author_image_url: ''},
|
||||
'"author_image_url" does not match any of the allowed types',
|
||||
'"author_image_url" does not look like a valid url (value=\'\')',
|
||||
],
|
||||
],
|
||||
});
|
||||
|
@ -181,7 +212,55 @@ describe('validateBlogPostFrontMatter author_image_url', () => {
|
|||
invalidFrontMatters: [
|
||||
[
|
||||
{authorImageURL: ''},
|
||||
'"authorImageURL" does not match any of the allowed types',
|
||||
'"authorImageURL" does not look like a valid url (value=\'\')',
|
||||
],
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateBlogPostFrontMatter authors', () => {
|
||||
testField({
|
||||
fieldName: 'author',
|
||||
validFrontMatters: [
|
||||
{authors: []},
|
||||
{authors: 'authorKey'},
|
||||
{authors: ['authorKey1', 'authorKey2']},
|
||||
{
|
||||
authors: {
|
||||
name: 'Author Name',
|
||||
imageURL: '/absolute',
|
||||
},
|
||||
},
|
||||
{
|
||||
authors: {
|
||||
key: 'authorKey',
|
||||
title: 'Author title',
|
||||
},
|
||||
},
|
||||
{
|
||||
authors: [
|
||||
'authorKey1',
|
||||
{key: 'authorKey3'},
|
||||
'authorKey3',
|
||||
{name: 'Author Name 4'},
|
||||
{key: 'authorKey5'},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
invalidFrontMatters: [
|
||||
[{authors: ''}, '"authors" is not allowed to be empty'],
|
||||
[
|
||||
{authors: [undefined]},
|
||||
'"authors[0]" does not look like a valid blog post author. Please use an author key or an author object (with a key and/or name).',
|
||||
],
|
||||
[
|
||||
{authors: [null]},
|
||||
'"authors[0]" does not look like a valid blog post author. Please use an author key or an author object (with a key and/or name).',
|
||||
],
|
||||
[
|
||||
{authors: [{}]},
|
||||
'"authors[0]" does not look like a valid blog post author. Please use an author key or an author object (with a key and/or name).',
|
||||
],
|
||||
],
|
||||
});
|
||||
|
@ -200,7 +279,7 @@ describe('validateBlogPostFrontMatter slug', () => {
|
|||
{slug: '/api/plugins/@docusaurus/plugin-debug'},
|
||||
{slug: '@site/api/asset/image.png'},
|
||||
],
|
||||
invalidFrontMatters: [[{slug: ''}, 'is not allowed to be empty']],
|
||||
invalidFrontMatters: [[{slug: ''}, 'not allowed to be empty']],
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -219,7 +298,7 @@ describe('validateBlogPostFrontMatter image', () => {
|
|||
{image: '@site/api/asset/image.png'},
|
||||
],
|
||||
invalidFrontMatters: [
|
||||
[{image: ''}, '"image" does not match any of the allowed types'],
|
||||
[{image: ''}, '"image" does not look like a valid url (value=\'\')'],
|
||||
],
|
||||
});
|
||||
});
|
||||
|
@ -236,7 +315,7 @@ describe('validateBlogPostFrontMatter tags', () => {
|
|||
],
|
||||
invalidFrontMatters: [
|
||||
[{tags: ''}, 'must be an array'],
|
||||
[{tags: ['']}, 'is not allowed to be empty'],
|
||||
[{tags: ['']}, 'not allowed to be empty'],
|
||||
],
|
||||
// See https://github.com/facebook/docusaurus/issues/4642
|
||||
convertibleFrontMatter: [
|
||||
|
@ -260,7 +339,7 @@ describe('validateBlogPostFrontMatter keywords', () => {
|
|||
],
|
||||
invalidFrontMatters: [
|
||||
[{keywords: ''}, 'must be an array'],
|
||||
[{keywords: ['']}, 'is not allowed to be empty'],
|
||||
[{keywords: ['']}, 'not allowed to be empty'],
|
||||
[{keywords: []}, 'does not contain 1 required value(s)'],
|
||||
],
|
||||
});
|
||||
|
@ -304,9 +383,7 @@ describe('validateBlogPostFrontMatter date', () => {
|
|||
fieldName: 'date',
|
||||
validFrontMatters: [
|
||||
{date: new Date('2020-01-01')},
|
||||
// @ts-expect-error: string for test
|
||||
{date: '2020-01-01'},
|
||||
// @ts-expect-error: string for test
|
||||
{date: '2020'},
|
||||
],
|
||||
invalidFrontMatters: [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue