mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-17 11:07:07 +02:00
feat(v2): read first heading as title and use it in front-matter (#4485)
* feat(v2): read first heading as title and pass it to front-matter * fix(v2): always trim content after extracting front-matter * fix(v2): remove heading from rss and keep duplicate heading * fix(v2): rollback some unnecessary comment changes * test(v2): add unit tests to blog * test(v2): add unit tests to docs * test(v2): correct issue on windows * test(v2): add additional test cases
This commit is contained in:
parent
fb372c574d
commit
ea13c94cc2
16 changed files with 448 additions and 35 deletions
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
date: 2019-01-02
|
||||
---
|
||||
|
||||
# some heading
|
|
@ -164,12 +164,33 @@ describe('loadBlog', () => {
|
|||
tags: [],
|
||||
truncated: false,
|
||||
});
|
||||
|
||||
expect({
|
||||
...blogPosts.find((v) => v.metadata.title === 'some heading')!.metadata,
|
||||
prevItem: undefined,
|
||||
}).toEqual({
|
||||
editUrl: `${BaseEditUrl}/blog/heading-as-title.md`,
|
||||
permalink: '/blog/heading-as-title',
|
||||
readingTime: 0,
|
||||
source: path.posix.join('@site', PluginPath, 'heading-as-title.md'),
|
||||
title: 'some heading',
|
||||
description: '',
|
||||
date: new Date('2019-01-02'),
|
||||
formattedDate: 'January 2, 2019',
|
||||
prevItem: undefined,
|
||||
tags: [],
|
||||
nextItem: {
|
||||
permalink: '/blog/date-matter',
|
||||
title: 'date-matter',
|
||||
},
|
||||
truncated: false,
|
||||
});
|
||||
});
|
||||
|
||||
test('simple website blog dates localized', async () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'website');
|
||||
const blogPostsFrench = await getBlogPosts(siteDir, {}, getI18n('fr'));
|
||||
expect(blogPostsFrench).toHaveLength(5);
|
||||
expect(blogPostsFrench).toHaveLength(6);
|
||||
expect(blogPostsFrench[0].metadata.formattedDate).toMatchInlineSnapshot(
|
||||
`"16 août 2020"`,
|
||||
);
|
||||
|
@ -180,9 +201,12 @@ describe('loadBlog', () => {
|
|||
`"27 février 2020"`,
|
||||
);
|
||||
expect(blogPostsFrench[3].metadata.formattedDate).toMatchInlineSnapshot(
|
||||
`"1 janvier 2019"`,
|
||||
`"2 janvier 2019"`,
|
||||
);
|
||||
expect(blogPostsFrench[4].metadata.formattedDate).toMatchInlineSnapshot(
|
||||
`"1 janvier 2019"`,
|
||||
);
|
||||
expect(blogPostsFrench[5].metadata.formattedDate).toMatchInlineSnapshot(
|
||||
`"14 décembre 2018"`,
|
||||
);
|
||||
});
|
||||
|
@ -212,7 +236,7 @@ describe('loadBlog', () => {
|
|||
expect(blogPost.metadata.editUrl).toEqual(hardcodedEditUrl);
|
||||
});
|
||||
|
||||
expect(editUrlFunction).toHaveBeenCalledTimes(5);
|
||||
expect(editUrlFunction).toHaveBeenCalledTimes(6);
|
||||
expect(editUrlFunction).toHaveBeenCalledWith({
|
||||
blogDirPath: 'blog',
|
||||
blogPath: 'date-matter.md',
|
||||
|
@ -243,6 +267,12 @@ describe('loadBlog', () => {
|
|||
permalink: '/blog/2018/12/14/Happy-First-Birthday-Slash',
|
||||
locale: 'en',
|
||||
});
|
||||
expect(editUrlFunction).toHaveBeenCalledWith({
|
||||
blogDirPath: 'blog',
|
||||
blogPath: 'heading-as-title.md',
|
||||
locale: 'en',
|
||||
permalink: '/blog/heading-as-title',
|
||||
});
|
||||
});
|
||||
|
||||
test('draft blog post not exists in production build', async () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue