From 8fe9268dc12111ae771a3ba4042c74acd3610116 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Thu, 4 Sep 2025 08:04:02 +1200 Subject: Add table of contents sidebar to generated HTML This is in addition to the existing table of contents at the top of each page. --- src/generate_html.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/generate_html.rs b/src/generate_html.rs index af48d2e..4064820 100644 --- a/src/generate_html.rs +++ b/src/generate_html.rs @@ -20,7 +20,13 @@ pub fn generate_html(document: &MarkdownDocument, page: &Page, website: &Website Some(name) => format!("{name}", make_url_safe(name)), None => String::new(), }; - let table_of_contents = get_table_of_contents(page); + let toc = get_table_of_contents(page); + let toc_main = if page.headings.len() > 3 { + format!("
\n{toc}
\n") + } else { String::new() }; + let toc_side = if page.headings.len() > 3 { + format!("
{toc}
\n") + } else { String::new() }; let main = document_to_html(document, page, website); let main = main.trim(); format!("\ @@ -32,6 +38,10 @@ pub fn generate_html(document: &MarkdownDocument, page: &Page, website: &Website {head} + +

{page_name}

{main}
+
") } @@ -90,7 +101,7 @@ pub fn get_table_of_contents(page: &Page) -> String { if page.headings.len() < 3 { return String::new(); } - let mut toc = String::from("
\n"); + toc.push_str("\n"); return toc; } -- cgit v1.2.3-70-g09d2