diff --git a/src/img/2026/tree-styling-0.png b/src/img/2026/tree-styling-0.png new file mode 100644 index 00000000..cced6f91 Binary files /dev/null and b/src/img/2026/tree-styling-0.png differ diff --git a/src/img/2026/tree-styling-1.png b/src/img/2026/tree-styling-1.png new file mode 100644 index 00000000..c6cd3e7c Binary files /dev/null and b/src/img/2026/tree-styling-1.png differ diff --git a/src/img/2026/tree-styling-2.png b/src/img/2026/tree-styling-2.png new file mode 100644 index 00000000..ff8a271f Binary files /dev/null and b/src/img/2026/tree-styling-2.png differ diff --git a/src/img/2026/tree-styling-3.png b/src/img/2026/tree-styling-3.png new file mode 100644 index 00000000..07f1aa9a Binary files /dev/null and b/src/img/2026/tree-styling-3.png differ diff --git a/src/img/2026/tree-styling-4.png b/src/img/2026/tree-styling-4.png new file mode 100644 index 00000000..fbfa05d4 Binary files /dev/null and b/src/img/2026/tree-styling-4.png differ diff --git a/src/img/2026/tree-styling-5.png b/src/img/2026/tree-styling-5.png new file mode 100644 index 00000000..fb8f714b Binary files /dev/null and b/src/img/2026/tree-styling-5.png differ diff --git a/src/img/2026/tree-styling-6.png b/src/img/2026/tree-styling-6.png new file mode 100644 index 00000000..0eacf322 Binary files /dev/null and b/src/img/2026/tree-styling-6.png differ diff --git a/src/img/2026/tree-styling-7.png b/src/img/2026/tree-styling-7.png new file mode 100644 index 00000000..933b743f Binary files /dev/null and b/src/img/2026/tree-styling-7.png differ diff --git a/src/posts/2026/2026-09-21-tree-style-toc.md b/src/posts/2026/2026-09-21-tree-style-toc.md new file mode 100644 index 00000000..4eb5773a --- /dev/null +++ b/src/posts/2026/2026-09-21-tree-style-toc.md @@ -0,0 +1,217 @@ +--- +title: tree-style table of contents +layout: post-with-toc.njk +image: + src: 2026/tree-styling-0.png + alt: "screenshot of the table of contents for a blog post (this blog post, in fact). it's been styled so that the output resembles the hierarchical file system output from the shell program 'tree.'" +tags: + - reference + - software +--- + +I have a shiny new Table of Contents (hereafter ToC) section for some of my posts (like this one)! And for fun and profit, it's styled like the output of [`tree`](https://en.wikipedia.org/wiki/Tree_(command)). I want to lay out the CSS I used for this. Fair warning, there's some hyper-specific border widths and positioning that *probably* should be a `calc()` function of some kind. + +I drew inspiration from this [StackOverflow issue regarding tree styling for lists](https://stackoverflow.com/questions/14423671/best-method-for-displaying-a-tree-list-using-css-only-no-images-or-js-example). + +## `tree` + +Just for reference, here's some sample `tree` output: + +```txt +. +├── footer.njk +├── head-content.njk +├── header.njk +├── layouts +│   ├── base.njk +│   ├── page-lists.njk +│   ├── page.njk +│   ├── post.njk +│   ├── post-with-toc.njk +│   └── tag-redirect.njk +├── pagination.njk +├── postlist.njk +└── webring.njk +``` + +(You'll note that there are gaps between the verticals of each line. That's due to the line-height on the page, but in a standard terminal those vertical lines would be contiguous.) + +## HTML + +Our ToC uses the following HTML structure: + +```html + +``` + +We can ignore the `