From 3b8d4c4f0d03d7e0951049611384c61d1d498f3a Mon Sep 17 00:00:00 2001 From: u <@> Date: Tue, 10 Mar 2026 10:17:43 +0200 Subject: a --- src/lib.rs | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 1276657..0576324 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,25 @@ +#![allow(mutable_transmutes)] use maud::{html, Markup, PreEscaped, DOCTYPE}; use regex::Regex; +use std::mem::{take, transmute}; use worker::*; pub mod solar; -use crate::solar::{dow, ganzhi, solar, SexagenaryDate, Term, TERMS}; +use crate::solar::{dow, solar}; + +async fn text(r: &mut Response) -> Result { + match r.body() { + ResponseBody::Body(bytes) => unsafe { + let bytes = transmute::<&Vec, &mut Vec>(bytes); + Ok(String::from_utf8_unchecked(take(bytes))) + }, + ResponseBody::Empty => Ok(String::new()), + ResponseBody::Stream(_) => unsafe { + let bytes = r.bytes().await?; + Ok(String::from_utf8_unchecked(bytes)) + }, + } +} #[event(fetch)] async fn fetch(req: Request, env: Env, _ctx: Context) -> Result { @@ -17,12 +33,24 @@ async fn fetch(req: Request, env: Env, _ctx: Context) -> Result { .get_async("/shitpit", |req, ctx| async move { let u = req.url()?; let a = ctx.env.assets("ASSETS")?; - let mut a = a.fetch(u.join("/_/diary")?, None).await?; - let a = a.text().await?; + let mut a = a.fetch(u.join("_/diary")?, None).await?; + let a = text(&mut a).await?; let re = Regex::new( r"(0[1-9]|[1-9]|1[0-2])\/(0[1-9]|[1-9]|1\d|2\d|3[01])\/(\d{2})$", ).unwrap(); bone("shitpit", "look in the sky! it's a bird! it's a plane! no it's superego!", html! { + p { + "The numbering system for people (#1, #2, ...) is arbitrary and " + "the numbers do not denote interpersonal proximity." + } + p { + "The Chinese characters next to Western dates (mm/dd/yy format) are " + "traditional Chinese " + a href="https://en.wikipedia.org/wiki/Sexagenary_cycle" { + "Sexagenary cycle" + } + " dates." + } pre { @for x in a.split('\n').map(|l| { let l = l.trim(); @@ -64,7 +92,7 @@ async fn fetch(req: Request, env: Env, _ctx: Context) -> Result { }) }) .get("/about", |_, _| { - bone("about", "And they completely goddamn disrespected me! Little idiots! Idiots!", html! { + bone("about", "And they completely goddamn disrespected me! Little idiots! Idiots!!", html! { p style="padding: 1vw" { "Ataxia is a nervous system dysfunction consisting of poor coördination of muscle movements such as gait abnormalities, slurring of speech, and eye movement issues." br; br; @@ -181,12 +209,16 @@ body { fn menu(nav: &str) -> Markup { html! { div class="nav" { - @let mut navs = ["home", "shitpit", "about"].iter().peekable(); + @let mut navs = [ + ("home", "/"), + ("shitpit", "/shitpit"), + ("about", "/about"), + ].iter().peekable(); @while let Some(&n) = navs.next() { - a class=(if n == nav { "menuon" } else { "menu" }) href={"/" (n)} { - (n) + a class=(if n.0 == nav { "menuon" } else { "menu" }) href=(n.1) { + (n.0) } - @if navs.next().is_some() { + @if navs.peek().is_some() { " / " } } -- cgit v1.2.3