1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-04-27 15:16:21 -04:00

clean up styled JSX of colorful homepage links

This commit is contained in:
Jake Jarvis 2022-01-01 13:00:26 -05:00
parent c420967b4c
commit 3ee8ab4423
Signed by: jake
GPG Key ID: 2B0C9CF251E69A39
8 changed files with 62 additions and 78 deletions

View File

@ -23,9 +23,8 @@ export default function ColorLink({
}: Props) { }: Props) {
external = external || isAbsoluteUrl(href); 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" // spits out an alpha color in rgb() that's compatible with linear-gradient()
const varName = `Home__${lightColor.replace("#", "")}`; const bgAlpha = (color: string) => hexRgb(color, { alpha: 0.4, format: "css" });
const alpha = 0.4;
return ( return (
<Link href={href} passHref={true} prefetch={false}> <Link href={href} passHref={true} prefetch={false}>
@ -37,20 +36,15 @@ export default function ColorLink({
rel={external ? "noopener noreferrer" : undefined} rel={external ? "noopener noreferrer" : undefined}
> >
{children} {children}
<style jsx global>{`
:root {
--${varName}: ${lightColor};
--${varName}_alpha: ${hexRgb(lightColor, { alpha: alpha, format: "css" })};
}
[data-theme="dark"] {
--${varName}: ${darkColor};
--${varName}_alpha: ${hexRgb(darkColor, { alpha: alpha, format: "css" })};
}
`}</style>
<style jsx>{` <style jsx>{`
a { a {
color: var(--${varName}); color: ${lightColor};
background-image: linear-gradient(var(--${varName}_alpha), var(--${varName}_alpha)); background-image: linear-gradient(${bgAlpha(lightColor)}, ${bgAlpha(lightColor)});
}
:global([data-theme="dark"]) a {
color: ${darkColor};
background-image: linear-gradient(${bgAlpha(darkColor)}, ${bgAlpha(darkColor)});
} }
`}</style> `}</style>
</a> </a>

View File

@ -39,7 +39,7 @@
word-spacing: -0.3em; word-spacing: -0.3em;
a { a {
background: none; background: none !important;
padding-bottom: 0; padding-bottom: 0;
} }
} }

View File

@ -1,22 +1,6 @@
.section { .section {
margin: 2.4em 0; 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 { &:first-of-type {
margin-top: 0; 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) { @media screen and (max-width: 768px) {
.section .year { .section .year {
font-size: 2em; font-size: 2em;

View File

@ -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"; 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 = []; const sections = [];
Object.entries(allNotes).forEach(([year, notes]: [string, any]) => { Object.entries(notesByYear).forEach(([year, notes]: [string, NoteProps[]]) => {
sections.push( sections.push(
<section key={year} className={styles.section}> <section key={year} className={styles.section}>
<h2 className={styles.year}>{year}</h2> <h2 className={styles.year}>{year}</h2>
<ul className={styles.list}> <ul className={styles.list}>
{notes.map((note) => ( {notes.map((note) => (
<ListItem key={note.slug} title={note.title} date={note.date} slug={note.slug} /> <li key={note.slug} className={styles.row}>
<span className={styles.date}>{format(parseISO(note.date), "MMM d")}</span>
<span>
<Link href={`/notes/${note.slug}/`} prefetch={false}>
<a>{note.title}</a>
</Link>
</span>
</li>
))} ))}
</ul> </ul>
</section> </section>
); );
}); });
// grouped notes enter this component ordered chronologically -- we want reverse chronological
const reversed = sections.reverse(); const reversed = sections.reverse();
return <>{reversed}</>; return <>{reversed}</>;

View File

@ -1,11 +0,0 @@
.row {
display: flex;
line-height: 1.75;
margin-bottom: 1em;
}
.date {
width: 5.25em;
flex-shrink: 0;
color: var(--medium);
}

View File

@ -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 (
<li className={styles.row}>
<span className={styles.date}>{format(parseISO(date), "MMM d")}</span>
<span>
<Link href={`/notes/${slug}/`} prefetch={false}>
<a>{title}</a>
</Link>
</span>
</li>
);
}

View File

@ -21,12 +21,9 @@ export const getNoteBySlug = (slug, fields = []) => {
fields.forEach((field) => { fields.forEach((field) => {
if (field === "slug") { if (field === "slug") {
items[field] = realSlug; items[field] = realSlug;
} } else if (field === "content") {
if (field === "content") {
items[field] = content; items[field] = content;
} } else if (typeof data[field] !== "undefined") {
if (typeof data[field] !== "undefined") {
items[field] = data[field]; items[field] = data[field];
} }
}); });

View File

@ -6,12 +6,12 @@ import List from "../../components/notes/List";
import { getAllNotes } from "../../lib/parse-notes"; import { getAllNotes } from "../../lib/parse-notes";
import type { GetStaticProps } from "next"; import type { GetStaticProps } from "next";
export default function Notes({ allNotes }) { export default function Notes({ notesByYear }) {
return ( return (
<> <>
<Layout> <Layout>
<Container title="Notes" description="Recent posts by Jake Jarvis."> <Container title="Notes" description="Recent posts by Jake Jarvis.">
<List allNotes={allNotes} /> <List notesByYear={notesByYear} />
</Container> </Container>
</Layout> </Layout>
</> </>
@ -26,7 +26,7 @@ export const getStaticProps: GetStaticProps = async () => {
return { return {
props: { props: {
allNotes: groupBy(allNotes, "year"), notesByYear: groupBy(allNotes, "year"),
}, },
}; };
}; };