From 3b8d4c4f0d03d7e0951049611384c61d1d498f3a Mon Sep 17 00:00:00 2001 From: u <@> Date: Tue, 10 Mar 2026 10:17:43 +0200 Subject: a --- .gitignore | 1 + assets/_/diary | 3 --- deploy.sh | 8 ++++++++ src/lib.rs | 48 ++++++++++++++++++++++++++++++++++++++++-------- src/solar.rs | 16 ++++++++-------- test.sh | 3 +++ wrangler.toml | 4 ---- 7 files changed, 60 insertions(+), 23 deletions(-) create mode 100755 deploy.sh create mode 100755 test.sh diff --git a/.gitignore b/.gitignore index d27315f..b26c921 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ target node_modules .wrangler +apikeys diff --git a/assets/_/diary b/assets/_/diary index aeb44f0..612ef56 100644 --- a/assets/_/diary +++ b/assets/_/diary @@ -1,6 +1,3 @@ -3/9/26 - - 3/8/26 I spent the entire day (re)watching Mahou Shoujo Madoka ☆ Magica, the mood I was in and the substances I was intoxicated with made for a borderline religious experience. My favorite character gotta be Miki Sayaka specifically because I can see myself in her idiotic vacillations between stubborn feeble mindedness and literally every single event happening to her taking something away from her. Madoka feels like a "baseline" in the story and I can't remember anything remarkable she did except for maybe becoming god in the end or whatever, I don't understand why people like her. Akemi Homura ends up ripping her apart(?)(i.e., copying the records of human kaname madoka (idk)) in the movie and creates a fake world where everything goes right (in her perspective). I am media illiterate so I didn't really "learn" anything from the anime. Maybe be kind to people because you never know when a time traveler will relive the same month a hundred times just to change your potentially unauspicious fate? Or alternatively, don't be nice to people because you never know when a time traveler will turn into a demon after you become God and rip you apart because she loves you so much? I don't know. Maybe "don't go against your fate"? I genuinely enjoyed the experimental-looking mix of art styles for witches and whatnot. diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..1c40038 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +cp ~/Documents/diary assets/_ +. ./apikeys +curl "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/purge_cache" \ + -H 'Content-Type: application/json' \ + -H "Authorization: Bearer ${APIKEY}" \ + -d '{ "purge_everything": true }' +npx wrangler deploy 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() { " / " } } 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( lo: &mut f64, hi: &mut f64, @@ -221,6 +222,9 @@ fn stday(i: usize, y: usize) -> f64 { lazy_static! { static ref GANZHIS: Vec = { + const gan: [char; 10] = ['甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸']; + const zhi: [char; 12] = [ '子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', + '戌', '亥', ]; let mut tmp: Vec = 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! { diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..2da20cf --- /dev/null +++ b/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +cp ~/Documents/diary assets/_ +worker-build --debug diff --git a/wrangler.toml b/wrangler.toml index b5d670b..5dc0e7c 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -8,7 +8,3 @@ command = "cargo install -q \"worker-build@^0.7\" && worker-build --release" [assets] directory = "./assets" binding = "ASSETS" - -[[kv_namespaces]] -binding = "ataxia" -id = "828dc8eb6d514054a382c3070dc94e8c" -- cgit v1.2.3