webarc/src/pages/component.rs

86 lines
2.5 KiB
Rust
Raw Normal View History

2025-02-09 00:07:28 +01:00
use based::ui::prelude::*;
use maud::{html, PreEscaped, Render};
2024-12-30 09:57:42 +01:00
/// 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> {
2025-02-09 00:07:28 +01:00
Padding(Text("/").bold().color(&Gray::_400))
.all(ScreenValue::_2)
.render()
2024-12-30 09:57:42 +01:00
}
/// 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();
2025-02-09 00:07:28 +01:00
Link(
&format!("/d/{}/{}", domain, upto.join("/")),
path.to_string(),
)
.use_htmx()
.render()
2024-12-30 09:57:42 +01:00
}
/// 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.
2024-12-30 21:25:40 +01:00
pub fn gen_path_header(
path_seperations: Vec<&str>,
domain: &str,
link: bool,
) -> PreEscaped<String> {
2024-12-30 09:57:42 +01:00
html! {
@for (index, path) in path_seperations.iter().enumerate() {
2024-12-30 21:25:40 +01:00
@if link {
2024-12-30 09:57:42 +01:00
(gen_path_link(path, index, &path_seperations, domain))
2024-12-30 21:25:40 +01:00
} @else {
p { (path) }
}
2024-12-30 09:57:42 +01:00
@if index < path_seperations.len()-1 {
(slash_seperator())
};
};
}
}
2024-12-30 22:14:39 +01:00
pub fn favicon(site: &str) -> PreEscaped<String> {
html! {
img class="h-8 w-8 m-2" src=(format!("/favicon/{site}")) {};
}
}