1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173 | ---
/**
* The layout for a single piece of content — a post, a photo set, a fav, an
* io issue. All four sites render individual entries through this.
*
* This is where per-article creative freedom is implemented:
*
* theme: any token from tokens.css, re-declared for this page only
* canvas: article | wide | bare
*
* `bare` gives you the tokens, the fonts and an empty page. No header, no
* footer, no prose styles, no measure. Use it when the article *is* the
* design; use `article` for the other ninety-five percent.
*/
import Base from './Base.astro';
import { formatDate, isoDate } from '../lib/format.js';
import type { SiteKey } from '../config.js';
interface Props {
site: SiteKey;
title: string;
summary: string;
path: string;
pubDate: Date;
updatedDate?: Date;
tags?: string[];
image?: string;
canvas?: 'article' | 'wide' | 'bare';
theme?: Record<string, string>;
/** Small line under the title: reading time, photo count, whatever fits. */
kicker?: string;
/** Hides the built-in title block when a page draws its own. */
showHeader?: boolean;
}
const {
site,
title,
summary,
path,
pubDate,
updatedDate,
tags = [],
image,
canvas = 'article',
theme,
kicker,
showHeader = true,
} = Astro.props;
/**
* Turn the frontmatter theme block into inline custom properties.
*
* Keys are written without the leading dashes in frontmatter (`accent`), and
* get them here. Anything that is not a plausible custom-property name is
* dropped rather than interpolated, so a typo cannot inject CSS.
*/
const themeStyle = theme
? Object.entries(theme)
.filter(([key]) => /^[a-z0-9-]+$/i.test(key))
.map(([key, value]) => `--${key}: ${String(value).replace(/[;{}]/g, '')}`)
.join('; ')
: undefined;
const bare = canvas === 'bare';
---
<Base
site={site}
title={title}
description={summary}
path={path}
image={image}
type="article"
publishedTime={pubDate}
modifiedTime={updatedDate}
chrome={!bare}
themeStyle={themeStyle}
>
<article class:list={['entry', `entry--${canvas}`]}>
{
showHeader && (
<header class="entry__header">
{kicker && <p class="eyebrow">{kicker}</p>}
<h1>{title}</h1>
<p class="meta entry__meta">
<time datetime={isoDate(pubDate)}>{formatDate(pubDate)}</time>
{updatedDate && (
<>
{' · updated '}
<time datetime={isoDate(updatedDate)}>{formatDate(updatedDate)}</time>
</>
)}
</p>
</header>
)
}
<div class:list={[!bare && 'prose', canvas === 'wide' && 'prose--wide']}>
<slot />
</div>
{
tags.length > 0 && !bare && (
<footer class="entry__tags meta">
{tags.map((tag) => (
<span class="tag">{tag}</span>
))}
</footer>
)
}
</article>
</Base>
<style>
/* The article participates in the page grid directly, so a figure inside it
can claim the wide or full track without a wrapper. */
.entry {
display: grid;
grid-column: full;
grid-template-columns: subgrid;
row-gap: 0;
}
.entry > * {
grid-column: content;
}
.entry__header {
margin-block: var(--space-xl) var(--space-l);
display: flex;
flex-direction: column;
gap: var(--space-2xs);
}
.entry__header h1 {
font-family: var(--font-prose);
font-size: var(--step-4);
font-weight: 600;
line-height: 1.08;
letter-spacing: -0.021em;
text-wrap: balance;
font-optical-sizing: auto;
}
.entry__meta {
font-variant-numeric: oldstyle-nums;
}
/* A photo essay starts in the wider track; its text still sits at the
reading measure because .prose sets its own max-inline-size. */
.entry--wide > .prose--wide {
grid-column: wide;
}
.entry--wide > .prose--wide > :not(figure, .u-wide, .u-full) {
max-inline-size: var(--measure);
}
.entry__tags {
margin-block-start: var(--space-2xl);
padding-block-start: var(--space-m);
border-block-start: 1px solid var(--rule);
display: flex;
flex-wrap: wrap;
gap: var(--space-2xs) var(--space-s);
}
.tag::before {
content: '#';
color: var(--ink-faint);
}
</style>
|