fix(v2): do not warn about duplicated title for pages (#4507)

This commit is contained in:
Armano 2021-03-24 12:31:26 +01:00 committed by GitHub
parent 839d9d70ba
commit 17a7ce6d0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 3 deletions

View file

@ -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`] = `
Object {
"content": "",

View file

@ -96,6 +96,23 @@ describe('load utils: parseMarkdown', () => {
).toMatchSnapshot();
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', () => {

View file

@ -276,9 +276,11 @@ export function readFrontMatter(
const heading = /^# (.*)[\n\r]?/gi.exec(result.content);
if (heading) {
if (result.data.title) {
console.warn(
`Duplicate title detected in \`${source || 'this'}\` file`,
);
if (removeTitleHeading) {
console.warn(
`Duplicate title detected in \`${source || 'this'}\` file`,
);
}
} else {
result.data.title = heading[1].trim();
if (removeTitleHeading) {