Skip to content

Commit

Permalink
Handle empty Yaml frontmatter
Browse files Browse the repository at this point in the history
Bug: #82
  • Loading branch information
samwilson authored May 4, 2024
1 parent 4f22c47 commit 3737278
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private function parseContents(): array
);
$parsedMetadata = $defaultMetadata;
}
$metadata = array_merge($defaultMetadata, $parsedMetadata);
$metadata = array_merge($defaultMetadata, $parsedMetadata ?? []);
$body = substr($contents, $frontmatterClosePos + $hyphenCount);
} else {
$metadata = $defaultMetadata;
Expand Down
5 changes: 5 additions & 0 deletions tests/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ public function provideWriting(): array
['template' => 'lorem'],
'Ipsum.',
],
'empty Yaml and no body' => [
"---\n---\n",
['template' => 'index'],
'',
],
];
}
}

0 comments on commit 3737278

Please sign in to comment.