From 579030db36abecd812795e14b6f517f26846ed56 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Sat, 17 Dec 2022 12:13:51 +0100 Subject: [PATCH] Highlight current module in the sidebar. --- crates/project/src/docs.rs | 15 +++++++++++++++ crates/project/templates/_layout.html | 8 +++++++- crates/project/templates/css/index.css | 11 +++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/crates/project/src/docs.rs b/crates/project/src/docs.rs index 3ab8c46b..a030ff7a 100644 --- a/crates/project/src/docs.rs +++ b/crates/project/src/docs.rs @@ -46,6 +46,15 @@ struct ModuleTemplate<'a> { timestamp: String, } +impl<'a> ModuleTemplate<'a> { + pub fn is_current_module(&self, module: &DocLink) -> bool { + match module.path.split(".html").next() { + None => false, + Some(name) => self.module_name == name, + } + } +} + #[derive(Template)] #[template(path = "page.html")] struct PageTemplate<'a> { @@ -61,6 +70,12 @@ struct PageTemplate<'a> { timestamp: &'a str, } +impl<'a> PageTemplate<'a> { + pub fn is_current_module(&self, _module: &DocLink) -> bool { + false + } +} + #[derive(PartialEq, Eq, PartialOrd, Ord, Clone)] struct DocLink { name: String, diff --git a/crates/project/templates/_layout.html b/crates/project/templates/_layout.html index 8f243315..f8c8611e 100644 --- a/crates/project/templates/_layout.html +++ b/crates/project/templates/_layout.html @@ -187,7 +187,13 @@ {% endif %} diff --git a/crates/project/templates/css/index.css b/crates/project/templates/css/index.css index ce9158d0..2b2c42fc 100644 --- a/crates/project/templates/css/index.css +++ b/crates/project/templates/css/index.css @@ -324,6 +324,17 @@ p code { margin-bottom: 4px; } +.sidebar ul li a > strong { + font-weight: 900; + color: var(--color-link); +} + +.sidebar ul li a > strong::before { + font-size: 0.75em; + content: 'ᐅ '; + padding-right: 0.1rem; +} + .sidebar .sidebar-toggle { color: var(--color-link); font-size: calc(0.8 * var(--sidebar-toggle-size));