mirror of
https://github.com/joelhooks/joelclaw.git
synced 2026-09-19 01:24:04 +08:00
5b39e347a5
- Fix wrong dates: inngest + peter articles were Feb 14, not Feb 15 - Add 'updated' frontmatter field + rendering in article detail page - ADR index: status counts are now clickable filter pills with glow effect - Click a status to filter, click again to clear - Filters via searchParams (server-side, no client JS)
73 lines
1.8 KiB
TypeScript
73 lines
1.8 KiB
TypeScript
import fs from "fs";
|
|
import path from "path";
|
|
import matter from "gray-matter";
|
|
|
|
export type ContentType = "article" | "note";
|
|
|
|
export type PostMeta = {
|
|
title: string;
|
|
date: string;
|
|
updated?: string;
|
|
description: string;
|
|
slug: string;
|
|
type: ContentType;
|
|
source?: string;
|
|
channel?: string;
|
|
duration?: string;
|
|
};
|
|
|
|
const contentDir = path.join(process.cwd(), "content");
|
|
|
|
export function getAllPosts(): PostMeta[] {
|
|
const files = fs.readdirSync(contentDir).filter((f) => f.endsWith(".mdx"));
|
|
|
|
return files
|
|
.map((filename) => {
|
|
const raw = fs.readFileSync(path.join(contentDir, filename), "utf-8");
|
|
const { data } = matter(raw);
|
|
|
|
return {
|
|
title: data.title ?? "Untitled",
|
|
date: data.date ?? "",
|
|
updated: data.updated,
|
|
description: data.description ?? "",
|
|
slug: filename.replace(/\.mdx$/, ""),
|
|
type: (data.type as ContentType) ?? "article",
|
|
source: data.source,
|
|
channel: data.channel,
|
|
duration: data.duration,
|
|
};
|
|
})
|
|
.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
|
|
}
|
|
|
|
export function getPost(slug: string) {
|
|
const filePath = path.join(contentDir, `${slug}.mdx`);
|
|
if (!fs.existsSync(filePath)) return null;
|
|
|
|
const raw = fs.readFileSync(filePath, "utf-8");
|
|
const { data, content } = matter(raw);
|
|
|
|
return {
|
|
meta: {
|
|
title: data.title ?? "Untitled",
|
|
date: data.date ?? "",
|
|
updated: data.updated,
|
|
description: data.description ?? "",
|
|
slug,
|
|
type: (data.type as ContentType) ?? "article",
|
|
source: data.source,
|
|
channel: data.channel,
|
|
duration: data.duration,
|
|
} satisfies PostMeta,
|
|
content,
|
|
};
|
|
}
|
|
|
|
export function getPostSlugs(): string[] {
|
|
return fs
|
|
.readdirSync(contentDir)
|
|
.filter((f) => f.endsWith(".mdx"))
|
|
.map((f) => f.replace(/\.mdx$/, ""));
|
|
}
|