start of landing page, needs 2 intro paragraphs & links, also images

This commit is contained in:
Joshua Higgins
2025-05-25 00:59:31 -04:00
parent 30a320f049
commit a5ce703879
15 changed files with 537 additions and 123 deletions

45
src/lib/posts.ts Normal file
View File

@@ -0,0 +1,45 @@
import fs from "fs"
import path from "path"
import matter from "gray-matter"
export interface Post {
slug: string
title: string
date: string
excerpt?: string
content: string
}
const postsDirectory = path.join(process.cwd(), "posts")
export async function getPost(slug: string): Promise<Post | null> {
try {
const fullPath = path.join(postsDirectory, `${slug}.md`)
// Try .md first, then .mdx
let fileContents: string
if (fs.existsSync(fullPath)) {
fileContents = fs.readFileSync(fullPath, "utf8")
} else {
const mdxPath = path.join(postsDirectory, `${slug}.mdx`)
if (fs.existsSync(mdxPath)) {
fileContents = fs.readFileSync(mdxPath, "utf8")
} else {
return null
}
}
const { data, content } = matter(fileContents)
return {
slug,
title: data.title || slug,
date: data.date || "",
excerpt: data.excerpt || "",
content,
}
} catch (error) {
console.error("Error reading post:", error)
return null
}
}