use chrono::TimeDelta; use maud::{DOCTYPE, Markup, PreEscaped, html}; use page::page::{Page, PageMetadata}; use std::pin::Pin; use crate::components::{ md::{Markdown, backlinks, meta_from_markdown}, misc::FarLink, }; mod handouts; mod index; mod notfound; pub use handouts::handouts; pub use index::index; pub use notfound::notfound; pub fn links() -> Page { /* Dead links: https://www.commitstrip.com/en/ http://www.3dprintmath.com/ */ page_from_markdown( include_str!("links.md"), Some("/assets/img/icon.png".to_owned()), ) } pub fn betalupi() -> Page { page_from_markdown( include_str!("betalupi.md"), Some("/assets/img/icon.png".to_owned()), ) } pub fn htwah_typesetting() -> Page { page_from_markdown( include_str!("htwah-typesetting.md"), Some("/assets/img/icon.png".to_owned()), ) } // // MARK: md // fn page_from_markdown(md: impl Into, default_image: Option) -> Page { let md: String = md.into(); let md = Markdown::parse(&md); let mut meta = meta_from_markdown(&md) .unwrap_or(Some(PageMetadata { title: "Invalid frontmatter!".into(), ..Default::default() })) .unwrap_or_default(); if meta.image.is_none() { meta.image = default_image } let html = PreEscaped(md.render()); Page { meta, immutable: true, html_ttl: Some(TimeDelta::days(1)), generate_html: Box::new(move |page, ctx| { let html = html.clone(); Box::pin(async move { let inner = html! { @if let Some(backlinks) = backlinks(page, ctx) { (backlinks) } (html) }; page_wrapper(&page.meta, inner, true).await }) }), } } // // MARK: wrapper // pub fn page_wrapper<'a>( meta: &'a PageMetadata, inner: Markup, footer: bool, ) -> Pin + 'a + Send + Sync>> { Box::pin(async move { html! { (DOCTYPE) html { head { meta charset="UTF8" {} meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" {} meta content="text/html; charset=UTF-8" http-equiv="content-type" {} meta property="og:type" content="website" {} link rel="stylesheet" href=("/assets/css/main.css") {} (&meta) title { (PreEscaped(meta.title.clone())) } // Use a small blurred placeholder while full-size images load. // Requires no other special scripts or css, just add some tags // to your ! script { (PreEscaped(" window.onload = function() { var imgs = document.querySelectorAll('.img-placeholder'); imgs.forEach(img => { img.style.border = 'none'; img.style.filter = 'blur(10px)'; img.style.transition = 'filter 0.3s'; var lg = new Image(); lg.src = img.dataset.large; lg.onload = function () { img.src = img.dataset.large; img.style.filter = 'blur(0px)'; }; }) } ")) } } body { main{ div class="wrapper" style=( // for 404 page. Margin makes it scroll. match footer { true => "margin-top:3ex;", false =>"" } ) { (inner) @if footer { footer { hr class = "footline" {} div class = "footContainer" { p { "This site was built by hand with " (FarLink("https://rust-lang.org", "Rust")) ", " (FarLink("https://maud.lambda.xyz", "Maud")) ", " (FarLink("https://github.com/connorskees/grass", "Grass")) ", and " (FarLink("https://docs.rs/axum/latest/axum", "Axum")) "." } } } } } }} } } }) }