mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
feat(blog): add LastUpdateAuthor & LastUpdateTime (#9912)
Co-authored-by: OzakIOne <OzakIOne@users.noreply.github.com> Co-authored-by: sebastien <lorber.sebastien@gmail.com>
This commit is contained in:
parent
7938803747
commit
c745021b01
40 changed files with 833 additions and 359 deletions
|
@ -30,6 +30,22 @@ exports[`validation schemas contentVisibilitySchema: for value={"unlisted":"bad
|
|||
|
||||
exports[`validation schemas contentVisibilitySchema: for value={"unlisted":42} 1`] = `""unlisted" must be a boolean"`;
|
||||
|
||||
exports[`validation schemas frontMatterLastUpdateSchema schema: for value="string" 1`] = `""value" does not look like a valid last update object. Please use an author key with a string or a date with a string or Date."`;
|
||||
|
||||
exports[`validation schemas frontMatterLastUpdateSchema schema: for value=[] 1`] = `""value" does not look like a valid last update object. Please use an author key with a string or a date with a string or Date."`;
|
||||
|
||||
exports[`validation schemas frontMatterLastUpdateSchema schema: for value={"author":23} 1`] = `""author" must be a string"`;
|
||||
|
||||
exports[`validation schemas frontMatterLastUpdateSchema schema: for value={"date":"20-20-20"} 1`] = `""date" must be a valid date"`;
|
||||
|
||||
exports[`validation schemas frontMatterLastUpdateSchema schema: for value={} 1`] = `""value" does not look like a valid last update object. Please use an author key with a string or a date with a string or Date."`;
|
||||
|
||||
exports[`validation schemas frontMatterLastUpdateSchema schema: for value=42 1`] = `""value" does not look like a valid last update object. Please use an author key with a string or a date with a string or Date."`;
|
||||
|
||||
exports[`validation schemas frontMatterLastUpdateSchema schema: for value=null 1`] = `""value" does not look like a valid last update object. Please use an author key with a string or a date with a string or Date."`;
|
||||
|
||||
exports[`validation schemas frontMatterLastUpdateSchema schema: for value=true 1`] = `""value" does not look like a valid last update object. Please use an author key with a string or a date with a string or Date."`;
|
||||
|
||||
exports[`validation schemas pathnameSchema: for value="foo" 1`] = `""value" (foo) is not a valid pathname. Pathname should start with slash and not contain any domain or query string."`;
|
||||
|
||||
exports[`validation schemas pathnameSchema: for value="https://github.com/foo" 1`] = `""value" (https://github.com/foo) is not a valid pathname. Pathname should start with slash and not contain any domain or query string."`;
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
PathnameSchema,
|
||||
RouteBasePathSchema,
|
||||
ContentVisibilitySchema,
|
||||
FrontMatterLastUpdateSchema,
|
||||
} from '../validationSchemas';
|
||||
|
||||
function createTestHelpers({
|
||||
|
@ -216,4 +217,28 @@ describe('validation schemas', () => {
|
|||
testFail({unlisted: 42});
|
||||
testFail({draft: true, unlisted: true});
|
||||
});
|
||||
|
||||
it('frontMatterLastUpdateSchema schema', () => {
|
||||
const {testFail, testOK} = createTestHelpers({
|
||||
schema: FrontMatterLastUpdateSchema,
|
||||
});
|
||||
|
||||
testOK(undefined);
|
||||
testOK({date: '2021-01-01'});
|
||||
testOK({date: '2021-01'});
|
||||
testOK({date: '2021'});
|
||||
testOK({date: new Date()});
|
||||
testOK({author: 'author'});
|
||||
testOK({author: 'author', date: '2021-01-01'});
|
||||
testOK({author: 'author', date: new Date()});
|
||||
|
||||
testFail(null);
|
||||
testFail({});
|
||||
testFail('string');
|
||||
testFail(42);
|
||||
testFail(true);
|
||||
testFail([]);
|
||||
testFail({author: 23});
|
||||
testFail({date: '20-20-20'});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -26,4 +26,6 @@ export {
|
|||
FrontMatterTagsSchema,
|
||||
FrontMatterTOCHeadingLevels,
|
||||
ContentVisibilitySchema,
|
||||
FrontMatterLastUpdateErrorMessage,
|
||||
FrontMatterLastUpdateSchema,
|
||||
} from './validationSchemas';
|
||||
|
|
|
@ -167,3 +167,16 @@ export const ContentVisibilitySchema = JoiFrontMatter.object<ContentVisibility>(
|
|||
"Can't be draft and unlisted at the same time.",
|
||||
})
|
||||
.unknown();
|
||||
|
||||
export const FrontMatterLastUpdateErrorMessage =
|
||||
'{{#label}} does not look like a valid last update object. Please use an author key with a string or a date with a string or Date.';
|
||||
|
||||
export const FrontMatterLastUpdateSchema = Joi.object({
|
||||
author: Joi.string(),
|
||||
date: Joi.date().raw(),
|
||||
})
|
||||
.or('author', 'date')
|
||||
.messages({
|
||||
'object.missing': FrontMatterLastUpdateErrorMessage,
|
||||
'object.base': FrontMatterLastUpdateErrorMessage,
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue