Files
mintel.me/apps/web/src/lib/posts.ts
Marc Mintel 6e64da48d6
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 6s
Build & Deploy / 🏗️ Build (push) Failing after 11m7s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🩺 Smoke Test (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 2s
Fix: Point posts directory to content/blog and remove truncated malformed files
2026-05-05 13:58:33 +02:00

38 lines
1.1 KiB
TypeScript

import fs from "fs";
import path from "path";
import matter from "gray-matter";
const POSTS_DIR = path.join(process.cwd(), "content/blog");
export async function getAllPosts() {
try {
if (!fs.existsSync(POSTS_DIR)) return [];
const files = fs.readdirSync(POSTS_DIR);
const posts = files
.filter((filename) => filename.endsWith(".mdx"))
.map((filename) => {
const filePath = path.join(POSTS_DIR, filename);
const fileContent = fs.readFileSync(filePath, "utf-8");
const { data, content } = matter(fileContent);
return {
title: data.title || "",
description: data.description || "",
date: data.date || new Date().toISOString(),
tags: data.tags || [],
slug: filename.replace(/\.mdx$/, ""),
thumbnail: data.thumbnail || "",
body: { code: "" },
lexicalContent: null,
mdxContent: content,
};
});
return posts.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
} catch (error) {
console.error("Error reading MDX posts:", error);
return [];
}
}