Skip to content

Commit

Permalink
fix(frontmatter): remove dangling CR
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Jan 6, 2025
1 parent faa8dd7 commit 9f07da0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as flat from 'flat'

const FRONTMATTER_DELIMITER_DEFAULT = '---'
const FRONTMATTER_DELIMITER_CODEBLOCK_STYLE = '```yaml [props]'
const LF = '\n'
const CR = '\r'

export function stringifyFrontMatter(data: any, content = '') {
if (!Object.keys(data).length) {
Expand Down Expand Up @@ -43,8 +45,11 @@ export function stringifyCodeBlockProps(data: any, content = '') {
export function parseFrontMatter(content: string) {
let data: any = {}
if (content.startsWith(FRONTMATTER_DELIMITER_DEFAULT)) {
const idx = content.indexOf('\n' + FRONTMATTER_DELIMITER_DEFAULT)
let idx = content.indexOf(LF + FRONTMATTER_DELIMITER_DEFAULT)
if (idx !== -1) {
if (content[idx - 1] === CR) {
idx -= 1
}
const frontmatter = content.slice(4, idx)
if (frontmatter) {
data = parse(frontmatter)
Expand Down

0 comments on commit 9f07da0

Please sign in to comment.