mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-04 04:37:28 +02:00
fix(v2): do not warn about duplicated title for pages (#4507)
This commit is contained in:
parent
839d9d70ba
commit
17a7ce6d0d
3 changed files with 33 additions and 3 deletions
|
@ -81,6 +81,17 @@ Object {
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`load utils: parseMarkdown readFrontMatter should not warn about duplicated title 1`] = `
|
||||||
|
Object {
|
||||||
|
"content": "# test",
|
||||||
|
"excerpt": "",
|
||||||
|
"frontMatter": Object {
|
||||||
|
"title": "title",
|
||||||
|
},
|
||||||
|
"hasFrontMatter": true,
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`load utils: parseMarkdown readFrontMatter should parse first heading as title 1`] = `
|
exports[`load utils: parseMarkdown readFrontMatter should parse first heading as title 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"content": "",
|
"content": "",
|
||||||
|
|
|
@ -96,6 +96,23 @@ describe('load utils: parseMarkdown', () => {
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
expect(warn).not.toBeCalled();
|
expect(warn).not.toBeCalled();
|
||||||
});
|
});
|
||||||
|
test('should not warn about duplicated title', () => {
|
||||||
|
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
||||||
|
expect(
|
||||||
|
readFrontMatter(
|
||||||
|
dedent`
|
||||||
|
---
|
||||||
|
title: title
|
||||||
|
---
|
||||||
|
# test
|
||||||
|
`,
|
||||||
|
undefined,
|
||||||
|
{},
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
).toMatchSnapshot();
|
||||||
|
expect(warn).not.toBeCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('parseMarkdownString', () => {
|
describe('parseMarkdownString', () => {
|
||||||
|
|
|
@ -276,9 +276,11 @@ export function readFrontMatter(
|
||||||
const heading = /^# (.*)[\n\r]?/gi.exec(result.content);
|
const heading = /^# (.*)[\n\r]?/gi.exec(result.content);
|
||||||
if (heading) {
|
if (heading) {
|
||||||
if (result.data.title) {
|
if (result.data.title) {
|
||||||
console.warn(
|
if (removeTitleHeading) {
|
||||||
`Duplicate title detected in \`${source || 'this'}\` file`,
|
console.warn(
|
||||||
);
|
`Duplicate title detected in \`${source || 'this'}\` file`,
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
result.data.title = heading[1].trim();
|
result.data.title = heading[1].trim();
|
||||||
if (removeTitleHeading) {
|
if (removeTitleHeading) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue