@@ -13,35 +13,57 @@ export async function getStaticPaths() {
1313type Props = CollectionEntry <' blog' >;
1414
1515const post = Astro .props ;
16- const { Content } = await post .render ();
16+ const { Content, headings } = await post .render ();
17+ const tocHeadings = headings .filter ((heading ) => heading .depth >= 2 && heading .depth <= 3 );
1718---
1819
1920<PostHogLayout >
2021 <Layout title ={ post .data .title } description ={ post .data .description } >
21- <article class =" py-10 max-w-3xl mx-auto" >
22- <div class =" mb-10 text-center" >
23- <div class =" mb-4 text-blog-text" >
24- <time datetime ={ post .data .pubDate .toISOString ()} >
25- { post .data .pubDate .toLocaleDateString (' en-us' , {
26- year: ' numeric' ,
27- month: ' long' ,
28- day: ' numeric' ,
29- })}
30- </time >
31- </div >
32-
33- <h1 class =" text-3xl md:text-5xl font-bold mb-6 text-blog-accent leading-tight" >
34- { post .data .title }
35- </h1 >
36- <h2 >{ post .data .description } </h2 >
37- </div >
22+ <section class =" py-10 max-w-3xl mx-auto" >
23+ <article >
24+ <div class =" mb-10 text-center" >
25+ <div class =" mb-4 text-blog-text" >
26+ <time datetime ={ post .data .pubDate .toISOString ()} >
27+ { post .data .pubDate .toLocaleDateString (' en-us' , {
28+ year: ' numeric' ,
29+ month: ' long' ,
30+ day: ' numeric' ,
31+ })}
32+ </time >
33+ </div >
3834
39- <div class =" prose prose-invert prose-lg max-w-none
40- prose-headings:font-bold prose-headings:tracking-tight
41- prose-a:text-blog-link prose-a:no-underline hover:prose-a:no-underline
42- prose-img:rounded-xl prose-img:shadow-md" >
43- <Content />
44- </div >
45- </article >
35+ <h1 class =" text-3xl md:text-5xl font-bold mb-6 text-blog-accent leading-tight" >
36+ { post .data .title }
37+ </h1 >
38+ <h2 >{ post .data .description } </h2 >
39+ </div >
40+
41+ { tocHeadings .length > 0 && (
42+ <details class = " mb-8 rounded-2xl border border-blog-border bg-blog-code-bg/60 p-4" >
43+ <summary class = " cursor-pointer text-sm font-semibold uppercase tracking-wide text-blog-accent" >
44+ Table of Contents
45+ </summary >
46+ <nav class = " mt-4" >
47+ <ul class = " space-y-2 text-sm text-blog-text" >
48+ { tocHeadings .map ((heading ) => (
49+ <li class :list = { [heading .depth === 3 ? ' pl-4' : ' pl-0' ]} >
50+ <a href = { ` #${heading .slug } ` } class = " text-blog-text hover:text-blog-link transition-colors" >
51+ { heading .text }
52+ </a >
53+ </li >
54+ ))}
55+ </ul >
56+ </nav >
57+ </details >
58+ )}
59+
60+ <div class =" prose prose-invert prose-lg max-w-none
61+ prose-headings:font-bold prose-headings:tracking-tight
62+ prose-a:text-blog-link prose-a:no-underline hover:prose-a:no-underline
63+ prose-img:rounded-xl prose-img:shadow-md" >
64+ <Content />
65+ </div >
66+ </article >
67+ </section >
4668 </Layout >
47- </PostHogLayout >
69+ </PostHogLayout >
0 commit comments