diff --git a/.env.example b/.env.example index 2013aa5..cf935ec 100644 --- a/.env.example +++ b/.env.example @@ -17,5 +17,6 @@ BOOK_LABEL_WEBSITE=Your website (optional): BOOK_LABEL_MESSAGE=Your message: BOOK_TEXTAREA_ROWS=8 BOOK_TEXTAREA_COLS=60 +# BOOK_STYLE_FILE=./my-styles.css # BOOK_STYLE=.entry-name { font-weight: bold; } # BOOK_TEMPLATE=./templates/default.html diff --git a/module.nix b/module.nix index 6464d15..1bbe6ef 100644 --- a/module.nix +++ b/module.nix @@ -87,6 +87,12 @@ in description = "Custom CSS injected into a style tag. Use class names: .guestbook-form, .guestbook-prompt, .guestbook-label, .guestbook-input, .guestbook-textarea, .guestbook-button, .entry-header, .entry-name, .entry-website, .entry-body, .entry-separator"; }; + styleFile = mkOption { + type = types.nullOr types.path; + default = null; + description = "Path to a CSS file. Takes precedence over style."; + }; + formPrompt = mkOption { type = types.str; default = "If you visited my site, please sign my guestbook!"; @@ -177,6 +183,8 @@ in BOOK_OPEN_REGISTRATION = if cfg.openRegistration then "true" else "false"; BOOK_SEPARATOR = cfg.separator; BOOK_STYLE = cfg.style; + } // lib.optionalAttrs (cfg.styleFile != null) { + BOOK_STYLE_FILE = cfg.styleFile; BOOK_FORM_PROMPT = cfg.formPrompt; BOOK_BUTTON_TEXT = cfg.buttonText; BOOK_LABEL_NAME = cfg.labelName; diff --git a/src/config.rs b/src/config.rs index b552b1e..75e93bd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -72,7 +72,14 @@ impl Config { std::fs::read_to_string(&path) .unwrap_or_else(|e| panic!("failed to read template {path}: {e}")) }), - style: env::var("BOOK_STYLE").unwrap_or_default(), + style: env::var("BOOK_STYLE_FILE") + .ok() + .map(|path| { + std::fs::read_to_string(&path) + .unwrap_or_else(|e| panic!("failed to read style file {path}: {e}")) + }) + .or_else(|| env::var("BOOK_STYLE").ok()) + .unwrap_or_default(), form_prompt: env::var("BOOK_FORM_PROMPT") .unwrap_or_else(|_| "If you visited my site, please sign my guestbook!".into()), button_text: env::var("BOOK_BUTTON_TEXT")