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:
ozaki 2024-03-15 12:50:06 +01:00 committed by GitHub
parent 7938803747
commit c745021b01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 833 additions and 359 deletions

View file

@ -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."`;

View file

@ -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'});
});
});

View file

@ -26,4 +26,6 @@ export {
FrontMatterTagsSchema,
FrontMatterTOCHeadingLevels,
ContentVisibilitySchema,
FrontMatterLastUpdateErrorMessage,
FrontMatterLastUpdateSchema,
} from './validationSchemas';

View file

@ -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,
});