From 3ee8ab4423b38baf5f1b69b39c10d170c925d28f Mon Sep 17 00:00:00 2001 From: Jake Jarvis Date: Sat, 1 Jan 2022 13:00:26 -0500 Subject: [PATCH] clean up styled JSX of colorful homepage links --- components/home/ColorLink.tsx | 24 ++++++--------- components/home/Home.module.scss | 2 +- components/notes/List.module.scss | 44 +++++++++++++++++---------- components/notes/List.tsx | 23 +++++++++++--- components/notes/ListItem.module.scss | 11 ------- components/notes/ListItem.tsx | 23 -------------- lib/parse-notes.ts | 7 ++--- pages/notes/index.tsx | 6 ++-- 8 files changed, 62 insertions(+), 78 deletions(-) delete mode 100644 components/notes/ListItem.module.scss delete mode 100644 components/notes/ListItem.tsx diff --git a/components/home/ColorLink.tsx b/components/home/ColorLink.tsx index cf13038a..b69983a7 100644 --- a/components/home/ColorLink.tsx +++ b/components/home/ColorLink.tsx @@ -23,9 +23,8 @@ export default function ColorLink({ }: Props) { external = external || isAbsoluteUrl(href); - // hacky hack to form a unique CSS var based on the light hex code, since they need to be set "globally" - const varName = `Home__${lightColor.replace("#", "")}`; - const alpha = 0.4; + // spits out an alpha color in rgb() that's compatible with linear-gradient() + const bgAlpha = (color: string) => hexRgb(color, { alpha: 0.4, format: "css" }); return ( @@ -37,20 +36,15 @@ export default function ColorLink({ rel={external ? "noopener noreferrer" : undefined} > {children} - diff --git a/components/home/Home.module.scss b/components/home/Home.module.scss index 500db376..cf59d526 100644 --- a/components/home/Home.module.scss +++ b/components/home/Home.module.scss @@ -39,7 +39,7 @@ word-spacing: -0.3em; a { - background: none; + background: none !important; padding-bottom: 0; } } diff --git a/components/notes/List.module.scss b/components/notes/List.module.scss index e7216c80..6ddce80a 100644 --- a/components/notes/List.module.scss +++ b/components/notes/List.module.scss @@ -1,22 +1,6 @@ .section { margin: 2.4em 0; - .year { - font-size: 2.2em; - margin-top: 0; - margin-bottom: 0.5em; - } - - .list { - list-style-type: none; - margin: 0; - padding: 0; - - li:last-of-type { - margin-bottom: 0; - } - } - &:first-of-type { margin-top: 0; } @@ -26,6 +10,34 @@ } } +.year { + font-size: 2.2em; + margin-top: 0; + margin-bottom: 0.5em; +} + +.list { + list-style-type: none; + margin: 0; + padding: 0; +} + +.row { + display: flex; + line-height: 1.75; + margin-bottom: 1em; + + &:last-of-type { + margin-bottom: 0; + } +} + +.date { + width: 5.25em; + flex-shrink: 0; + color: var(--medium); +} + @media screen and (max-width: 768px) { .section .year { font-size: 2em; diff --git a/components/notes/List.tsx b/components/notes/List.tsx index 1384a0c0..e6a05579 100644 --- a/components/notes/List.tsx +++ b/components/notes/List.tsx @@ -1,23 +1,38 @@ -import ListItem from "./ListItem"; +import Link from "next/link"; +import { format, parseISO } from "date-fns"; import styles from "./List.module.scss"; -export default function List({ allNotes }) { +type NoteProps = { + title: string; + date: string; + slug: string; +}; + +export default function List({ notesByYear }) { const sections = []; - Object.entries(allNotes).forEach(([year, notes]: [string, any]) => { + Object.entries(notesByYear).forEach(([year, notes]: [string, NoteProps[]]) => { sections.push(

{year}

); }); + // grouped notes enter this component ordered chronologically -- we want reverse chronological const reversed = sections.reverse(); return <>{reversed}; diff --git a/components/notes/ListItem.module.scss b/components/notes/ListItem.module.scss deleted file mode 100644 index f140bbe3..00000000 --- a/components/notes/ListItem.module.scss +++ /dev/null @@ -1,11 +0,0 @@ -.row { - display: flex; - line-height: 1.75; - margin-bottom: 1em; -} - -.date { - width: 5.25em; - flex-shrink: 0; - color: var(--medium); -} diff --git a/components/notes/ListItem.tsx b/components/notes/ListItem.tsx deleted file mode 100644 index 0de28219..00000000 --- a/components/notes/ListItem.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import Link from "next/link"; -import { format, parseISO } from "date-fns"; - -import styles from "./ListItem.module.scss"; - -export type Props = { - title: string; - date: string; - slug: string; -}; - -export default function ListItem({ title, date, slug }: Props) { - return ( -
  • - {format(parseISO(date), "MMM d")} - - - {title} - - -
  • - ); -} diff --git a/lib/parse-notes.ts b/lib/parse-notes.ts index bab68e6b..4dde7603 100644 --- a/lib/parse-notes.ts +++ b/lib/parse-notes.ts @@ -21,12 +21,9 @@ export const getNoteBySlug = (slug, fields = []) => { fields.forEach((field) => { if (field === "slug") { items[field] = realSlug; - } - if (field === "content") { + } else if (field === "content") { items[field] = content; - } - - if (typeof data[field] !== "undefined") { + } else if (typeof data[field] !== "undefined") { items[field] = data[field]; } }); diff --git a/pages/notes/index.tsx b/pages/notes/index.tsx index 95b27ac9..2c4a045f 100644 --- a/pages/notes/index.tsx +++ b/pages/notes/index.tsx @@ -6,12 +6,12 @@ import List from "../../components/notes/List"; import { getAllNotes } from "../../lib/parse-notes"; import type { GetStaticProps } from "next"; -export default function Notes({ allNotes }) { +export default function Notes({ notesByYear }) { return ( <> - + @@ -26,7 +26,7 @@ export const getStaticProps: GetStaticProps = async () => { return { props: { - allNotes: groupBy(allNotes, "year"), + notesByYear: groupBy(allNotes, "year"), }, }; };