From c70c4449fcc0f405912479c46b0d8c9de53fd97f Mon Sep 17 00:00:00 2001 From: lew Date: Tue, 28 Apr 2026 01:59:35 +0100 Subject: [PATCH] config: simplification of some options, moved into html template --- .env.example | 20 +++++++++++++------- module.nix | 42 ++++++++++++++++++++++++++++-------------- src/config.rs | 19 +++++++++++++------ src/render.rs | 29 +++++++++++------------------ src/web.rs | 4 +++- templates/default.html | 12 ++++++------ 6 files changed, 74 insertions(+), 52 deletions(-) diff --git a/.env.example b/.env.example index 0d05b58..2ef4faf 100644 --- a/.env.example +++ b/.env.example @@ -69,20 +69,26 @@ # .entry-name, .entry-website, .entry-body # BOOK_STYLE= -# Text shown above the form. Empty by default. -# BOOK_FORM_PROMPT=Thanks for visiting. Sign the guestbook! - # Submit button text. -# BOOK_BUTTON_TEXT=sign +# BOOK_BUTTON_TEXT=Submit Entry # Label for the name field. -# BOOK_LABEL_NAME=name +# BOOK_LABEL_NAME=Your name # Label for the website field. -# BOOK_LABEL_WEBSITE=website (optional) +# BOOK_LABEL_WEBSITE=Link a website (optional) # Label for the message field. -# BOOK_LABEL_MESSAGE=message +# BOOK_LABEL_MESSAGE=Leave a message (optional) + +# Label for the drawing field (when BOOK_ENABLE_DRAWINGS=true). +# BOOK_LABEL_DRAWING=Leave a drawing (optional) + +# Label for the voice note field (when BOOK_ENABLE_VOICE_NOTES=true). +# BOOK_LABEL_VOICE_NOTE=Leave a voice note (optional) + +# Initial text on the voice note record button. +# BOOK_VOICE_NOTE_RECORD_TEXT=Start recording # Message textarea width in pixels. # BOOK_TEXTAREA_WIDTH=320 diff --git a/module.nix b/module.nix index 5e24e52..cdba7f7 100644 --- a/module.nix +++ b/module.nix @@ -249,35 +249,47 @@ in description = "Custom success page template with {{title}} and {{style}} placeholders. Uses built-in default if null."; }; - greeting = mkOption { - type = types.str; - default = ""; - description = "Text shown above the form."; - }; - labels = { submit = mkOption { type = types.str; - default = "sign"; + default = "Submit Entry"; description = "Submit button text."; }; name = mkOption { type = types.str; - default = "name"; - description = "Label for the name field (used as both screen-reader label and placeholder)."; + default = "Your name"; + description = "Label for the name field."; }; website = mkOption { type = types.str; - default = "website (optional)"; - description = "Label for the website field (used as both screen-reader label and placeholder)."; + default = "Link a website (optional)"; + description = "Label for the website field."; }; message = mkOption { type = types.str; - default = "message"; - description = "Label for the message field (used as both screen-reader label and placeholder)."; + default = "Leave a message (optional)"; + description = "Label for the message field."; + }; + + drawing = mkOption { + type = types.str; + default = "Leave a drawing (optional)"; + description = "Label for the drawing field (when drawing.enable=true)."; + }; + + voiceNote = mkOption { + type = types.str; + default = "Leave a voice note (optional)"; + description = "Label for the voice note field (when voiceNote.enable=true)."; + }; + + voiceNoteRecord = mkOption { + type = types.str; + default = "Start recording"; + description = "Initial text on the voice note record button."; }; }; @@ -323,11 +335,13 @@ in BOOK_MAX_MESSAGE_LENGTH = toString cfg.limits.message; BOOK_MAX_WEBSITE_LENGTH = toString cfg.limits.website; BOOK_STYLE = cfg.styles.css; - BOOK_FORM_PROMPT = cfg.styles.greeting; BOOK_BUTTON_TEXT = cfg.styles.labels.submit; BOOK_LABEL_NAME = cfg.styles.labels.name; BOOK_LABEL_WEBSITE = cfg.styles.labels.website; BOOK_LABEL_MESSAGE = cfg.styles.labels.message; + BOOK_LABEL_DRAWING = cfg.styles.labels.drawing; + BOOK_LABEL_VOICE_NOTE = cfg.styles.labels.voiceNote; + BOOK_VOICE_NOTE_RECORD_TEXT = cfg.styles.labels.voiceNoteRecord; BOOK_CANVAS_WIDTH = toString cfg.features.drawing.canvasWidth; BOOK_CANVAS_HEIGHT = toString cfg.features.drawing.canvasHeight; BOOK_ENABLE_VOICE_NOTES = if cfg.features.voiceNote.enable then "true" else "false"; diff --git a/src/config.rs b/src/config.rs index 1916f90..41671f0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -37,11 +37,13 @@ pub struct Config { pub template: Option, pub success_template: Option, pub style: String, - pub form_prompt: String, pub button_text: String, pub label_name: String, pub label_website: String, pub label_message: String, + pub label_drawing: String, + pub label_voice_note: String, + pub voice_note_record_text: String, pub textarea_width: u32, pub textarea_height: u32, } @@ -167,14 +169,19 @@ impl Config { }) .or_else(|| env::var("BOOK_STYLE").ok()) .unwrap_or_default(), - form_prompt: env::var("BOOK_FORM_PROMPT").unwrap_or_default(), button_text: env::var("BOOK_BUTTON_TEXT") - .unwrap_or_else(|_| "Submit".into()), - label_name: env::var("BOOK_LABEL_NAME").unwrap_or_else(|_| "name".into()), + .unwrap_or_else(|_| "Submit Entry".into()), + label_name: env::var("BOOK_LABEL_NAME").unwrap_or_else(|_| "Your name".into()), label_website: env::var("BOOK_LABEL_WEBSITE") - .unwrap_or_else(|_| "website (optional)".into()), + .unwrap_or_else(|_| "Link a website (optional)".into()), label_message: env::var("BOOK_LABEL_MESSAGE") - .unwrap_or_else(|_| "message (optional)".into()), + .unwrap_or_else(|_| "Leave a message (optional)".into()), + label_drawing: env::var("BOOK_LABEL_DRAWING") + .unwrap_or_else(|_| "Leave a drawing (optional)".into()), + label_voice_note: env::var("BOOK_LABEL_VOICE_NOTE") + .unwrap_or_else(|_| "Leave a voice note (optional)".into()), + voice_note_record_text: env::var("BOOK_VOICE_NOTE_RECORD_TEXT") + .unwrap_or_else(|_| "Start recording".into()), textarea_width: env::var("BOOK_TEXTAREA_WIDTH") .unwrap_or_else(|_| "320".into()) .parse() diff --git a/src/render.rs b/src/render.rs index d209d7a..eb062af 100644 --- a/src/render.rs +++ b/src/render.rs @@ -13,17 +13,8 @@ pub fn render_page(template: &str, config: &Config, entries: &[Entry], form_html &config.style }; let style = format!(""); - let prompt = if config.enable_submissions { - format!( - "{}", - config.form_prompt - ) - } else { - String::new() - }; template .replace("{{title}}", &config.site_title) - .replace("{{prompt}}", &prompt) .replace("{{form}}", form_html) .replace("{{entries}}", &entries_html) .replace("{{style}}", &style) @@ -50,7 +41,7 @@ pub fn render_form(config: &Config) -> String { let drawing_section = if config.enable_drawings { format!( - r##"drawing (optional) + r##"{label} "##, + label = config.label_drawing, w = config.canvas_width, h = config.canvas_height, ) @@ -111,7 +103,7 @@ pub fn render_form(config: &Config) -> String { let voice_note_section = if config.enable_voice_notes { format!( - r##"voice note (optional) + r##"{label} "##, + label = config.label_voice_note, + record = config.voice_note_record_text, max_dur = config.voice_note_max_duration, ) } else { @@ -176,16 +170,13 @@ pub fn render_form(config: &Config) -> String { }; format!( - r#"
-Leave your own message. -
+ r#" {website_section} {drawing_section}{voice_note_section}{captcha_section} -
-
"#, +"#, label_name = config.label_name, website_section = website_section, label_message = config.label_message, @@ -348,11 +339,13 @@ mod tests { template: None, success_template: None, style: String::new(), - form_prompt: "Thanks for visiting. Sign the guestbook!".into(), button_text: "sign".into(), label_name: "name".into(), label_website: "website (optional)".into(), label_message: "message (optional)".into(), + label_drawing: "drawing (optional)".into(), + label_voice_note: "voice note (optional)".into(), + voice_note_record_text: "record".into(), textarea_width: 400, textarea_height: 150, } diff --git a/src/web.rs b/src/web.rs index ed213da..95be1b6 100644 --- a/src/web.rs +++ b/src/web.rs @@ -414,11 +414,13 @@ mod tests { template: None, success_template: None, style: String::new(), - form_prompt: "Thanks for visiting. Sign the guestbook!".into(), button_text: "sign".into(), label_name: "name".into(), label_website: "website (optional)".into(), label_message: "message (optional)".into(), + label_drawing: "drawing (optional)".into(), + label_voice_note: "voice note (optional)".into(), + voice_note_record_text: "record".into(), textarea_width: 400, textarea_height: 150, } diff --git a/templates/default.html b/templates/default.html index 870ddc1..4cca25b 100644 --- a/templates/default.html +++ b/templates/default.html @@ -7,13 +7,11 @@ Available placeholders: title - Site title (BOOK_SITE_TITLE). Useful in and headings. - prompt - The form prompt text (BOOK_FORM_PROMPT), wrapped in a - <span class="guestbook-prompt">. Empty when submissions - are disabled. Place anywhere relative to the form. form - The submission form (labels, inputs, button). Controlled by BOOK_LABEL_NAME, BOOK_LABEL_WEBSITE, BOOK_LABEL_MESSAGE, - BOOK_BUTTON_TEXT, BOOK_TEXTAREA_WIDTH, BOOK_TEXTAREA_HEIGHT. - Empty when BOOK_ENABLE_SUBMISSIONS=false. + BOOK_LABEL_DRAWING, BOOK_LABEL_VOICE_NOTE, BOOK_BUTTON_TEXT, + BOOK_TEXTAREA_WIDTH, BOOK_TEXTAREA_HEIGHT. Empty when + BOOK_ENABLE_SUBMISSIONS=false. entries - Approved guestbook entries, newest first. style - Custom CSS from BOOK_STYLE or BOOK_STYLE_FILE, wrapped in a <style> tag. Uses built-in default.css when neither is set. @@ -32,8 +30,10 @@ <div class="page-container"> <h1>{{title}}</h1> -{{prompt}} +<details class="guestbook-details"> +<summary class="guestbook-summary">Click me to leave an entry</summary> {{form}} +</details> <h1>entries</h1> {{entries}}