Files
indiekit-blog/_includes/components/widgets/toc.njk
svemagie 856792ebbe fix(a11y): sweep all remaining accent-600 contrast failures across all components, pages, CSS and JS
Bump all text-accent-600/dark:text-accent-400 to accent-700/300 for WCAG AA.
Bluesky brand blue fixed: #0085ff -> #0057c7 (light) / keep #0085ff (dark).
37 files changed across widgets, sections, layouts, pages, CSS and JS.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-14 15:47:09 +01:00

60 lines
2.3 KiB
Plaintext

{# Table of Contents Widget (for articles with headings) #}
<is-land on:visible>
<div class="widget">
<h3 class="widget-title">Contents</h3>
<nav class="toc" aria-label="Table of contents">
{% if toc and toc.length %}
<ul class="space-y-1 text-sm">
{% for item in toc %}
<li class="{% if item.level == 3 %}ml-3{% elif item.level == 4 %}ml-6{% elif item.level == 5 %}ml-9{% elif item.level == 6 %}ml-12{% endif %}">
<a href="#{{ item.slug }}" class="text-surface-600 dark:text-surface-400 hover:text-accent-700 dark:hover:text-accent-300 hover:underline transition-colors">
{{ item.text }}
</a>
</li>
{% endfor %}
</ul>
{% else %}
<ul class="space-y-1 text-sm" data-toc-fallback-list></ul>
<script>
(() => {
const script = document.currentScript;
if (!script) return;
const widget = script.closest(".widget");
const fallbackList = widget ? widget.querySelector("[data-toc-fallback-list]") : null;
if (!widget || !fallbackList) return;
const shell = widget.closest(".widget-collapsible");
const contentRoot = document.querySelector("article .e-content");
if (!contentRoot) {
if (shell) shell.style.display = "none";
return;
}
const headings = Array.from(contentRoot.querySelectorAll("h2[id], h3[id], h4[id], h5[id], h6[id]"));
if (!headings.length) {
if (shell) shell.style.display = "none";
return;
}
for (const heading of headings) {
const level = Number.parseInt(heading.tagName.slice(1), 10);
const item = document.createElement("li");
if (Number.isFinite(level) && level > 2) {
item.style.marginLeft = `${(level - 2) * 0.75}rem`;
}
const link = document.createElement("a");
link.href = `#${heading.id}`;
link.className = "text-surface-600 dark:text-surface-400 hover:text-accent-700 dark:hover:text-accent-300 hover:underline transition-colors";
link.textContent = heading.textContent ? heading.textContent.trim() : heading.id;
item.appendChild(link);
fallbackList.appendChild(item);
}
})();
</script>
{% endif %}
</nav>
</div>
</is-land>