webarc/src/pages/component.rs
JMARyA 3e77ec5008
Some checks failed
ci/woodpecker/push/build Pipeline failed
update
2025-02-09 00:07:28 +01:00

85 lines
2.5 KiB
Rust

use based::ui::prelude::*;
use maud::{html, PreEscaped, Render};
/// Generates an SVG arrow icon with the specified color.
///
/// # Parameters
/// - `color`: The color of the arrow icon.
///
/// # Returns
/// A `PreEscaped<String>` containing the SVG markup for the arrow icon.
pub fn arrow_icon(color: &str) -> PreEscaped<String> {
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<String>` containing the HTML markup for a slash separator.
pub fn slash_seperator() -> PreEscaped<String> {
Padding(Text("/").bold().color(&Gray::_400))
.all(ScreenValue::_2)
.render()
}
/// 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<String>` containing the HTML markup for the hyperlink.
pub fn gen_path_link(
path: &str,
index: usize,
path_seperations: &[&str],
domain: &str,
) -> PreEscaped<String> {
let upto: Vec<&str> = path_seperations.iter().take(index + 1).cloned().collect();
Link(
&format!("/d/{}/{}", domain, upto.join("/")),
path.to_string(),
)
.use_htmx()
.render()
}
/// 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<String>` containing the HTML markup for the path header.
pub fn gen_path_header(
path_seperations: Vec<&str>,
domain: &str,
link: bool,
) -> PreEscaped<String> {
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 fn favicon(site: &str) -> PreEscaped<String> {
html! {
img class="h-8 w-8 m-2" src=(format!("/favicon/{site}")) {};
}
}