From f794fa3ce0ed70e6cab67b2e7f51d05558304290 Mon Sep 17 00:00:00 2001 From: lew Date: Thu, 9 Apr 2026 17:42:32 +0100 Subject: [PATCH] include_str default css, fix placeholder replacement in comments --- src/render.rs | 8 +++++--- templates/default.html | 44 ++++++++++++------------------------------ 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/src/render.rs b/src/render.rs index 9dd3e2e..514317b 100644 --- a/src/render.rs +++ b/src/render.rs @@ -2,14 +2,16 @@ use crate::config::Config; use crate::entries::Entry; pub const DEFAULT_TEMPLATE: &str = include_str!("../templates/default.html"); +pub const DEFAULT_STYLE: &str = include_str!("../templates/default.css"); pub fn render_page(template: &str, config: &Config, entries: &[Entry], form_html: &str) -> String { let entries_html = render_entries(entries, &config.separator); - let style = if config.style.is_empty() { - String::new() + let css = if config.style.is_empty() { + DEFAULT_STYLE } else { - format!("", config.style) + &config.style }; + let style = format!(""); template .replace("{{title}}", &config.site_title) .replace("{{form}}", form_html) diff --git a/templates/default.html b/templates/default.html index 93004e5..e1f6074 100644 --- a/templates/default.html +++ b/templates/default.html @@ -2,32 +2,21 @@ Default guestbook template. Copy this file and point BOOK_TEMPLATE at your copy to customize. + Placeholders are inserted with double curly braces, e.g. curly-title-curly. + Available placeholders: - {{title}} - Site title (BOOK_SITE_TITLE). Useful in and headings. - {{form}} - The submission form (labels, inputs, button). Controlled by - BOOK_FORM_PROMPT, BOOK_LABEL_NAME, BOOK_LABEL_WEBSITE, - BOOK_LABEL_MESSAGE, BOOK_BUTTON_TEXT, BOOK_TEXTAREA_ROWS, - BOOK_TEXTAREA_COLS. Empty when BOOK_OPEN_REGISTRATION=false. - {{entries}} - Approved guestbook entries, newest first. Entry separator - controlled by BOOK_SEPARATOR. - {{style}} - Custom CSS from BOOK_STYLE or BOOK_STYLE_FILE, wrapped in - a <style> tag. Empty when neither is set. + title - Site title (BOOK_SITE_TITLE). Useful in <title> and headings. + form - The submission form (labels, inputs, button). Controlled by + BOOK_FORM_PROMPT, BOOK_LABEL_NAME, BOOK_LABEL_WEBSITE, + BOOK_LABEL_MESSAGE, BOOK_BUTTON_TEXT, BOOK_TEXTAREA_ROWS, + BOOK_TEXTAREA_COLS. Empty when BOOK_OPEN_REGISTRATION=false. + entries - Approved guestbook entries, newest first. Entry separator + controlled by BOOK_SEPARATOR. + style - Custom CSS from BOOK_STYLE or BOOK_STYLE_FILE, wrapped in + a <style> tag. Uses built-in default.css when neither is set. - Available CSS classes on rendered elements: - - .page-container - Main page wrapper - .guestbook-prompt - Text above the form - .guestbook-form - The <form> element - .guestbook-label - Field labels - .guestbook-input - Text inputs (name, website) - .guestbook-textarea - Message textarea - .guestbook-button - Submit button - .entry-header - Entry date/name/website line - .entry-name - Author name within the header - .entry-website - Website link within the header - .entry-body - Entry message content (raw HTML, not escaped) - .entry-separator - Divider between entries + See default.css for available CSS classes on rendered elements. --> <!DOCTYPE html> <html lang="en"> @@ -35,15 +24,6 @@ <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>{{title}} - {{style}}