mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-02 11:47:23 +02:00
Allow for header and empty body (#127)
My hack of checking if the body was empty wasn't correct :( ```js --- id: String title: String layout: stdlib --- ``` The above would be treated as pure content. Now it's working properly :)
This commit is contained in:
parent
a794897d85
commit
5693eba5d1
1 changed files with 6 additions and 3 deletions
|
@ -72,6 +72,9 @@ function readSidebar() {
|
|||
// split markdown header
|
||||
function splitHeader(content) {
|
||||
const lines = content.split("\n");
|
||||
if (lines[0] !== "---") {
|
||||
return false;
|
||||
}
|
||||
let i = 1;
|
||||
for (; i < lines.length - 1; ++i) {
|
||||
if (lines[i] === "---") {
|
||||
|
@ -88,9 +91,8 @@ function splitHeader(content) {
|
|||
function extractMetadata(content) {
|
||||
const metadata = {};
|
||||
const both = splitHeader(content);
|
||||
// if no content returned, then that means there was no header, and both.header is the content
|
||||
if (!both.content) {
|
||||
return {metadata, rawContent: both.header};
|
||||
if (both === false) {
|
||||
return {metadata, rawContent: content};
|
||||
}
|
||||
const lines = both.header.split("\n");
|
||||
for (let i = 0; i < lines.length - 1; ++i) {
|
||||
|
@ -102,6 +104,7 @@ function extractMetadata(content) {
|
|||
} catch (e) {}
|
||||
metadata[key] = value;
|
||||
}
|
||||
|
||||
return {metadata, rawContent: both.content};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue