feat(content-blog): include front matter in loaded content metadata (#6189)

* feat(content-blog): include front matter in metadata

* fixes
This commit is contained in:
Joshua Chen 2021-12-26 11:24:24 +08:00 committed by GitHub
parent e1bff072fe
commit 2cc89e502f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 0 deletions

View file

@ -126,6 +126,9 @@ describe('loadBlog', () => {
authors: [], authors: [],
date: new Date('2019-01-01'), date: new Date('2019-01-01'),
formattedDate: 'January 1, 2019', formattedDate: 'January 1, 2019',
frontMatter: {
date: new Date('2019-01-01'),
},
prevItem: undefined, prevItem: undefined,
tags: [], tags: [],
nextItem: { nextItem: {
@ -161,6 +164,15 @@ describe('loadBlog', () => {
], ],
date: new Date('2018-12-14'), date: new Date('2018-12-14'),
formattedDate: 'December 14, 2018', formattedDate: 'December 14, 2018',
frontMatter: {
authors: [
{
name: 'Yangshun Tay (translated)',
},
'slorber',
],
title: 'Happy 1st Birthday Slash! (translated)',
},
tags: [], tags: [],
prevItem: { prevItem: {
permalink: '/blog/date-matter', permalink: '/blog/date-matter',
@ -187,6 +199,11 @@ describe('loadBlog', () => {
}, },
date: new Date('2020-08-16'), date: new Date('2020-08-16'),
formattedDate: 'August 16, 2020', formattedDate: 'August 16, 2020',
frontMatter: {
date: new Date('2020-08-16'),
slug: '/hey/my super path/héllô',
title: 'Complex Slug',
},
tags: [], tags: [],
truncated: false, truncated: false,
}); });
@ -216,6 +233,14 @@ describe('loadBlog', () => {
}, },
date: new Date('2020-08-15'), date: new Date('2020-08-15'),
formattedDate: 'August 15, 2020', formattedDate: 'August 15, 2020',
frontMatter: {
author: 'Sébastien Lorber',
author_title: 'Docusaurus maintainer',
author_url: 'https://sebastienlorber.com',
date: new Date('2020-08-15'),
slug: '/simple/slug',
title: 'Simple Slug',
},
tags: [], tags: [],
truncated: false, truncated: false,
}); });
@ -233,6 +258,9 @@ describe('loadBlog', () => {
authors: [], authors: [],
date: new Date('2019-01-02'), date: new Date('2019-01-02'),
formattedDate: 'January 2, 2019', formattedDate: 'January 2, 2019',
frontMatter: {
date: new Date('2019-01-02'),
},
prevItem: undefined, prevItem: undefined,
tags: [], tags: [],
nextItem: { nextItem: {
@ -388,6 +416,7 @@ describe('loadBlog', () => {
authors: [], authors: [],
date: noDateSourceBirthTime, date: noDateSourceBirthTime,
formattedDate, formattedDate,
frontMatter: {},
tags: [], tags: [],
prevItem: undefined, prevItem: undefined,
nextItem: undefined, nextItem: undefined,

View file

@ -234,6 +234,7 @@ async function processBlogSourceFile(
: undefined, : undefined,
truncated: truncateMarker?.test(content) || false, truncated: truncateMarker?.test(content) || false,
authors, authors,
frontMatter,
}, },
content, content,
}; };

View file

@ -43,6 +43,7 @@ declare module '@theme/BlogPostPage' {
readonly nextItem?: {readonly title: string; readonly permalink: string}; readonly nextItem?: {readonly title: string; readonly permalink: string};
readonly prevItem?: {readonly title: string; readonly permalink: string}; readonly prevItem?: {readonly title: string; readonly permalink: string};
readonly authors: import('./types').Author[]; readonly authors: import('./types').Author[];
readonly frontMatter: FrontMatter & Record<string, unknown>;
readonly tags: readonly { readonly tags: readonly {
readonly label: string; readonly label: string;
readonly permalink: string; readonly permalink: string;

View file

@ -160,6 +160,7 @@ export interface MetaData {
truncated: boolean; truncated: boolean;
editUrl?: string; editUrl?: string;
authors: Author[]; authors: Author[];
frontMatter: BlogPostFrontMatter & Record<string, unknown>;
} }
export interface Assets { export interface Assets {