From a6baea06697f6c76c695dc4198099deb8ba916e0 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 6 Jun 2025 15:45:11 +0200 Subject: feat(treewide): Prepare for first release This commit contains many changes, as they were developed alongside `git-bug-rs` and unfortunately not separately committed. A toplevel summary would include: - Appropriate redirects, - The templating moved to `vy` (as this works with rustfmt formatting), - Search support (via `git-bug-rs`), - And better layout in the link section. --- src/web/generate/templates.rs | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/web/generate/templates.rs (limited to 'src/web/generate/templates.rs') diff --git a/src/web/generate/templates.rs b/src/web/generate/templates.rs new file mode 100644 index 0000000..693b862 --- /dev/null +++ b/src/web/generate/templates.rs @@ -0,0 +1,44 @@ +use vy::{DOCTYPE, IntoHtml, PreEscaped, body, div, head, html, link, meta, title}; + +pub(crate) fn make_page( + content: impl IntoHtml, + description: &str, + title: Option<&str>, +) -> impl IntoHtml { + ( + DOCTYPE, + html!( + lang = "en", + head!( + title!(title.unwrap_or("Back")), + link!(rel = "icon", href = "/favicon.ico"), + link!(rel = "stylesheet", "type" = "text/css", href = "/style.css"), + meta!(charset = "UTF-8"), + meta!( + name = "viewport", + content = "width=device-width,initial-scale=1" + ), + meta!(name = "description", content = description), + ), + body!(div!(class = "content", content)) + ), + ) +} + +pub(super) fn to_markdown(input: &str, is_title: bool) -> PreEscaped { + let markdown = markdown::to_html(input.trim()); + + // If the markdown contains only one line line, assuming that it is a title is okay. + if input.lines().count() == 1 && markdown.starts_with("

") && is_title { + PreEscaped( + markdown + .strip_prefix("

") + .expect("We checked") + .strip_suffix("

") + .expect("markdown crate produces no invalid html") + .to_owned(), + ) + } else { + PreEscaped(markdown) + } +} -- cgit 1.4.1