Skip to content

Commit 88e0e28

Browse files
committed
refactor: use gray-matter for parsing frontmatter
1 parent 16b012a commit 88e0e28

File tree

4 files changed

+73
-112
lines changed

4 files changed

+73
-112
lines changed

modules/standard-site-sync.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import process from 'node:process'
2-
import { readFileSync } from 'node:fs'
32
import { createHash } from 'node:crypto'
43
import { defineNuxtModule, useNuxt, createResolver } from 'nuxt/kit'
54
import { safeParse } from 'valibot'
65
import * as site from '../shared/types/lexicons/site'
76
import { BlogPostSchema } from '../shared/schemas/blog'
87
import { NPMX_SITE } from '../shared/utils/constants'
9-
import { parseBasicFrontmatter } from '../shared/utils/parse-basic-frontmatter'
8+
import { read } from 'gray-matter'
109
import { TID } from '@atproto/common'
1110
import { Client } from '@atproto/lex'
1211

@@ -77,8 +76,7 @@ export default defineNuxtModule({
7776
* WARN: DOES NOT CATCH ERRORS, THIS MUST BE HANDLED
7877
*/
7978
const syncFile = async (filePath: string, siteUrl: string, client: Client) => {
80-
const fileContent = readFileSync(filePath, 'utf-8')
81-
const frontmatter = parseBasicFrontmatter(fileContent)
79+
const { data: frontmatter } = read(filePath)
8280

8381
// Schema expects 'path' & frontmatter provides 'slug'
8482
const normalizedFrontmatter = {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"defu": "6.1.4",
7979
"fast-npm-meta": "1.0.0",
8080
"focus-trap": "^7.8.0",
81+
"gray-matter": "4.0.3",
8182
"marked": "17.0.1",
8283
"module-replacements": "2.11.0",
8384
"nuxt": "4.3.0",

pnpm-lock.yaml

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/unit/shared/utils/parse-basic-frontmatter.spec.ts

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)