// SPDX-License-Identifier: 0BSD // Copyright © Paweł Redman #let webroot = "/" #let format-date-en(date) = { let months = ( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ) [#months.at(date.month() - 1) #date.day(), #date.year()] } #let link-self(page, body) = { let parts = page.split("#") let url = if parts.len() == 1 { webroot + page + ".html" } else { webroot + parts.at(0) + ".html#" + parts.slice(1).join("#") } link(url, body) } #let static(path) = { webroot + "static/" + path } #let img(src, alt: "") = { html.elem("img", attrs: (src: src, alt: alt)) } #let anchor(name) = { html.elem("span", attrs: (id: name))[] } #let breadcrumbs() = { let path = sys.inputs.at("path") let parts = path.split("/") link(webroot)[redman.xyz] for (i, part) in parts.enumerate() { let is_last = i == parts.len() - 1 let url = parts.slice(0, i + 1).join("/") + "/index.html" if is_last { " / " part } else { " / " link(webroot + url, part) } } } #let template(title, header, main, front_page: false) = { let body_attrs = if front_page { (class: "front-page") } else { (:) } html.html({ html.head({ html.meta(charset: "utf-8") html.meta(name: "viewport", content: "width=device-width, initial-scale=1") html.title(title) html.link(rel: "stylesheet", href: static("style.css")) }) html.elem("body", attrs: body_attrs, { html.header(header) html.main(main) html.footer[ © 2019--2026 Paweł Redman \ Text and images are licensed under #link("https://creativecommons.org/licenses/by-sa/4.0/")[CC-BY-SA 4.0] unless noted otherwise. ] }) }) } #let post(body, title: none, author: "Paweł Redman", date: none, updated: none) = { set document( title: title, author: author, ) set text(lang: "en") set heading(numbering: "1.1.") set math.equation(numbering: "(1.)") // As of 0.14, equations aren't supported in HTML. Emit them as SVG instead. show math.equation: it => context { show: if it.block { it => it } else { box } if it.block { html.elem("div", attrs: (class: "block-math"))[ #html.frame(it) ] } else { html.frame(it) } } if date != none { [ #metadata(( title: title, date_year: date.year(), date_month: date.month(), date_day: date.day(), )) ] } else { [ #metadata(( title: title, )) ] } template( title, html.nav(breadcrumbs()), html.article({ html.header({ html.h1(title) if date != none { html.p(id: "author")[ by #author, published on #html.time(datetime: date)[#format-date-en(date)] #if updated != none { [, updated on #html.time(datetime: updated)[#format-date-en(updated)]] } ] } }) body }), ) }