1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-10-23 08:04:28 -04:00

consolidate mdx file parsing

This commit is contained in:
2022-01-03 17:53:47 -05:00
parent d2b71887b4
commit 3864a57d1a
9 changed files with 59 additions and 68 deletions

View File

@@ -1,23 +1,29 @@
import { format } from "date-fns";
import Layout from "../../components/Layout";
import Container from "../../components/Container";
import List from "../../components/notes/List";
import { getAllNotes } from "../../lib/parse-notes";
import type { GetStaticProps } from "next";
const Notes = ({ notes }) => (
const Notes = ({ notesByYear }) => (
<Layout>
<Container title="Notes" description="Recent posts by Jake Jarvis.">
<List notes={notes} />
<List notesByYear={notesByYear} />
</Container>
</Layout>
);
export const getStaticProps: GetStaticProps = async () => {
const notes = getAllNotes();
// parse the year of each note and group them together
const notesByYear = {};
getAllNotes().map((note) => {
const year = parseInt(format(new Date(note.date), "yyyy"));
(notesByYear[year] || (notesByYear[year] = [])).push(note);
});
return {
props: {
notes,
notesByYear,
},
};
};