aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs17
-rw-r--r--src/renderer.rs15
2 files changed, 29 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 2f81baa..33b0699 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -28,6 +28,8 @@ mod renderer;
use crate::config::MiniserveConfig;
use crate::errors::ContextualError;
+static STYLESHEET: &str = include_str!(concat!(env!("OUT_DIR"), "/style.css"));
+
fn main() -> Result<()> {
let args = args::CliArgs::parse();
@@ -181,10 +183,20 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> {
.map(|sock| sock.to_string().green().bold().to_string())
.collect::<Vec<_>>();
+ let stylesheet = web::Data::new(
+ [
+ STYLESHEET,
+ inside_config.default_color_scheme.css(),
+ inside_config.default_color_scheme_dark.css_dark().as_str(),
+ ]
+ .join("\n"),
+ );
+
let srv = actix_web::HttpServer::new(move || {
App::new()
.wrap(configure_header(&inside_config.clone()))
.app_data(inside_config.clone())
+ .app_data(stylesheet.clone())
.wrap_fn(errors::error_page_middleware)
.wrap(middleware::Logger::default())
.route(&inside_config.favicon_route, web::get().to(favicon))
@@ -345,9 +357,8 @@ async fn favicon() -> impl Responder {
.body(logo)
}
-async fn css() -> impl Responder {
- let css = include_str!(concat!(env!("OUT_DIR"), "/style.css"));
+async fn css(stylesheet: web::Data<String>) -> impl Responder {
HttpResponse::Ok()
.insert_header(ContentType(mime::TEXT_CSS))
- .body(css)
+ .body(stylesheet.to_string())
}
diff --git a/src/renderer.rs b/src/renderer.rs
index 2e1ff2e..2de95c8 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -346,6 +346,21 @@ pub enum ThemeSlug {
Monokai,
}
+impl ThemeSlug {
+ pub fn css(&self) -> &str {
+ match self {
+ ThemeSlug::Squirrel => include_str!(concat!(env!("OUT_DIR"), "/theme-squirrel.css")),
+ ThemeSlug::Archlinux => include_str!(concat!(env!("OUT_DIR"), "/theme-archlinux.css")),
+ ThemeSlug::Zenburn => include_str!(concat!(env!("OUT_DIR"), "/theme-zenburn.css")),
+ ThemeSlug::Monokai => include_str!(concat!(env!("OUT_DIR"), "/theme-monokai.css")),
+ }
+ }
+
+ pub fn css_dark(&self) -> String {
+ format!("@media (prefers-color-scheme: dark) {{\n{}}}", self.css())
+ }
+}
+
/// Partial: qr code spoiler
fn qr_spoiler(show_qrcode: bool, content: &Uri) -> Markup {
html! {