diff options
| author | u <@> | 2026-03-10 10:17:43 +0200 |
|---|---|---|
| committer | u <@> | 2026-03-10 10:17:43 +0200 |
| commit | 3b8d4c4f0d03d7e0951049611384c61d1d498f3a (patch) | |
| tree | f8688c8f756f7b4707db865325191fa7caaa02af /src | |
| parent | 45329d748b964748ba4f09b70500d81137aad487 (diff) | |
a
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 48 | ||||
| -rw-r--r-- | src/solar.rs | 16 |
2 files changed, 48 insertions, 16 deletions
@@ -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<String> { + match r.body() { + ResponseBody::Body(bytes) => unsafe { + let bytes = transmute::<&Vec<u8>, &mut Vec<u8>>(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<Response> { @@ -17,12 +33,24 @@ async fn fetch(req: Request, env: Env, _ctx: Context) -> Result<Response> { .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<Response> { }) }) .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() { " / " } } diff --git a/src/solar.rs b/src/solar.rs index af52afc..06cffb3 100644 --- a/src/solar.rs +++ b/src/solar.rs @@ -5,8 +5,7 @@ // based on https://prospertimes.neocities.org/solarterms.js use lazy_static::lazy_static; -use num::{cast, traits::AsPrimitive}; -use std::num::Wrapping as W; +use num::cast; use std::{ f64::consts::PI, mem::MaybeUninit, @@ -75,6 +74,7 @@ pub const TERMS: [Term; 24] = terms![ {"冬至", 270, 12, 19, 23}, ]; +// julian d8 fn compute_JD(mut y: f64, mut m: f64, d: f64) -> f64 { if m <= 2. { y -= 1.; @@ -107,6 +107,7 @@ fn compute_ang(jd: f64) -> f64 { Lapp } +#[inline(always)] fn bisect<T>( lo: &mut f64, hi: &mut f64, @@ -221,6 +222,9 @@ fn stday(i: usize, y: usize) -> f64 { lazy_static! { static ref GANZHIS: Vec<String> = { + const gan: [char; 10] = ['甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸']; + const zhi: [char; 12] = [ '子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', + '戌', '亥', ]; let mut tmp: Vec<String> = vec![]; tmp.reserve(60); (0..60).for_each(|i| { @@ -233,18 +237,14 @@ lazy_static! { tmp }; } -const gan: [char; 10] = - ['甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸']; -const zhi: [char; 12] = [ - '子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥', -]; + pub fn ganzhi(i: usize) -> &'static str { &GANZHIS[i] } #[inline(always)] fn int(x: f64) -> usize { - x as usize + x as usize // x.as_int_unchecked() // wont work on wasm } lazy_static! { |
