include_str default css, fix placeholder replacement in comments
This commit is contained in:
parent
1a7605c4fc
commit
f794fa3ce0
2 changed files with 17 additions and 35 deletions
|
|
@ -2,14 +2,16 @@ use crate::config::Config;
|
||||||
use crate::entries::Entry;
|
use crate::entries::Entry;
|
||||||
|
|
||||||
pub const DEFAULT_TEMPLATE: &str = include_str!("../templates/default.html");
|
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 {
|
pub fn render_page(template: &str, config: &Config, entries: &[Entry], form_html: &str) -> String {
|
||||||
let entries_html = render_entries(entries, &config.separator);
|
let entries_html = render_entries(entries, &config.separator);
|
||||||
let style = if config.style.is_empty() {
|
let css = if config.style.is_empty() {
|
||||||
String::new()
|
DEFAULT_STYLE
|
||||||
} else {
|
} else {
|
||||||
format!("<style>\n{}\n </style>", config.style)
|
&config.style
|
||||||
};
|
};
|
||||||
|
let style = format!("<style>\n{css}\n </style>");
|
||||||
template
|
template
|
||||||
.replace("{{title}}", &config.site_title)
|
.replace("{{title}}", &config.site_title)
|
||||||
.replace("{{form}}", form_html)
|
.replace("{{form}}", form_html)
|
||||||
|
|
|
||||||
|
|
@ -2,32 +2,21 @@
|
||||||
Default guestbook template.
|
Default guestbook template.
|
||||||
Copy this file and point BOOK_TEMPLATE at your copy to customize.
|
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:
|
Available placeholders:
|
||||||
|
|
||||||
{{title}} - Site title (BOOK_SITE_TITLE). Useful in <title> and headings.
|
title - Site title (BOOK_SITE_TITLE). Useful in <title> and headings.
|
||||||
{{form}} - The submission form (labels, inputs, button). Controlled by
|
form - The submission form (labels, inputs, button). Controlled by
|
||||||
BOOK_FORM_PROMPT, BOOK_LABEL_NAME, BOOK_LABEL_WEBSITE,
|
BOOK_FORM_PROMPT, BOOK_LABEL_NAME, BOOK_LABEL_WEBSITE,
|
||||||
BOOK_LABEL_MESSAGE, BOOK_BUTTON_TEXT, BOOK_TEXTAREA_ROWS,
|
BOOK_LABEL_MESSAGE, BOOK_BUTTON_TEXT, BOOK_TEXTAREA_ROWS,
|
||||||
BOOK_TEXTAREA_COLS. Empty when BOOK_OPEN_REGISTRATION=false.
|
BOOK_TEXTAREA_COLS. Empty when BOOK_OPEN_REGISTRATION=false.
|
||||||
{{entries}} - Approved guestbook entries, newest first. Entry separator
|
entries - Approved guestbook entries, newest first. Entry separator
|
||||||
controlled by BOOK_SEPARATOR.
|
controlled by BOOK_SEPARATOR.
|
||||||
{{style}} - Custom CSS from BOOK_STYLE or BOOK_STYLE_FILE, wrapped in
|
style - Custom CSS from BOOK_STYLE or BOOK_STYLE_FILE, wrapped in
|
||||||
a <style> tag. Empty when neither is set.
|
a <style> tag. Uses built-in default.css when neither is set.
|
||||||
|
|
||||||
Available CSS classes on rendered elements:
|
See default.css for 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
|
|
||||||
-->
|
-->
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
@ -35,15 +24,6 @@
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>{{title}}</title>
|
<title>{{title}}</title>
|
||||||
<style>
|
|
||||||
.page-container {
|
|
||||||
max-width: 70ch;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 1rem;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
word-wrap: break-word;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
{{style}}
|
{{style}}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue