File tree Expand file tree Collapse file tree 1 file changed +8
-10
lines changed
src/lib/services/contents/file Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,8 @@ export const parseEntryFile = async ({
6060 parserConfig : { extension, format, frontmatterDelimiter } ,
6161 } ,
6262} ) => {
63- text = text . trim ( ) ;
63+ // Normalize line breaks
64+ text = text . trim ( ) . replace ( / \r \n ? / g, '\n' ) ;
6465
6566 format ||= /** @type {FileFormat | undefined } */ (
6667 [ 'md' , 'markdown' ] . includes ( extension ?? '' ) || path . match ( / \. (?: m d | m a r k d o w n ) $ / )
@@ -98,16 +99,13 @@ export const parseEntryFile = async ({
9899
99100 if ( format . match ( / ^ (?: y a m l | t o m l | j s o n ) - f r o n t m a t t e r $ / ) ) {
100101 const [ startDelimiter , endDelimiter ] = getFrontMatterDelimiters ( format , frontmatterDelimiter ) ;
102+ const sd = escapeRegExp ( startDelimiter ) ;
103+ const ed = escapeRegExp ( endDelimiter ) ;
104+ // Front matter matching: allow an empty head
105+ const regex = new RegExp ( `^${ sd } $\\n(?:(?<head>.*?)$\\n)?${ ed } $(?:\\n(?<body>.+))?` , 'ms' ) ;
106+ const { head, body } = text . match ( regex ) ?. groups ?? { } ;
101107
102- const [ , head , body = '' ] =
103- text . match (
104- new RegExp (
105- `^${ escapeRegExp ( startDelimiter ) } \\n(.+?)\\n${ escapeRegExp ( endDelimiter ) } (?:\\n(.+))?` ,
106- 'ms' ,
107- ) ,
108- ) ?? [ ] ;
109-
110- if ( ! head ) {
108+ if ( ! head && ! body ) {
111109 throw new Error ( 'No front matter block found' ) ;
112110 }
113111
You can’t perform that action at this time.
0 commit comments