Skip to content

Commit 5d8d16f

Browse files
benbalterCopilot
andcommitted
Polish: frosted navbar, word count, smooth TOC scroll
- Increase navbar backdrop blur to md (12px) for frosted glass effect - Add word count alongside reading time in post header metadata - Add smooth scroll + URL hash update on sidebar TOC link clicks - Auto-scroll active TOC link into view for long outlines Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 18d04c8 commit 5d8d16f

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/components/Navigation.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function isNavActive(itemUrl: string): boolean {
3737
}
3838
3939
// Base classes for navbar
40-
const baseClasses = "navbar flex flex-wrap items-center justify-between py-3 px-4 bg-gray-100/95 dark:bg-gray-800/95 backdrop-blur-sm border border-gray-200 dark:border-gray-700 shadow-sm mb-4 max-md:mb-2";
40+
const baseClasses = "navbar flex flex-wrap items-center justify-between py-3 px-4 bg-gray-100/90 dark:bg-gray-800/90 backdrop-blur-md border border-gray-200 dark:border-gray-700 shadow-sm mb-4 max-md:mb-2";
4141
4242
// Conditionally add rounded classes based on hero presence
4343
// For hero pages: round only bottom corners (top-left and top-right are 0)

src/components/TableOfContentsSidebar.astro

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const showToc = headings.length >= MIN_HEADINGS_FOR_TOC;
7878
const activeLink = linkMap.get(id);
7979
if (activeLink) {
8080
activeLink.setAttribute('data-active', 'true');
81+
activeLink.scrollIntoView({ block: 'nearest', inline: 'nearest' });
8182
}
8283
}
8384
}
@@ -124,6 +125,25 @@ const showToc = headings.length >= MIN_HEADINGS_FOR_TOC;
124125
if (el) observer.observe(el);
125126
});
126127

128+
// Smooth scroll on TOC link clicks with URL hash update
129+
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
130+
links.forEach((link) => {
131+
link.addEventListener('click', (e) => {
132+
const id = link.dataset.tocHref;
133+
if (!id) return;
134+
const heading = document.getElementById(id);
135+
if (!heading) return;
136+
137+
e.preventDefault();
138+
heading.scrollIntoView({
139+
behavior: prefersReducedMotion.matches ? 'auto' : 'smooth',
140+
block: 'start',
141+
});
142+
history.replaceState(null, '', `#${id}`);
143+
setActive(id);
144+
});
145+
});
146+
127147
// Initial highlight
128148
updateActive();
129149
}

src/layouts/PostLayout.astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ const blogPostingSchema = pubDate ? generateBlogPostingSchema({
108108
<span class="inline-flex items-center gap-1">
109109
<Icon name="clock" /> {readingTime} min read
110110
</span>
111+
<span class="mx-1.5" aria-hidden="true">·</span>
112+
<span>{(readingTime * 200).toLocaleString()} words</span>
111113
</div>
112114
)}
113115

0 commit comments

Comments
 (0)