Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions components/date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { parseISO, format } from "date-fns";

export default function Date({ dateString }) {
console.info(dateString)

const date = parseISO(dateString);
return <time dateTime={dateString}>
{format(date, 'LLLL d, yyyy')}
</time>
}
25 changes: 25 additions & 0 deletions lib/posts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from "fs";
import path from "path";
import matter from "gray-matter";
import remark from "remark";
import html from "remark-html";

const postsDirectory = path.join(process.cwd(), 'posts');

Expand Down Expand Up @@ -34,4 +36,27 @@ export function getSortedPostsData() {
return 0
}
})
}

export function getAllPostIds() {
return fs.readdirSync(postsDirectory).map(fileName => {
return {
params: {
id: fileName.replace(/\.md$/, '')
}
}
})
}

export async function getPostData(id) {
const fullPath = path.join(postsDirectory, `${id}.md`);
const fileContents = fs.readFileSync(fullPath, 'utf8')
const matterResults = matter(fileContents)

const processedContents = await remark().use(html).process(matterResults.content)
const contentHtml = processedContents.toString()

return {
id, ...matterResults.data, contentHtml
}
}
Loading