import { readdirSync, readFileSync } from 'fs' import path from 'path' import fm from 'front-matter' const dirPath = './content/books' const output = [] const files = readdirSync(dirPath) for (const file of files) { const filePath = path.join(dirPath, file) const content = readFileSync(filePath, { encoding: 'utf-8' }) const { attributes, body } = fm(content, { allowUnsafe: true }) const entry = { title: attributes.title, author: attributes.author, read_date: attributes.readDate, rating: Math.round(attributes.stars * 2), // "image": attributes.thumbnailUrl, tags: attributes.tags.split(', '), review: body, url: attributes.url } output.push(entry) } console.log(JSON.stringify(output))