-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBlogPostLayout.astro
More file actions
296 lines (269 loc) · 13.7 KB
/
BlogPostLayout.astro
File metadata and controls
296 lines (269 loc) · 13.7 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
---
import BaseLayout from "./BaseLayout.astro";
import { formatDate, slugify, withBase } from "../lib/utils";
interface Reference {
type: string;
label: string;
url: string;
}
interface Props {
title: string;
publishDate: string;
updatedDate?: string | null;
author: string;
description?: string | null;
tags?: readonly string[];
slug?: string;
legacyUrl?: string | null;
references?: Reference[];
}
const isDev = import.meta.env.DEV;
const { title, publishDate, updatedDate, author, description, tags, slug, legacyUrl, references = [] } = Astro.props;
const bloggerUrl = legacyUrl ? `https://pythoninsider.blogspot.com${legacyUrl}` : null;
// Group references by type
const refGroups = new Map<string, Reference[]>();
for (const ref of references) {
if (!refGroups.has(ref.type)) refGroups.set(ref.type, []);
refGroups.get(ref.type)!.push(ref);
}
const groupMeta: Record<string, { label: string; order: number }> = {
"pep": { label: "PEPs", order: 0 },
"docs": { label: "Documentation", order: 1 },
"gh-repo": { label: "Repositories", order: 2 },
"gh-user": { label: "People", order: 3 },
"pypi": { label: "Packages", order: 4 },
};
const sortedGroups = [...refGroups.entries()]
.sort((a, b) => (groupMeta[a[0]]?.order ?? 99) - (groupMeta[b[0]]?.order ?? 99));
---
<BaseLayout title={`${title} | Python Insider`} description={description ?? undefined} image={slug ? withBase(`/og/${slug}.png`) : undefined}>
<div class="relative mx-auto flex max-w-6xl gap-10">
<article class="prose mx-auto min-w-0 max-w-3xl flex-1">
<header class="not-prose mb-10 animate-fade-up">
<div class="flex items-start justify-between gap-4">
<div class="min-w-0 flex-1">
<h1 class="text-3xl font-bold leading-tight text-zinc-900 dark:text-zinc-100 sm:text-4xl" style="font-family: var(--font-display); letter-spacing: -0.02em;">
{title}
</h1>
</div>
{isDev && slug && (
<a
href={withBase(`/keystatic/collection/posts/item/${slug}`)}
class="edit-btn-always mt-2 flex-shrink-0 rounded-lg bg-zinc-100 p-2.5 text-zinc-400 hover:bg-amber-100 hover:text-amber-700 dark:bg-zinc-800 dark:text-zinc-600 dark:hover:bg-amber-900/30 dark:hover:text-amber-400"
title="Edit in Keystatic"
>
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" />
</svg>
</a>
)}
</div>
<div class="mt-4 flex flex-wrap items-center gap-x-3 gap-y-1 text-sm text-zinc-500 dark:text-zinc-400">
<a href={withBase(`/authors/${slugify(author)}`)} class="font-medium text-zinc-800 hover:text-[#306998] dark:text-zinc-200 dark:hover:text-[#ffd43b] transition-colors">{author}</a>
<span class="text-zinc-300 dark:text-zinc-600">/</span>
<time datetime={publishDate}>{formatDate(publishDate)}</time>
{updatedDate && (
<>
<span class="text-zinc-300 dark:text-zinc-600">·</span>
<span class="text-xs">Updated <time datetime={updatedDate}>{formatDate(updatedDate)}</time></span>
</>
)}
</div>
{tags && tags.length > 0 && (
<div class="mt-5 flex flex-wrap gap-1.5">
{tags.map((tag) => (
<a
href={withBase(`/tags/${tag}`)}
class="tag-pill rounded-md bg-zinc-100 px-2.5 py-1 text-xs font-medium text-zinc-600 dark:bg-zinc-700/60 dark:text-zinc-300"
>
{tag}
</a>
))}
</div>
)}
<div class="mt-8 h-px" style="background: linear-gradient(to right, rgba(48, 105, 152, 0.3), rgba(255, 212, 59, 0.2), transparent);"></div>
</header>
<div class="animate-fade-up stagger-1">
<slot />
</div>
<!-- Blogger legacy notice -->
{bloggerUrl && (
<div class="not-prose mt-6">
<a
href={bloggerUrl}
target="_blank"
rel="noopener noreferrer"
class="flex items-center gap-3 rounded-lg border border-orange-200/60 bg-gradient-to-r from-orange-50 to-amber-50/50 px-4 py-3 transition-colors hover:border-orange-300/80 hover:from-orange-50 hover:to-amber-50 dark:border-orange-800/30 dark:from-orange-950/20 dark:to-amber-950/10 dark:hover:border-orange-700/40 dark:hover:from-orange-950/30 dark:hover:to-amber-950/20"
>
<div class="flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full bg-orange-100 dark:bg-orange-900/30">
<svg class="h-4 w-4 text-orange-500 dark:text-orange-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 8v4l3 3" />
<circle cx="12" cy="12" r="10" />
</svg>
</div>
<div class="min-w-0 flex-1">
<p class="text-xs font-medium text-orange-800 dark:text-orange-300">Originally published on Blogger</p>
<p class="mt-0.5 truncate text-[11px] text-orange-600/70 dark:text-orange-400/50">{bloggerUrl}</p>
</div>
<svg class="h-4 w-4 flex-shrink-0 text-orange-400 dark:text-orange-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
</svg>
</a>
</div>
)}
<footer class="not-prose mt-16">
<!-- Navigation -->
<div class="flex items-center justify-between border-t border-zinc-200 pt-6 dark:border-zinc-700">
<a
href={withBase("/blog")}
class="group inline-flex items-center gap-2 text-sm font-medium text-[#306998] transition-colors hover:text-[#254f73] dark:text-[#ffd43b] dark:hover:text-[#f0c419]"
>
<span class="transition-transform group-hover:-translate-x-0.5">←</span>
Back to all posts
</a>
{isDev && slug && (
<a
href={withBase(`/keystatic/collection/posts/item/${slug}`)}
class="inline-flex items-center gap-1.5 rounded-lg bg-zinc-100 px-3 py-1.5 text-xs font-medium text-zinc-500 transition-colors hover:bg-amber-100 hover:text-amber-700 dark:bg-zinc-800 dark:text-zinc-400 dark:hover:bg-amber-900/30 dark:hover:text-amber-400"
>
<svg class="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" />
</svg>
Edit post
</a>
)}
</div>
</footer>
</article>
<!-- Sidebar: ToC + References -->
<aside class="hidden w-56 flex-shrink-0 xl:block">
<div class="sticky top-24 space-y-6">
<!-- Table of Contents -->
<nav id="toc" class="toc-nav">
<div class="toc-header mb-3 flex items-center gap-2">
<svg class="h-3.5 w-3.5 text-[#306998] dark:text-[#ffd43b]" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="8" y1="6" x2="21" y2="6" /><line x1="8" y1="12" x2="21" y2="12" /><line x1="8" y1="18" x2="21" y2="18" /><line x1="3" y1="6" x2="3.01" y2="6" /><line x1="3" y1="12" x2="3.01" y2="12" /><line x1="3" y1="18" x2="3.01" y2="18" />
</svg>
<span class="text-[11px] font-bold uppercase tracking-[0.1em] text-zinc-400 dark:text-zinc-500" style="font-family: var(--font-display);">On this page</span>
</div>
<ul id="toc-list" class="toc-list space-y-0.5"></ul>
</nav>
<!-- References (sidebar, collapsed by default) -->
{sortedGroups.length > 0 && (
<details class="sidebar-refs group/refs">
<summary class="mb-3 flex cursor-pointer list-none items-center gap-2 [&::-webkit-details-marker]:hidden">
<svg class="h-3.5 w-3.5 text-[#306998] dark:text-[#ffd43b]" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20" />
</svg>
<span class="text-[11px] font-bold uppercase tracking-[0.1em] text-zinc-400 dark:text-zinc-500" style="font-family: var(--font-display);">
References
</span>
<span class="ml-auto flex items-center gap-1.5 text-[10px] tabular-nums font-medium text-zinc-400 dark:text-zinc-500">
{references.length}
<svg class="h-3 w-3 transition-transform group-open/refs:rotate-90" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6"/></svg>
</span>
</summary>
<div class="space-y-3">
{sortedGroups.map(([type, refs]) => (
<div>
<div class="mb-1.5 text-[10px] font-bold uppercase tracking-[0.12em] text-zinc-400 dark:text-zinc-500">
{groupMeta[type]?.label ?? type}
</div>
<div class="flex flex-wrap gap-1">
{refs.map((ref) => (
<a
href={ref.url}
class:list={[
"ref-footer-chip group inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-[11px] font-medium transition-all",
type === "pep" && "bg-amber-50 text-amber-800 hover:bg-amber-100 dark:bg-amber-900/20 dark:text-amber-300 dark:hover:bg-amber-900/40",
type === "docs" && "bg-blue-50 text-blue-700 hover:bg-blue-100 dark:bg-blue-900/20 dark:text-blue-300 dark:hover:bg-blue-900/40",
type === "gh-repo" && "bg-zinc-100 text-zinc-700 hover:bg-zinc-200 dark:bg-zinc-800 dark:text-zinc-300 dark:hover:bg-zinc-700",
type === "gh-user" && "bg-zinc-100 text-zinc-700 hover:bg-zinc-200 dark:bg-zinc-800 dark:text-zinc-300 dark:hover:bg-zinc-700",
type === "pypi" && "bg-emerald-50 text-emerald-700 hover:bg-emerald-100 dark:bg-emerald-900/20 dark:text-emerald-300 dark:hover:bg-emerald-900/40",
]}
target="_blank"
rel="noopener noreferrer"
>
<span class="truncate max-w-[140px]">{ref.label}</span>
<svg class="h-2 w-2 opacity-0 transition-opacity group-hover:opacity-50" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path d="M7 7h10v10"/><path d="M7 17 17 7"/></svg>
</a>
))}
</div>
</div>
))}
</div>
</details>
)}
</div>
</aside>
</div>
<script>
function initToc() {
const article = document.querySelector('article.prose');
const tocList = document.getElementById('toc-list');
const tocNav = document.getElementById('toc');
if (!article || !tocList || !tocNav) return;
// Clear previous ToC (for Astro page transitions)
tocList.innerHTML = '';
const headings = article.querySelectorAll('h2, h3, h4');
if (headings.length === 0) {
tocNav.style.display = 'none';
return;
}
tocNav.style.display = '';
// Build ToC
headings.forEach((heading) => {
if (!heading.id) {
heading.id = heading.textContent!.trim()
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/(^-|-$)/g, '');
}
const li = document.createElement('li');
const a = document.createElement('a');
a.href = `#${heading.id}`;
a.textContent = heading.textContent!.trim();
a.className = 'toc-link';
if (heading.tagName === 'H3') {
a.classList.add('toc-link-h3');
} else if (heading.tagName === 'H4') {
a.classList.add('toc-link-h4');
}
a.addEventListener('click', (e) => {
e.preventDefault();
heading.scrollIntoView({ behavior: 'smooth' });
history.replaceState(null, '', `#${heading.id}`);
});
li.appendChild(a);
tocList.appendChild(li);
});
// IntersectionObserver for active heading
const links = tocList.querySelectorAll('.toc-link');
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const id = entry.target.id;
links.forEach((link) => {
if (link.getAttribute('href') === `#${id}`) {
link.classList.add('toc-active');
} else {
link.classList.remove('toc-active');
}
});
}
});
},
{ rootMargin: '0px 0px -70% 0px' }
);
headings.forEach((heading) => observer.observe(heading));
// Set first as active by default
if (links.length > 0) {
links[0].classList.add('toc-active');
}
}
// Run on page load and Astro page transitions
initToc();
document.addEventListener('astro:after-swap', initToc);
</script>
</BaseLayout>