From 09e56d3417c0bbf3ce5325053dac2e0fadef2349 Mon Sep 17 00:00:00 2001 From: Kara Date: Tue, 12 Sep 2023 03:59:05 -0500 Subject: [PATCH] subpage footer --- book.toml | 4 +-- scripts/{sidebar.js => nav-additions.js} | 30 +++++++++++++++--- theme/index.hbs | 4 +++ theme/{sidebar-style.css => nav-style.css} | 36 ++++++++++++++++++++++ theme/ss14.css | 1 + 5 files changed, 68 insertions(+), 7 deletions(-) rename scripts/{sidebar.js => nav-additions.js} (75%) rename theme/{sidebar-style.css => nav-style.css} (62%) diff --git a/book.toml b/book.toml index 58f108564..1f935b836 100644 --- a/book.toml +++ b/book.toml @@ -15,8 +15,8 @@ assets_version = "2.0.2" # do not edit: managed by `mdbook-admonish install` before = ["mermaid", "admonish"] # templates can include these so we run this first [output.html] -additional-js = ['scripts/mermaid.min.js', 'scripts/mermaid-init.js', 'scripts/sidebar.js'] -additional-css = ['theme/mdbook-admonish.css', 'theme/ss14.css', 'theme/sidebar-style.css'] +additional-js = ['scripts/mermaid.min.js', 'scripts/mermaid-init.js', 'scripts/nav-additions.js'] +additional-css = ['theme/mdbook-admonish.css', 'theme/ss14.css', 'theme/nav-style.css'] default-theme = "navy" preferred-dark-theme = "navy" diff --git a/scripts/sidebar.js b/scripts/nav-additions.js similarity index 75% rename from scripts/sidebar.js rename to scripts/nav-additions.js index 5f1352cdf..ff0bad7cc 100644 --- a/scripts/sidebar.js +++ b/scripts/nav-additions.js @@ -32,17 +32,37 @@ var updateFunction = function() { }); }; -// Populate sidebar on load window.addEventListener('load', function() { - var pagetoc = document.getElementsByClassName("pagetoc")[0]; - var elements = document.getElementsByClassName("header"); /* Scroll the page index on the left to the current active page */ var active = document.querySelector(".chapter li a.active"); active.scrollIntoView({ behavior: "instant", block: "center", inline: "nearest" }); - // don't show sidebar with only 1 header (or less) - if (elements.length <= 1) + /* Populate subpage footer */ + + /* Get next sibling of active list element + then check if it has a nested ol + if so, this implies our current active element has nested subpages */ + var nextListEl = active.parentElement.nextElementSibling; + var footer = document.getElementById("subpage-footer"); + footer.style.display = "none"; + if (nextListEl != null) + { + console.log(nextListEl); + var list = nextListEl.querySelector(".section") + if (list != null) + { + footer.style.display = "block"; + footer.appendChild(list.cloneNode(true)); + } + } + + /* Populate pagetoc sidebar */ + + var pagetoc = document.getElementsByClassName("pagetoc")[0]; + var elements = document.getElementsByClassName("header"); + // don't show pagetoc sidebar with less than 2 headers + if (elements.length < 2) return; Array.prototype.forEach.call(elements, function(el) { diff --git a/theme/index.hbs b/theme/index.hbs index a37d48193..2280e395d 100644 --- a/theme/index.hbs +++ b/theme/index.hbs @@ -191,6 +191,10 @@
--> + + diff --git a/theme/sidebar-style.css b/theme/nav-style.css similarity index 62% rename from theme/sidebar-style.css rename to theme/nav-style.css index bb228b420..98bafe7c9 100644 --- a/theme/sidebar-style.css +++ b/theme/nav-style.css @@ -1,3 +1,5 @@ +/* Styling for the subpage footer & sidebar toc */ + @media only screen and (max-width:1365px) { .sidetoc { display: none; @@ -41,8 +43,42 @@ } } +#subpage-footer { + max-width: 400px; + margin-top: 100px; + margin-left: 150px; + color: var(--fg) !important; + display: block; +} + +#subpage-footer > p { + line-height: 1.0em; +} + +#subpage-footer > ol { + list-style: none outside none; + padding-left: 20px; + line-height: 1.6em; + border-top: 1px solid var(--sidebar-bg); + padding-top: 10px; +} + +#subpage-footer ol > li.chapter-item { + display: flex; +} + +#subpage-footer a.toggle { + display: block; + margin-left: auto; + padding-left: 20px; + opacity: 0.68; +} + @media print { .sidetoc { display: none; } + #subpage-footer { + display: none; + } } diff --git a/theme/ss14.css b/theme/ss14.css index 3fed6280c..9d656b63e 100644 --- a/theme/ss14.css +++ b/theme/ss14.css @@ -7,6 +7,7 @@ --sidebar-active: #e23229; } +/* title text on top of every page */ .menu-title { color: #e23229; }