|
1 | | ---- |
2 | | -import { type CollectionEntry, getCollection } from 'astro:content'; |
3 | | -import Layout from '../../layouts/Layout.astro'; |
4 | | -import PostHogLayout from '../../layouts/PostHogLayout.astro'; |
5 | | -import { getReadingTimeLabel } from '../../utils/readingTime'; |
6 | | -
|
7 | | -export async function getStaticPaths() { |
8 | | - const posts = await getCollection('blog'); |
9 | | - return posts.map((post) => ({ |
10 | | - params: { slug: post.slug }, |
11 | | - props: post, |
12 | | - })); |
13 | | -} |
14 | | -type Props = CollectionEntry<'blog'>; |
15 | | -
|
16 | | -const post = Astro.props; |
17 | | -const { Content, headings } = await post.render(); |
18 | | -const tocHeadings = headings.filter((heading) => heading.depth >= 2 && heading.depth <= 3); |
19 | | -const readingTime = getReadingTimeLabel(post.body); |
20 | | ---- |
21 | | - |
22 | | -<PostHogLayout> |
23 | | - <Layout title={post.data.title} description={post.data.description}> |
24 | | - <div |
25 | | - data-reading-progress |
26 | | - style="transform: scaleX(0);" |
27 | | - class="fixed top-16 left-0 w-full z-50 h-[3px] bg-blog-accent origin-left" |
28 | | - ></div> |
29 | | - <section class="py-10 max-w-3xl mx-auto"> |
30 | | - <article> |
31 | | - <div class="mb-10 text-center"> |
32 | | - <div class="mb-4 text-blog-text"> |
33 | | - <time datetime={post.data.pubDate.toISOString()}> |
34 | | - {post.data.pubDate.toLocaleDateString('en-us', { |
35 | | - year: 'numeric', |
36 | | - month: 'long', |
37 | | - day: 'numeric', |
38 | | - })} |
39 | | - </time> |
40 | | - </div> |
41 | | - |
42 | | - <h1 class="text-3xl md:text-5xl font-bold mb-6 text-blog-accent leading-tight"> |
43 | | - {post.data.title} |
44 | | - </h1> |
45 | | - <h2>{post.data.description}</h2> |
46 | | - <h3 class="mx-auto mt-3 inline-flex rounded-full border border-blog-border bg-blog-code-bg/60 px-3 py-1 text-sm font-medium italic tracking-wide text-blog-link/90"> |
47 | | - {readingTime} |
48 | | - </h3> |
49 | | - </div> |
50 | | - |
51 | | - {tocHeadings.length > 0 && ( |
52 | | - <details class="mb-8 rounded-2xl border border-blog-border bg-blog-code-bg/60 p-4"> |
53 | | - <summary class="cursor-pointer text-sm font-semibold uppercase tracking-wide text-blog-accent"> |
54 | | - Table of Contents |
55 | | - </summary> |
56 | | - <nav class="mt-4"> |
57 | | - <ul class="space-y-2 text-sm text-blog-text"> |
58 | | - {tocHeadings.map((heading) => ( |
59 | | - <li class:list={[heading.depth === 3 ? 'pl-4' : 'pl-0']}> |
60 | | - <a href={`#${heading.slug}`} class="text-blog-text hover:text-blog-link transition-colors"> |
61 | | - {heading.text} |
62 | | - </a> |
63 | | - </li> |
64 | | - ))} |
65 | | - </ul> |
66 | | - </nav> |
67 | | - </details> |
68 | | - )} |
69 | | - |
70 | | - <div class="prose prose-invert prose-lg max-w-none |
71 | | - prose-headings:font-bold prose-headings:tracking-tight |
72 | | - prose-a:text-blog-link prose-a:no-underline hover:prose-a:no-underline |
73 | | - prose-img:rounded-xl prose-img:shadow-md"> |
74 | | - <Content /> |
75 | | - </div> |
76 | | - </article> |
77 | | - </section> |
78 | | - </Layout> |
79 | | -</PostHogLayout> |
| 1 | +--- |
| 2 | +import { type CollectionEntry, getCollection } from 'astro:content'; |
| 3 | +import Layout from '../../layouts/Layout.astro'; |
| 4 | +import { getReadingTimeLabel } from '../../utils/readingTime'; |
| 5 | +
|
| 6 | +export async function getStaticPaths() { |
| 7 | + const posts = await getCollection('blog'); |
| 8 | + return posts.map((post) => ({ |
| 9 | + params: { slug: post.slug }, |
| 10 | + props: post, |
| 11 | + })); |
| 12 | +} |
| 13 | +type Props = CollectionEntry<'blog'>; |
| 14 | +
|
| 15 | +const post = Astro.props; |
| 16 | +const { Content, headings } = await post.render(); |
| 17 | +const tocHeadings = headings.filter((heading) => heading.depth >= 2 && heading.depth <= 3); |
| 18 | +const readingTime = getReadingTimeLabel(post.body); |
| 19 | +--- |
| 20 | + |
| 21 | +<Layout title={post.data.title} description={post.data.description}> |
| 22 | + <div |
| 23 | + data-reading-progress |
| 24 | + style="transform: scaleX(0);" |
| 25 | + class="fixed top-16 left-0 w-full z-50 h-[3px] bg-blog-accent origin-left" |
| 26 | + ></div> |
| 27 | + <section class="py-10 max-w-3xl mx-auto"> |
| 28 | + <article> |
| 29 | + <div class="mb-10 text-center"> |
| 30 | + <div class="mb-4 text-blog-text"> |
| 31 | + <time datetime={post.data.pubDate.toISOString()}> |
| 32 | + {post.data.pubDate.toLocaleDateString('en-us', { |
| 33 | + year: 'numeric', |
| 34 | + month: 'long', |
| 35 | + day: 'numeric', |
| 36 | + })} |
| 37 | + </time> |
| 38 | + </div> |
| 39 | + |
| 40 | + <h1 class="text-3xl md:text-5xl font-bold mb-6 text-blog-accent leading-tight"> |
| 41 | + {post.data.title} |
| 42 | + </h1> |
| 43 | + <h2>{post.data.description}</h2> |
| 44 | + <h3 class="mx-auto mt-3 inline-flex rounded-full border border-blog-border bg-blog-code-bg/60 px-3 py-1 text-sm font-medium italic tracking-wide text-blog-link/90"> |
| 45 | + {readingTime} |
| 46 | + </h3> |
| 47 | + </div> |
| 48 | + |
| 49 | + {tocHeadings.length > 0 && ( |
| 50 | + <details class="mb-8 rounded-2xl border border-blog-border bg-blog-code-bg/60 p-4"> |
| 51 | + <summary class="cursor-pointer text-sm font-semibold uppercase tracking-wide text-blog-accent"> |
| 52 | + Table of Contents |
| 53 | + </summary> |
| 54 | + <nav class="mt-4"> |
| 55 | + <ul class="space-y-2 text-sm text-blog-text"> |
| 56 | + {tocHeadings.map((heading) => ( |
| 57 | + <li class:list={[heading.depth === 3 ? 'pl-4' : 'pl-0']}> |
| 58 | + <a href={`#${heading.slug}`} class="text-blog-text hover:text-blog-link transition-colors"> |
| 59 | + {heading.text} |
| 60 | + </a> |
| 61 | + </li> |
| 62 | + ))} |
| 63 | + </ul> |
| 64 | + </nav> |
| 65 | + </details> |
| 66 | + )} |
| 67 | + |
| 68 | + <div class="prose prose-invert prose-lg max-w-none |
| 69 | + prose-headings:font-bold prose-headings:tracking-tight |
| 70 | + prose-a:text-blog-link prose-a:no-underline hover:prose-a:no-underline |
| 71 | + prose-img:rounded-xl prose-img:shadow-md"> |
| 72 | + <Content /> |
| 73 | + </div> |
| 74 | + </article> |
| 75 | + </section> |
| 76 | + </Layout> |
|
0 commit comments