From 18cfe87faaf2306b5cda3176e44025e9cd17d6b2 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 29 Jul 2025 09:01:47 +1200 Subject: Add embed-html-head and override-html-head fragment types These will both add content to the 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. --- src/generate_html.rs | 21 +++++++++++++++++++-- 1 file 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() { -- cgit v1.2.3-70-g09d2