#![feature(negative_impls)] #![feature(freeze)] #![feature(freeze_impls)] #![feature(portable_simd)] #![feature(concat_bytes)] #![allow(internal_features)] #![allow(mutable_transmutes)] use maud::{DOCTYPE, Markup, PreEscaped, html}; use worker::*; pub mod dateparse; pub mod solar; use crate::{ dateparse::dateparse, solar::{dow, solar, SexagenaryDate}, }; #[event(fetch)] async fn fetch(req: Request, env: Env, _ctx: Context) -> Result { Router::new() .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 = unsafe { String::from_utf8_unchecked(a.bytes().await?) }; 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 { @let mut peek = a.split('\n').map(|l| { (l, dateparse(l).map(|c| { let (m, d, y) = c; let y = y + 2000; let (dowc, dowl) = dow(y, m, d); let SexagenaryDate { year: y, month: m, day: d, term: t, } = solar(y, m, d); let href = l.replace('/', "_"); html! { (PreEscaped("")) a name=(href) { } a class="sec" href={"#" (href)} { (format!("{l} {dowl}. {y}年 {m}月 {d}日 ({dowc})")) @if let Some((t, _)) = t { " " (t) } } (PreEscaped("
"))
                            }
                        }))
                    }).peekable();
                    @while let Some((l, d)) = peek.next() {
                        @if let Some(h) = d {
                            (h)
                        } @else {
                            (PreEscaped(l))
                            @if let Some((_, None)) = &peek.peek() {
                                "\n"
                            }
                        }
                    }
                }
            })
        })
        .get("/", |_, _| {
            bone("home", "ataxia.moe: like i heard a transmission from Apollo 13", html! {
                p style="padding: 1vw" {
                    "No. Stop." br; br; "Check out "
                    a href="/shitpit" { "the shitpit" }
                    " in the meantime."
                }
            })
        })
        .get("/about", |_, _| {
            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;
                    "Hosted on "
                    a href="https://developers.cloudflare.com/workers/" { "Cloudflare Workers" }
                    ". Source available "
                    a href="https://git.neetlo.li/ataxia/tree" { "here" }
                    "."
                    br; br;
                    "I may be contacted by shouting loudly on the Internet, though I doubt there would be a need to."
                }
            })
        })
        .or_else_any_method("/*catchall" /* wtf is this syntax? */ , |req, _| {
            match req.path().as_ref() {
                "/index.html" => Response::redirect(req.url()?.join("/")?),
                "/journal" | "/diary" => Response::redirect(req.url()?.join("shitpit")?),
                _ => Ok(bone("", "404 Not Found", html! {
                    p style="padding: 1vw" { "what?" }
                })?.with_status(404)),
            }
        })
        .run(req, env)
        .await
}

fn header() -> Markup {
    let css = r"/* i dont know css im so fucking sorry ill fix it l8r */
pre {
  white-space: pre-wrap;
  white-space: -moz-pre-wrap;
  white-space: -pre-wrap;
  white-space: -o-pre-wrap;
  word-wrap: break-word;
  font-family: serif;
}
.remark {
  box-sizing: content-box;
  border-top: 0px solid #000;
  border-left: 0px solid #000;
  border-right: 0px solid #000;
  border-bottom: 1px solid #000;
  padding: 1vw;
  padding-top: 0;
}
.nav {
  border-bottom: 1px solid #000;
  padding: 1vw;
  padding-top: 0;
}
main {
  border: 1px #000 solid;
}
body {
  background-color: #eee;
}

p, a.sec, pre {
  padding: 0 3vw;
}
@media only screen and (min-width: 800px) {

  p, a.sec, pre {
    padding: 0 4vw;
    /*align: center;
    display:flex;
    align-items: center;
    justify-content: center;*/
  }
}
pre {
  font-size: 14pt;
}
a, p { font-size: 14pt; }
a.splink { color: #005953; font-size: inherit; }
a.sec, a.menu, a.menuon {
  color: #005953;
  font-family: 'Iansui', serif;
  font-size: 1.5em;
}
a.sec:link, a.sec:visited, a.sec:active {
   text-decoration: none;
}
a.sec:hover, a.sec:focus {
   text-decoration: underline;
}
a.menu:link, a.menu:visited, a.menu:active {
   text-decoration: none;
}
a.menu:hover, a.menu:focus {
   text-decoration: underline;
}
@media (prefers-color-scheme: dark) {
  body {
    background-color: #222;
    color: #dcdccc;
  }
  .nav, .remark {
    border-bottom: 1px solid #dcdccc;
  }
  main {
    border: 1px #dcdccc solid;
  }
  a.splink, a.sec, a.menu, a.menuon { color: #51bd96; }
}
@font-face {
  font-family: 'Iansui';
  font-style: normal;
  font-display: swap;
  font-weight: 400;
  src: url(/_/iansui.woff2) format('woff2');
  unicode-range: U+3000-303F,U+3105-312F,U+4E00-9FFF;
}
body {
  max-width: 960px;
  margin-left: auto;
  margin-right: auto;
}
.f,.f *{position:fixed;height:100%;top:0;left:50%}
.f *{transform:translate(-50%,0)}
.f{display:none;left:0;width:100%;background:rgba(0,0,0,0.8)}
*:focus+.f{display:block}
";
    html! {
        (DOCTYPE)
        style { (PreEscaped(css)) }
        (PreEscaped(r#""#))
    }
}

fn menu(nav: &str) -> Markup {
    html! {
        div class="nav" {
            @let mut navs = [
                ("home", "/"),
                ("shitpit", "/shitpit"),
                ("about", "/about"),
            ].iter().peekable();
            @while let Some(&(n, l)) = navs.next() {
                a class=(if n == nav { "menuon" } else { "menu" }) href=(l) {
                    (n)
                }
                @if navs.peek().is_some() { " / " }
            }
        }
    }
}

fn bone(wh: &str, rm: &str, b: Markup) -> Result {
    Response::from_html(
        (html! {
            (header())
            main id="content" {
                h2 class="remark" { (rm) }
                (menu(wh))
                (b)
            }
        })
        .into_string(),
    )
}