From 34dc0a88358e37c45aee46deceb905579bd5d057 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 16 Jul 2024 12:23:26 -0700 Subject: [PATCH] Make the sidebar work without JS Uses an iframe instead. The downside of iframes comes from them not necessarily being same-origin as the main page (particularly with `file:///` URLs), which can cause themes to fall out of sync, but that's not a problem here since themes don't work without JS anyway. --- src/renderer/html_handlebars/hbs_renderer.rs | 10 +++-- src/theme/css/chrome.css | 16 ++++++++ src/theme/index.hbs | 3 ++ src/theme/mod.rs | 16 +++++--- src/theme/toc.html.hbs | 43 ++++++++++++++++++++ 5 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 src/theme/toc.html.hbs diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index a591e86ffe..64bfd85cc0 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -529,7 +529,8 @@ impl Renderer for HtmlHandlebars { handlebars.register_partial("header", String::from_utf8(theme.header.clone())?)?; debug!("Register the toc handlebars template"); - handlebars.register_template_string("toc", String::from_utf8(theme.toc.clone())?)?; + handlebars.register_template_string("toc_js", String::from_utf8(theme.toc_js.clone())?)?; + handlebars.register_template_string("toc_html", String::from_utf8(theme.toc_html.clone())?)?; debug!("Register handlebars helpers"); self.register_hbs_helpers(&mut handlebars, &html_config); @@ -586,11 +587,14 @@ impl Renderer for HtmlHandlebars { debug!("Creating print.html ✓"); } - debug!("Render toc.js"); + debug!("Render toc"); { - let rendered_toc = handlebars.render("toc", &data)?; + let rendered_toc = handlebars.render("toc_js", &data)?; utils::fs::write_file(destination, "toc.js", rendered_toc.as_bytes())?; debug!("Creating toc.js ✓"); + let rendered_toc = handlebars.render("toc_html", &data)?; + utils::fs::write_file(destination, "toc.html", rendered_toc.as_bytes())?; + debug!("Creating toc.html ✓"); } debug!("Copy static files"); diff --git a/src/theme/css/chrome.css b/src/theme/css/chrome.css index 83b7969bce..e62056b053 100644 --- a/src/theme/css/chrome.css +++ b/src/theme/css/chrome.css @@ -399,6 +399,22 @@ ul#searchresults span.teaser em { background-color: var(--sidebar-bg); color: var(--sidebar-fg); } +.sidebar-iframe-inner { + background-color: var(--sidebar-bg); + color: var(--sidebar-fg); + padding: 10px 10px; + margin: 0; + font-size: 1.4rem; +} +.sidebar-iframe-outer { + border: none; + height: 100%; + position: absolute; + top: 0; + bottom: 0; + left: 0; + right: 0; +} [dir=rtl] .sidebar { left: unset; right: 0; } .sidebar-resizing { -moz-user-select: none; diff --git a/src/theme/index.hbs b/src/theme/index.hbs index fb6c10b2b8..97f59a1325 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -111,6 +111,9 @@