blob: 88e456640fdc9a20cef7d384ef545ba93c895996 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
import {readdirSync, readFileSync} from "fs";
import matter from "gray-matter";
export default function getPostMetadata() {
const folder = "posts/";
const files = readdirSync(folder);
const markdownPosts = files.filter((file) => file.endsWith(".md"));
return markdownPosts.map((fileName) => {
const fileContent = readFileSync(`posts/${fileName}`, "utf-8");
const matterResult = matter(fileContent);
return {
title: matterResult.data.title,
author: matterResult.data.author,
date: matterResult.data.date,
description: matterResult.data.description,
slug: fileName.replace(".md", "")
}
})
}
|