diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2025-07-29 09:01:47 +1200 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2025-07-29 09:02:26 +1200 |
commit | 18cfe87faaf2306b5cda3176e44025e9cd17d6b2 (patch) | |
tree | 7cd70b39cf1c97003d5219d8fe190cc7911f2c9d | |
parent | a84c2e234e30b0a0f1cbf690bec060dc68588db6 (diff) | |
download | toaster-18cfe87faaf2306b5cda3176e44025e9cd17d6b2.zip |
Add embed-html-head and override-html-head fragment types
These will both add content to the <head> HTML element on that page,
with the override variant also preventing the default head declared in
the toaster.conf file from being used on that page.
-rw-r--r-- | src/generate_html.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/generate_html.rs b/src/generate_html.rs index 2aab900..af48d2e 100644 --- a/src/generate_html.rs +++ b/src/generate_html.rs @@ -63,8 +63,24 @@ pub fn generate_html_redirect(path: &str) -> String { pub fn get_html_head(page: &Page, website: &Website) -> String { + let mut include_default_head = true; + let mut html_head = String::new(); + for block in &page.document.blocks { + if let markdown::Block::Fragment { language, content } = block { + if language == "override-html-head" { + html_head.push_str(content); + include_default_head = false; + } + if language == "embed-html-head" { + html_head.push_str(content); + } + } + } + if include_default_head { + html_head.insert_str(0, &website.get_config("html.head")); + } let root = page.root(); - website.get_config("html.head") + html_head .replace("href='/", &format!("href='{root}")) .replace("src='/", &format!("src='{root}")) } @@ -193,7 +209,8 @@ pub fn document_to_html(document: &MarkdownDocument, page: &Page, website: &Webs "embed-html" => html!("{content}"), "embed-css" => wrap!("style", html!("{content}")), "embed-javascript"|"embed-js" => wrap!("script", html!("{content}")), - "hidden"|"todo"|"embed-html-head" => (), + "embed-html-head"|"override-html-head" => (), + "hidden"|"todo" => (), "poem" => wrap!("div", "class='poem'", for line in content.lines() { let line = line.trim_end(); match line.is_empty() { |