Skip to content

Commit

Permalink
fix: deal with annoying date stuff because YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
ericrallen committed Mar 3, 2024
1 parent 7430652 commit 8a4c040
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Post } from "@/interfaces/post";
import fs from "fs";
import matter from "gray-matter";
import { join } from "path";
import { parseISO } from "date-fns";

const postsDirectory = join(process.cwd(), "_posts");

Expand All @@ -15,6 +16,10 @@ export function getPostBySlug(slug: string) {
const fileContents = fs.readFileSync(fullPath, "utf8");
const { data, content } = matter(fileContents);

if (typeof data?.date?.toISOString !== "undefined") {
data.date = data.date.toISOString();
}

return { ...data, slug: realSlug, content } as Post;
}

Expand Down

0 comments on commit 8a4c040

Please sign in to comment.