Skip to content

Commit 1605572

Browse files
committed
feat: add automatic Table of Contents for pages\n\n- Render .TableOfContents in single template when available\n- Add basic TOC styling in main.css
1 parent 4b040a3 commit 1605572

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

assets/css/main.css

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,36 @@ blockquote > :last-child {
412412
margin-bottom: 0;
413413
}
414414

415+
/* Table of Contents */
416+
.toc {
417+
margin: var(--spacing-base) 0;
418+
padding: var(--spacing-sm);
419+
border: 1px solid var(--color-border);
420+
background: var(--color-bg-secondary);
421+
border-radius: var(--border-radius);
422+
}
423+
424+
.toc h2 {
425+
margin: 0 0 var(--spacing-sm) 0;
426+
font-weight: bold;
427+
font-size: 0.95em;
428+
}
429+
430+
.toc .toc-content ul {
431+
list-style: none;
432+
margin: 0;
433+
padding-left: 1em;
434+
}
435+
436+
.toc .toc-content a {
437+
text-decoration: none;
438+
color: var(--color-text-primary);
439+
}
440+
441+
.toc .toc-content a:hover {
442+
text-decoration: underline;
443+
}
444+
415445
@media (max-width: 600px) {
416446
.path-nav li {
417447
max-width: 100px; /* More aggressive truncation on mobile */

layouts/_default/single.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
{{ define "main" }}
22
<h1>{{ .Title }}</h1>
33
{{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }}
4+
5+
{{/* Table of Contents: render only when the page has one */}}
6+
{{ if .TableOfContents }}
7+
<nav class="toc">
8+
<h2>Table of contents</h2>
9+
<div class="toc-content">
10+
{{ .TableOfContents }}
11+
</div>
12+
</nav>
13+
{{ end }}
14+
415
{{ .Content }}
516
{{ partial "date.html" .Date}}
617

0 commit comments

Comments
 (0)