Rust library to generate static websites
1use maud::Markup;
2use maud::PreEscaped;
3use maud::html;
4use maudit::route::PageContext;
5
6pub fn header(
7 ctx: &mut PageContext,
8 bottom_border: bool,
9) -> Result<Markup, maudit::errors::AssetError> {
10 ctx.assets.include_script("assets/mobile-menu.ts")?;
11
12 let border = if bottom_border { "border-b" } else { "" };
13 let nav_links = vec![
14 ("/docs/", "Documentation"),
15 ("/news/", "News"),
16 ("/contribute/", "Contribute"),
17 ("https://github.com/bruits/maudit/issues/1", "Roadmap"),
18 ];
19 let social_links = vec![
20 (
21 "/chat/",
22 "Join our Discord",
23 include_str!("../../assets/discord.svg"),
24 ),
25 (
26 "https://github.com/bruits/maudit",
27 "View on GitHub",
28 include_str!("../../assets/github.svg"),
29 ),
30 ];
31
32 Ok(html! {
33 header.px-4.md:px-8.py-4.text-our-black.bg-our-white."border-borders".(border) {
34 div.container.flex.items-center.mx-auto.justify-between {
35 div.flex.items-center.gap-x-8 {
36 a.flex.gap-x-2.items-center href="/" {
37 (PreEscaped(include_str!("../../assets/logo.svg")))
38 h1.text-2xl.tracking-wide { "Maudit" }
39 }
40 nav.text-lg.gap-x-12.relative."top-[2px]".hidden."md:flex" {
41 @for (href, text) in &nav_links {
42 a href=(href) { (text) }
43 }
44 }
45 }
46
47 div.gap-x-6.hidden.md:flex {
48 @for (href, _text, icon_svg) in &social_links {
49 a href=(href) {
50 span.sr-only { (_text) }
51 (PreEscaped(icon_svg))
52 }
53 }
54 }
55
56 div.md:hidden.flex.align-middle.justify-center.items-center {
57 button id="mobile-menu-button" aria-label="Toggle main menu" {
58 span id="hamburger-icon" {
59 (PreEscaped(include_str!("../../assets/hamburger.svg")))
60 }
61 span id="close-icon" .hidden {
62 (PreEscaped(include_str!("../../assets/close.svg")))
63 }
64 }
65 }
66 }
67 }
68
69 // Mobile menu panel
70 div id="mobile-menu-panel" .fixed.left-0.w-full.bg-our-white.transform."-translate-x-4".transition-all.opacity-0.pointer-events-none.z-50 style="top: 65px; bottom: 0;" {
71 nav {
72 @for (href, text) in &nav_links {
73 a.block.text-2xl.font-medium.text-our-black.px-4.py-4.border-b.border-borders href=(href) { (text) }
74 }
75 }
76 div.px-6.py-8.flex.flex-wrap.gap-8 {
77 @for (href, text, icon_svg) in &social_links {
78 a.flex.items-center href=(href) {
79 span.sr-only { (text) }
80 (PreEscaped(icon_svg))
81 }
82 }
83 }
84 }
85 })
86}