use based::{ page::Shell, request::{RequestContext, StringResponse}, }; use maud::{html, PreEscaped}; /// Generates an SVG arrow icon with the specified color. /// /// # Parameters /// - `color`: The color of the arrow icon. /// /// # Returns /// A `PreEscaped` containing the SVG markup for the arrow icon. pub fn arrow_icon(color: &str) -> PreEscaped { html! { svg class=(format!("w-5 h-5 text-{color}-500")) xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" { path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" {}; }; } } /// Generates a styled slash separator. /// /// # Returns /// A `PreEscaped` containing the HTML markup for a slash separator. pub fn slash_seperator() -> PreEscaped { html! { p class="font-bold p-2 text-gray-400" { " / " }; } } /// Generates a hyperlink for a specific path within a domain. /// /// # Parameters /// - `path`: The path segment to link. /// - `index`: The index of the current path segment in the hierarchy. /// - `path_seperations`: The array of all path segments in the hierarchy. /// - `domain`: The domain to which the path belongs. /// /// # Returns /// A `PreEscaped` containing the HTML markup for the hyperlink. pub fn gen_path_link( path: &str, index: usize, path_seperations: &[&str], domain: &str, ) -> PreEscaped { let upto: Vec<&str> = path_seperations.iter().take(index + 1).cloned().collect(); html! { a href=(format!("/d/{}/{}", domain, upto.join("/"))) { (path)} } } /// Generates a breadcrumb-like header for a path within a domain. /// /// # Parameters /// - `path_seperations`: A vector of path segments representing the hierarchy. /// - `domain`: The domain to which the path belongs. /// /// # Returns /// A `PreEscaped` containing the HTML markup for the path header. pub fn gen_path_header( path_seperations: Vec<&str>, domain: &str, link: bool, ) -> PreEscaped { html! { @for (index, path) in path_seperations.iter().enumerate() { @if link { (gen_path_link(path, index, &path_seperations, domain)) } @else { p { (path) } } @if index < path_seperations.len()-1 { (slash_seperator()) }; }; } } pub async fn render_page(content: PreEscaped, ctx: RequestContext) -> StringResponse { based::page::render_page( content, "Website Archive", ctx, &Shell::new( html! { script src="https://cdn.tailwindcss.com" {}; meta name="viewport" content="width=device-width, initial-scale=1.0" {}; script src="/assets/htmx.min.js" {}; }, html! {}, Some("bg-zinc-950 text-white min-h-screen flex pt-8 justify-center".to_string()), ), ) .await } pub fn favicon(site: &str) -> PreEscaped { html! { img class="h-8 w-8 m-2" src=(format!("/favicon/{site}")) {}; } }