Skip to content

Commit 1622a43

Browse files
committed
Add tailwind/typography plugin for blog posts
Add 1u, 2u, etc. and 1col, 2col, etc. based on the 40px unit as a theme spacing. Add mainClass prop to BaseLayout.astro to style the container.
1 parent 6a76aef commit 1622a43

File tree

7 files changed

+99
-31
lines changed

7 files changed

+99
-31
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"@stylistic/eslint-plugin": "^4.4.0",
2424
"@stylistic/stylelint-config": "^2.0.0",
2525
"@stylistic/stylelint-plugin": "^3.1.2",
26+
"@tailwindcss/typography": "^0.5.16",
27+
"@tailwindcss/vite": "^4.1.3",
2628
"@types/react": "^19.1.5",
2729
"@types/react-dom": "^19.1.5",
2830
"@typescript-eslint/parser": "^8.32.1",

src/components/BlogListItem.astro

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
import { Image } from "astro:assets";
33
import type { CollectionEntry } from "astro:content";
4-
import DefaultThumbnail from "@/components/DefaultThumbnail.astro";
4+
import DefaultThumbnail from "./DefaultThumbnail.astro";
55
import { base, getImageAsset, formatShortMDY } from "@/utils";
66
77
interface Props {
@@ -10,7 +10,8 @@ interface Props {
1010
1111
// the thumbnail item is set to 14rem square, and the largest base font size is
1212
// 21px, so double that to support a max 2X image
13-
const ThumbnailUnits = 14;
13+
// TODO: fix this calculation to make it more generic
14+
const ThumbnailUnits = 17.5;
1415
const ThumbnailWidth = ThumbnailUnits * 21;
1516
const Thumbnail2X = 2 * ThumbnailWidth;
1617
@@ -36,10 +37,10 @@ const dateString = formatShortMDY(date);
3637
const thumbnailSize = `${ThumbnailUnits}rem`;
3738
---
3839

39-
<li class="my-6 flex flex-row gap-4">
40+
<li class="mb-2u flex flex-row gap-1u">
4041
<a href={postURL}>
4142
{thumbnailImage
42-
? <Image class="thumbnail aspect-square object-cover object-center w-56 h-56"
43+
? <Image class="thumbnail aspect-square object-cover object-center w-4col"
4344
src={thumbnailImage}
4445
alt={image_alt}
4546
widths={[Thumbnail2X]}
@@ -50,7 +51,7 @@ const thumbnailSize = `${ThumbnailUnits}rem`;
5051
</a>
5152
<div class="flex-1">
5253
<time class="block text-gray-500 mb-2 leading-none" datetime={date?.toISOString()}>{dateString}</time>
53-
<h3 class="text-xl font-semibold mb-2"><a class="text-blue-700 hover:underline" href={postURL}>{title}</a></h3>
54+
<h3 class="text-2xl font-semibold font-condensed mb-6"><a href={postURL}>{title}</a></h3>
5455
{/* descriptionHTML is formatted as a <p> tag - Tailwind prose handles paragraph styling if applied upstream */}
5556
<Fragment set:html={descriptionHTML} />
5657
</div>

src/components/HeaderNav.astro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ const routes = [
4141
</NavLink>
4242
</li>
4343
))}
44-
<li>
45-
<button class="md:hidden text-stone-800" id="mobile-menu-button">
44+
<!--
45+
<li class="md:hidden">
46+
<button class="text-stone-800" id="mobile-menu-button">
4647
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
4748
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
4849
</svg>
4950
</button>
5051
</li>
52+
-->
5153
</ul>
5254
</nav>
5355
<!-- Mobile menu -->

src/layouts/BaseLayout.astro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ interface Props {
1010
header?: string;
1111
meta?: MetadataProp;
1212
frontmatter?: CollectionEntry<"blog">["data"] | CollectionEntry<"projects">["data"];
13+
mainClass?: string;
1314
}
1415
1516
let {
1617
title = "SF Civic Tech",
1718
meta = {},
18-
frontmatter
19+
frontmatter,
20+
mainClass,
1921
} = Astro.props;
2022
2123
if (frontmatter) {
@@ -39,7 +41,7 @@ const header = Astro.props.header ?? title;
3941
meta={meta}
4042
>
4143
<HeaderNav />
42-
<main class="my-10">
44+
<main class:list={["my-2u", mainClass]}>
4345
{header &&
4446
<h1 class="text-3xl font-bold mb-8">{header}</h1>}
4547
<slot />

src/pages/blog/[slug].astro

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { Image } from "astro:assets";
33
import { render } from "astro:content";
44
import BaseLayout from "@/layouts/BaseLayout.astro";
5-
import NavLink from "@/components/NavLink.astro";
65
import { getImageAsset, formatShortMDY } from "@/utils";
76
import { getBlogPosts } from "@/content";
87
@@ -45,14 +44,15 @@ const meta = {
4544
title={title}
4645
header=""
4746
meta={meta}
47+
mainClass="max-w-8col mx-auto"
4848
>
49-
<h1 class="mb-2 text-3xl font-bold">{title}</h1>
50-
<div class="date text-sm mb-6 flex justify-between items-center">
49+
<h1 class="mb-1u text-3xl font-bold">{title}</h1>
50+
<div class="font-condensed text-sm mb-2u flex justify-between items-center">
5151
<time datetime={date?.toISOString()}>{dateString}</time>
52-
<NavLink href="/blog">All posts</NavLink>
52+
<a href="/blog">All posts</a>
5353
</div>
5454
{imageData &&
55-
<p class="mb-4">
55+
<p class="mb-1u">
5656
<Image src={imageData} alt={image_alt} />
5757
</p>}
5858
<div class="prose max-w-none">

src/styles/global.css

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import url("https://fonts.googleapis.com/css2?family=Barlow+Condensed:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Barlow:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");
22
@import "tailwindcss";
3+
@plugin "@tailwindcss/typography";
34

45
@theme {
56
--font-body: "Barlow", sans-serif;
@@ -19,18 +20,33 @@
1920
--text-4xl: 3rem; /* 48px */
2021
--text-5xl: 3.75rem; /* 60px */
2122
--text-6xl: 4.5rem; /* 72px */
23+
24+
--spacing-1u: var(--unit);
25+
--spacing-2u: calc(var(--unit) * 2);
26+
--spacing-3u: calc(var(--unit) * 3);
27+
--spacing-4u: calc(var(--unit) * 4);
28+
--spacing-5u: calc(var(--unit) * 5);
29+
--spacing-6u: calc(var(--unit) * 6);
30+
--spacing-7u: calc(var(--unit) * 7);
31+
--spacing-8u: calc(var(--unit) * 8);
32+
33+
--spacing-1col: calc(var(--unit) * (1 * 2 - 1));
34+
--spacing-2col: calc(var(--unit) * (2 * 2 - 1));
35+
--spacing-3col: calc(var(--unit) * (3 * 2 - 1));
36+
--spacing-4col: calc(var(--unit) * (4 * 2 - 1));
37+
--spacing-5col: calc(var(--unit) * (5 * 2 - 1));
38+
--spacing-6col: calc(var(--unit) * (6 * 2 - 1));
39+
--spacing-7col: calc(var(--unit) * (7 * 2 - 1));
40+
--spacing-8col: calc(var(--unit) * (8 * 2 - 1));
41+
--spacing-9col: calc(var(--unit) * (9 * 2 - 1));
42+
--spacing-10col: calc(var(--unit) * (10 * 2 - 1));
2243
}
2344

2445
@layer base {
2546
:root {
26-
/* Colors */
2747
--color-sf-red: #f22613;
28-
/*
29-
--color-sf-blue: #67b4f5;
30-
--color-sf-purple: #c05f9a;
31-
--color-sf-navy: #323266;
32-
--color-sf-cream: #f7efde;
33-
*/
48+
49+
--unit: 40px;
3450
}
3551

3652
html {
@@ -56,6 +72,34 @@
5672
background-color: var(--color-background-base);
5773
}
5874

75+
main::before {
76+
--col-color: rgba(255, 0, 0, 0.03);
77+
--col-size: 40px;
78+
content: "";
79+
position: absolute;
80+
top: 0;
81+
left: 0;
82+
width: 100%;
83+
height: 100%;
84+
pointer-events: none;
85+
background-image:
86+
repeating-linear-gradient(
87+
to right,
88+
var(--col-color) 0,
89+
var(--col-color) var(--col-size),
90+
transparent var(--col-size),
91+
transparent calc(var(--col-size) * 2)
92+
);
93+
background-size: 80px 100%;
94+
z-index: 1;
95+
display: none;
96+
}
97+
98+
main {
99+
position: relative;
100+
z-index: 2;
101+
}
102+
59103
p {
60104
@apply mb-4;
61105
}
@@ -68,7 +112,7 @@
68112
duration-300
69113
ease-out
70114
underline-offset-[.2rem]
71-
decoration-primary/25
115+
decoration-primary/20
72116
hover:decoration-primary;
73117
}
74118
}
@@ -82,4 +126,23 @@
82126
display: none;
83127
}
84128
}
129+
130+
.prose {
131+
line-height: revert;
132+
133+
/*
134+
a {
135+
*/
136+
a:where(a:not([role=button])), [role=link] {
137+
color: var(--color-sf-red);
138+
@apply underline
139+
font-semibold
140+
transition
141+
duration-300
142+
ease-out
143+
underline-offset-[.2rem]
144+
decoration-primary/20
145+
hover:decoration-primary;
146+
}
147+
}
85148
}

tailwind.config.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
/** @type {import('tailwindcss').Config} */
1+
/** @type {import("tailwindcss").Config} */
2+
import typography from "@tailwindcss/typography";
3+
24
export default {
3-
content: ["./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}"],
4-
theme: {
5-
extend: {
6-
// Theme extensions are now primarily handled via CSS variables in global.css
7-
// Keep this extend block if you have other non-variable extensions or plugins need it.
8-
},
9-
},
10-
plugins: [],
5+
content: ["./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}"],
6+
plugins: [
7+
typography
8+
],
119
};

0 commit comments

Comments
 (0)