1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-03 12:06:39 -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,6 +1,5 @@
import Link from "next/link";
import { format, parseISO } from "date-fns";
import groupBy from "lodash.groupby";
import { format } from "date-fns";
import styles from "./List.module.scss";
@ -10,18 +9,17 @@ type NoteProps = {
slug: string;
};
const List = ({ notes }) => {
const notesByYear = groupBy(notes, "year");
const List = ({ notesByYear }) => {
const sections = [];
Object.entries(notesByYear).forEach(([year, yearNotes]: [string, NoteProps[]]) => {
Object.entries(notesByYear).forEach(([year, notes]: [string, NoteProps[]]) => {
sections.push(
<section key={year} className={styles.section}>
<h2 className={styles.year}>{year}</h2>
<ul className={styles.list}>
{yearNotes.map((note) => (
{notes.map((note) => (
<li key={note.slug} className={styles.row}>
<span className={styles.date}>{format(parseISO(note.date), "MMM d")}</span>
<span className={styles.date}>{format(new Date(note.date), "MMM d")}</span>
<span>
<Link href={`/notes/${note.slug}/`} prefetch={false}>
<a>{note.title}</a>

View File

@ -1,5 +1,5 @@
import Link from "next/link";
import { format, parseISO } from "date-fns";
import { format } from "date-fns";
import Hits from "../hits/Hits";
import { DateIcon, TagIcon, EditIcon, ViewsIcon } from "../icons";
import * as config from "../../lib/config";
@ -20,8 +20,8 @@ const Meta = ({ title, date, slug, tags = [] }: Props) => (
<span>
<DateIcon className={`icon ${styles.icon}`} />
</span>
<span title={format(parseISO(date), "PPppp")}>
<Link href={`/notes/${slug}/`}>{format(parseISO(date), "MMMM d, yyyy")}</Link>
<span title={format(new Date(date), "PPppp")}>
<Link href={`/notes/${slug}/`}>{format(new Date(date), "MMMM d, yyyy")}</Link>
</span>
</div>
{tags.length > 0 && (