Skip to main content

static_page_builder/
partials.rs

1//! A series of components used across the site.
2use crate::data::PageMetaData;
3use maud::{html, Markup, DOCTYPE};
4
5/// The `<head>` portion of the webpage.
6pub fn head(meta: &PageMetaData) -> Markup {
7    html! {
8        head {
9            meta charset=(meta.charset);
10            title { (meta.title) }
11            meta name="description" content=(meta.description);
12            meta name="viewport" content="width=device-width, initial-scale=1";
13            meta name="theme-color" content=(meta.theme_color);
14            @for f in meta.favicons {
15                (f)
16            }
17            @for css in meta.css {
18                (css)
19            }
20            @for js in meta.scripts {
21                (js)
22            }
23        }
24    }
25}
26
27/// The `<header>` portion of the webpage. Displays logos and menus.
28pub fn header(meta: &PageMetaData) -> Markup {
29    html! {
30        header.site-header {
31            @if let Some(logo) = meta.logo {
32                (logo)
33            }
34            @if let Some(menu) = meta.menu {
35                (menu)
36            }
37        }
38    }
39}
40
41/// The `<footer>` portion of the webpage. Displays copyright and contact information.
42pub fn footer(meta: &PageMetaData) -> Markup {
43    html! {
44        footer.site-footer {
45            @if let Some(contact) = meta.contact {
46                (contact)
47            }
48            (meta.copyright)
49        }
50    }
51}
52
53/// The `<body>` portion of the webpage. Wraps the main content and offsets it from the header and
54/// footer.
55pub fn body(m: Markup, meta: &PageMetaData) -> Markup {
56    html! {
57        body {
58            div.bg-img {}
59            (header(meta))
60            main.site-body {
61                (m)
62            }
63            (footer(meta))
64        }
65    }
66}
67
68/// A template of the page with its `<DOCTYPE>` and `<html>` tags.
69pub fn page(m: Markup, meta: &PageMetaData) -> Markup {
70    html! {
71        (DOCTYPE)
72        html lang=(meta.lang) {
73            (head(&meta))
74            (body(m, &meta))
75        }
76    }
77}
78
79/// A template of a page. Uses default [`MetaData`](crate::data::MetaData) if not provided.
80pub fn basic_page(m: Markup, meta_data: Option<&PageMetaData>) -> Markup {
81    let store;
82    let meta;
83    if let Some(meta_ref) = meta_data {
84        meta = meta_ref;
85    } else {
86        store = PageMetaData::default();
87        meta = &store;
88    }
89    page(m, meta)
90}