1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-03 11:46:39 -04:00

simplify note parsing logic

This commit is contained in:
2022-01-02 23:05:51 -05:00
parent ca614e1a1a
commit 49fb053649
15 changed files with 164 additions and 154 deletions

View File

@ -1,5 +1,6 @@
import Link from "next/link";
import { format, parseISO } from "date-fns";
import groupBy from "lodash.groupby";
import styles from "./List.module.scss";
@ -9,15 +10,16 @@ type NoteProps = {
slug: string;
};
const List = ({ notesByYear }) => {
const List = ({ notes }) => {
const notesByYear = groupBy(notes, "year");
const sections = [];
Object.entries(notesByYear).forEach(([year, notes]: [string, NoteProps[]]) => {
Object.entries(notesByYear).forEach(([year, yearNotes]: [string, NoteProps[]]) => {
sections.push(
<section key={year} className={styles.section}>
<h2 className={styles.year}>{year}</h2>
<ul className={styles.list}>
{notes.map((note) => (
{yearNotes.map((note) => (
<li key={note.slug} className={styles.row}>
<span className={styles.date}>{format(parseISO(note.date), "MMM d")}</span>
<span>