1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-11-26 07:46:06 -05:00

CSS modules ➡️ Stitches 🧵 (#799)

This commit is contained in:
2022-03-03 09:18:26 -05:00
committed by GitHub
parent ac7ac71c10
commit c2dde042b7
93 changed files with 2392 additions and 3000 deletions

View File

@@ -1,55 +0,0 @@
.meta {
display: inline-flex;
flex-wrap: wrap;
font-size: 0.825em;
line-height: 2.3;
letter-spacing: 0.04em;
color: var(--medium);
}
.meta_item {
display: inline-flex;
margin-right: 1.6em;
white-space: nowrap;
}
.icon {
width: 1.2em;
height: 1.2em;
vertical-align: -0.2em;
margin-right: 0.6em;
}
.tags {
white-space: normal;
display: inline-flex;
flex-wrap: wrap;
}
.tag {
text-transform: lowercase;
white-space: nowrap;
margin-right: 0.75em;
}
.tag::before {
content: "\0023"; /* cosmetically hashtagify tags */
padding-right: 0.125em;
color: var(--light);
}
.tag:last-of-type {
margin-right: 0;
}
.date_link,
.edit_link {
color: inherit;
text-decoration: none;
}
.views {
/* fix potential layout shift when number of hits loads */
min-width: 7em;
margin-right: 0;
}

View File

@@ -1,73 +1,121 @@
import Link from "next/link";
import classNames from "classnames";
import { format } from "date-fns";
import HitCounter from "../HitCounter/HitCounter";
import NoteTitle from "../NoteTitle/NoteTitle";
import { DateIcon, TagIcon, EditIcon, ViewsIcon } from "../Icons";
import { styled } from "../../lib/styles/stitches.config";
import * as config from "../../lib/config";
import type { NoteType } from "../../types";
import styles from "./NoteMeta.module.css";
const Wrapper = styled("div", {
display: "inline-flex",
flexWrap: "wrap",
fontSize: "0.825em",
lineHeight: 2.3,
letterSpacing: "0.04em",
color: "$medium",
});
const MetaItem = styled("div", {
display: "inline-flex",
marginRight: "1.6em",
whiteSpace: "nowrap",
});
const MetaLink = styled("a", {
color: "inherit",
textDecoration: "none",
});
const Icon = styled("svg", {
width: "1.2em",
height: "1.2em",
verticalAlign: "-0.2em",
marginRight: "0.6em",
});
const Tag = styled("span", {
textTransform: "lowercase",
whiteSpace: "nowrap",
marginRight: "0.75em",
"&::before": {
content: "\\0023", // cosmetically hashtagify tags
paddingRight: "0.125em",
color: "$light",
},
"&:last-of-type": {
marginRight: 0,
},
});
export type NoteMetaProps = Pick<NoteType["frontMatter"], "slug" | "date" | "title" | "htmlTitle" | "tags">;
const NoteMeta = ({ slug, date, title, htmlTitle, tags = [] }: NoteMetaProps) => (
<>
<div className={styles.meta}>
<div className={styles.meta_item}>
<Wrapper>
<MetaItem>
<Link
href={{
pathname: "/notes/[slug]/",
query: { slug },
}}
passHref={true}
>
<a className={styles.date_link}>
<MetaLink>
<span>
<DateIcon className={styles.icon} />
<Icon as={DateIcon} />
</span>
<span title={format(new Date(date), "PPppp")}>{format(new Date(date), "MMMM d, yyyy")}</span>
</a>
</MetaLink>
</Link>
</div>
</MetaItem>
{tags.length > 0 && (
<div className={classNames(styles.meta_item, styles.tags)}>
<MetaItem
css={{
whiteSpace: "normal",
display: "inline-flex",
flexWrap: "wrap",
}}
>
<span>
<TagIcon className={styles.icon} />
<Icon as={TagIcon} />
</span>
{tags.map((tag) => (
<span key={tag} className={styles.tag}>
{tag}
</span>
<Tag key={tag}>{tag}</Tag>
))}
</div>
</MetaItem>
)}
<div className={styles.meta_item}>
<a
className={styles.edit_link}
<MetaItem>
<MetaLink
href={`https://github.com/${config.githubRepo}/blob/main/notes/${slug}.mdx`}
target="_blank"
rel="noopener noreferrer"
title={`Edit "${title}" on GitHub`}
>
<span>
<EditIcon className={styles.icon} />
<Icon as={EditIcon} />
</span>
<span>Improve This Post</span>
</a>
</div>
</MetaLink>
</MetaItem>
{/* only count hits on production site */}
{process.env.NEXT_PUBLIC_VERCEL_ENV === "production" && (
<div className={classNames(styles.meta_item, styles.views)}>
<MetaItem
// fix potential layout shift when number of hits loads
css={{ minWidth: "7em", marginRight: 0 }}
>
<span>
<ViewsIcon className={styles.icon} />
<Icon as={ViewsIcon} />
</span>
<HitCounter slug={`notes/${slug}`} />
</div>
</MetaItem>
)}
</div>
</Wrapper>
<NoteTitle slug={slug} htmlTitle={htmlTitle || title} />
</>