Something went wrong. Try again.
My Personal Site (also at https://sammyshear.com) sshear.dev
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235---import { type CollectionEntry } from "astro:content";import Prose from "./Prose.astro";import { render } from "astro:content";
export interface Props { post: CollectionEntry<"blog">;}
const { post } = Astro.props;const { Content, headings } = await render(post);
const categoryColors: Record<string, string> = { Programming: "bg-ctp-mauve text-ctp-base", Linguistics: "bg-ctp-green text-ctp-base", Judaism: "bg-ctp-blue text-ctp-base", General: "bg-ctp-surface2 text-ctp-text"};
const categoryDotColors: Record<string, string> = { Programming: "bg-ctp-mauve", Linguistics: "bg-ctp-green", Judaism: "bg-ctp-blue", General: "bg-ctp-surface2"};
const toc = headings.filter((h: any) => h.depth >= 2 && h.depth <= 4);---
<article class="flex flex-col"> <header class="flex flex-col gap-4 mb-4"> <div class="flex flex-wrap items-center gap-3 font-sans"> { post.data.categories.map((tag) => { return ( <span class={`text-xs font-sans font-semibold px-2 py-1 rounded ${categoryColors[tag] || categoryColors.General}`} > {tag} </span> ); }) } <time class="text-sm text-ctp-subtext0" datetime={post.data.publishedTime.toISOString()} > { post.data.publishedTime.toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric" }) } </time> </div> <h1 class="text-xl md:text-2xl lg:text-3xl font-bold font-sans text-ctp-text leading-tight" > {post.data.title} </h1> <span class="text-lg text-ctp-subtext1 font-sans"> by {post.data.author} </span> </header>
{ toc.length > 0 && ( <details class="lg:hidden mb-8 bg-ctp-surface0/50 rounded-lg border border-ctp-surface0 overflow-hidden"> <summary class="px-4 py-3 cursor-pointer font-sans font-semibold text-sm text-ctp-text select-none hover:text-ctp-sky transition-colors list-none flex items-center justify-between"> <span>Table of Contents</span> <svg class="w-4 h-4 transition-transform details-open:rotate-180" fill="none" stroke="currentColor" viewBox="0 0 24 24" > <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" /> </svg> </summary> <nav class="px-4 pb-4 pt-1 border-t border-ctp-surface0"> <ul class="flex flex-col gap-1"> {toc.map((heading: any) => ( <li style={{ paddingLeft: `${(heading.depth - 2) * 1}rem` }} > <a href={`#${heading.slug}`} data-toc-link={heading.slug} class="toc-link block text-sm font-sans py-1.5 text-ctp-subtext0 hover:text-ctp-sky transition-colors" > {heading.text} </a> </li> ))} </ul> </nav> </details> ) }
<div class="flex flex-col lg:flex-row gap-12"> <div class="flex-1 min-w-0"> <Prose> <Content /> </Prose> </div>
{ toc.length > 0 && ( <aside class="hidden lg:block w-64 shrink-0"> <div class="sticky top-8 flex flex-col gap-6"> <nav class="flex flex-col gap-3"> <h2 class="text-sm font-sans font-semibold text-ctp-text uppercase tracking-wide"> Contents </h2> <ul class="flex flex-col gap-1 border-l border-ctp-surface0"> {toc.map((heading: any) => ( <li> <a href={`#${heading.slug}`} data-toc-link={heading.slug} class="toc-link block text-sm font-sans py-1 border-l -ml-px border-transparent transition-colors hover:text-ctp-sky hover:border-ctp-sky" style={{ paddingLeft: `${(heading.depth - 1) * 1}rem` }} > {heading.text} </a> </li> ))} </ul> </nav>
<div class="flex flex-col gap-3 p-4 bg-ctp-surface0/50 rounded-lg border border-ctp-surface0"> <h2 class="text-sm font-sans font-semibold text-ctp-text uppercase tracking-wide"> Details </h2> <div class="flex flex-col gap-2 text-sm font-sans text-ctp-subtext0"> <div class="flex items-center gap-2"> {post.data.categories.map((tag) => { return ( <> <span class={`w-2 h-2 rounded-full ${categoryDotColors[tag] ?? "bg-ctp-surface2"}`} /> <span>{tag}</span> </> ); })} </div> <div> {post.data.publishedTime.toLocaleDateString( "en-US", { year: "numeric", month: "long", day: "numeric" } )} </div> </div> </div> </div> </aside> ) } </div></article>
<script> (function () { const headings = document.querySelectorAll("h2[id], h3[id], h4[id]"); const tocLinks = document.querySelectorAll(".toc-link");
function setActiveLink(slug: any) { tocLinks.forEach((link) => { const isActive = link.getAttribute("data-toc-link") === slug; if (isActive) { link.classList.add("text-ctp-sky"); link.classList.remove("text-ctp-subtext0"); if (link.closest("aside")) { link.classList.add("border-ctp-sky"); link.classList.remove("border-transparent"); } } else { link.classList.remove("text-ctp-sky"); link.classList.add("text-ctp-subtext0"); if (link.closest("aside")) { link.classList.remove("border-ctp-sky"); link.classList.add("border-transparent"); } } }); }
// IntersectionObserver for scroll-based highlighting const observer = new IntersectionObserver( (entries) => { const visible = entries .filter((e) => e.isIntersecting) .sort( (a, b) => a.boundingClientRect.top - b.boundingClientRect.top );
if (visible.length > 0) { setActiveLink(visible[0].target.id); } }, { rootMargin: "-10% 0px -60% 0px", threshold: 0 } );
headings.forEach((heading) => observer.observe(heading));
// Click handlers for TOC links tocLinks.forEach((link) => { link.addEventListener("click", (_e) => { const slug = link.getAttribute("data-toc-link"); setActiveLink(slug); }); }); })();</script>