diff options
author | Lukas Stabe <lukas@stabe.de> | 2020-09-26 03:39:52 +0000 |
---|---|---|
committer | Lukas Stabe <lukas@stabe.de> | 2020-09-26 03:39:52 +0000 |
commit | a4d227d34ad2bbf40ff5d542dcc8821ccb090ac7 (patch) | |
tree | caf6638bd2f26f90c4c93049100135763034afcd /src/renderer.rs | |
parent | move css out of html into its own route (diff) | |
download | miniserve-a4d227d34ad2bbf40ff5d542dcc8821ccb090ac7.tar.gz miniserve-a4d227d34ad2bbf40ff5d542dcc8821ccb090ac7.zip |
remove default color scheme cli argument
Diffstat (limited to 'src/renderer.rs')
-rw-r--r-- | src/renderer.rs | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/renderer.rs b/src/renderer.rs index 0f11c25..2ebe214 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -7,7 +7,6 @@ use strum::IntoEnumIterator; use crate::archive::CompressionMethod; use crate::listing::{Breadcrumb, Entry, SortingMethod, SortingOrder}; -use crate::themes::ColorScheme; /// Renders the file listing #[allow(clippy::too_many_arguments)] @@ -44,13 +43,17 @@ pub fn page( const body = document.body; var theme = localStorage.getItem('theme'); - if (theme != null) { + if (theme != null && theme != 'default') { body.classList.add('theme_' + theme); } function updateColorScheme(name) { body.classList.remove.apply(body.classList, Array.from(body.classList).filter(v=>v.startsWith("theme_"))); - body.classList.add('theme_' + name); + + if (name != "default") { + body.classList.add('theme_' + name); + } + localStorage.setItem('theme', name); } </script> @@ -150,6 +153,14 @@ fn build_upload_action( upload_action } +const THEMES: &[(&str, &str)] = &[ + ("Default (light/dark)", "default"), + ("Squirrel (light)", "squirrel"), + ("Archlinux (dark)", "archlinux"), + ("Zenburn (dark)", "zenburn"), + ("Monokai (dark)", "monokai"), +]; + /// Partial: color scheme selector fn color_scheme_selector(show_qrcode: bool) -> Markup { html! { @@ -169,8 +180,8 @@ fn color_scheme_selector(show_qrcode: bool) -> Markup { "Change theme..." } ul.theme { - @for color_scheme in ColorScheme::iter() { - li { + @for color_scheme in THEMES { + li.(format!("theme_{}", color_scheme.1)) { (color_scheme_link(color_scheme)) } } @@ -181,18 +192,12 @@ fn color_scheme_selector(show_qrcode: bool) -> Markup { } // /// Partial: color scheme link -fn color_scheme_link(color_scheme: ColorScheme) -> Markup { - let title = format!("Switch to {} theme", color_scheme); +fn color_scheme_link(color_scheme: &(&str, &str)) -> Markup { + let title = format!("Switch to {} theme", color_scheme.0); html! { - a href=(format!("javascript:updateColorScheme(\"{}\")", color_scheme.to_slug())) title=(title) { - (color_scheme) - " " - @if color_scheme.is_dark() { - "(dark)" - } @else { - "(light)" - } + a href=(format!("javascript:updateColorScheme(\"{}\")", color_scheme.1)) title=(title) { + (color_scheme.0) } } } |