23 lines
560 B
JavaScript
23 lines
560 B
JavaScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import matter from 'gray-matter'
|
|
|
|
const CONTENT_DIR = path.join(process.cwd(), 'content', 'posts')
|
|
const mdFiles = fs.readdirSync(CONTENT_DIR).filter(f => f.endsWith('.md')).sort()
|
|
|
|
let yamlOutput = '```yaml\n'
|
|
|
|
mdFiles.forEach(file => {
|
|
const p = path.join(CONTENT_DIR, file)
|
|
const data = matter(fs.readFileSync(p, 'utf8'))
|
|
let title = data.data.title || ''
|
|
|
|
// Escape quotes
|
|
title = title.replace(/'/g, "''")
|
|
|
|
yamlOutput += `${file}: '${title}'\n`
|
|
})
|
|
|
|
yamlOutput += '```\n'
|
|
console.log(yamlOutput)
|