summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs48
1 files changed, 40 insertions, 8 deletions
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<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() {
" / "
}
}