32 lines
752 B
JavaScript
32 lines
752 B
JavaScript
import { readdirSync, readFileSync } from "fs";
|
|
import path from "path";
|
|
import fm from "front-matter";
|
|
import { stringToSlug } from "../src/lib/helpers.js";
|
|
|
|
const dirPath = "./content/writing";
|
|
|
|
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 = {
|
|
slug: stringToSlug(attributes.title),
|
|
title: attributes.title,
|
|
excerpt: attributes.desc,
|
|
date_published: attributes.pubdate,
|
|
tags: attributes.tags || [],
|
|
content: body,
|
|
};
|
|
|
|
output.push(entry);
|
|
}
|
|
|
|
console.log(JSON.stringify(output));
|