diff options
| author | Xe Iaso <me@christine.website> | 2023-09-30 10:36:37 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-30 10:36:37 -0400 |
| commit | ac6a3df0d18cc73524c0096d954a57d24cad5669 (patch) | |
| tree | 81474177d730440657f490ae29892d62392251ea /src | |
| parent | cbdea8ba3fca9a663778af71f8df5965aeb6c090 (diff) | |
| download | xesite-ac6a3df0d18cc73524c0096d954a57d24cad5669.tar.xz xesite-ac6a3df0d18cc73524c0096d954a57d24cad5669.zip | |
Xesite V4 (#723)
* scripts/ditherify: fix quoting
Signed-off-by: Xe Iaso <me@xeiaso.net>
* clean up some old files
Signed-off-by: Xe Iaso <me@xeiaso.net>
* import site into lume
Signed-off-by: Xe Iaso <me@xeiaso.net>
* initial go code
Signed-off-by: Xe Iaso <me@xeiaso.net>
* move vods index to top level
Signed-off-by: Xe Iaso <me@xeiaso.net>
* remove the ads
Signed-off-by: Xe Iaso <me@xeiaso.net>
* internal/lume: metrics
Signed-off-by: Xe Iaso <me@xeiaso.net>
* delete old code
Signed-off-by: Xe Iaso <me@xeiaso.net>
* load config into memory
Signed-off-by: Xe Iaso <me@xeiaso.net>
* autogenerate data from dhall config
Signed-off-by: Xe Iaso <me@xeiaso.net>
* various cleanups, import clackset logic
Signed-off-by: Xe Iaso <me@xeiaso.net>
* Update signalboost.dhall (#722)
Added myself, and also fixed someone’s typo
* Add Connor Edwards to signal boost (#721)
* add cache headers
Signed-off-by: Xe Iaso <me@xeiaso.net>
* move command to xesite folder
Signed-off-by: Xe Iaso <me@xeiaso.net>
* xesite: listen for GitHub webhook push events
Signed-off-by: Xe Iaso <me@xeiaso.net>
* xesite: 5 minute timeout for rebuilding the site
Signed-off-by: Xe Iaso <me@xeiaso.net>
* xesite: add rebuild metrics
Signed-off-by: Xe Iaso <me@xeiaso.net>
* xesite: update default variables
Signed-off-by: Xe Iaso <me@xeiaso.net>
* don't commit binaries oops lol
Signed-off-by: Xe Iaso <me@xeiaso.net>
* lume: make search have a light background
Signed-off-by: Xe Iaso <me@xeiaso.net>
* add a notfound page
Signed-off-by: Xe Iaso <me@xeiaso.net>
* fetch info from patreon API
Signed-off-by: Xe Iaso <me@xeiaso.net>
* create contact page
Signed-off-by: Xe Iaso <me@xeiaso.net>
* Toot embedding
Signed-off-by: Xe Iaso <me@xeiaso.net>
* attempt a docker image
Signed-off-by: Xe Iaso <me@xeiaso.net>
* lume: fix deno lock
Signed-off-by: Xe Iaso <me@xeiaso.net>
* add gokrazy post
Signed-off-by: Xe Iaso <me@xeiaso.net>
* cmd/xesite: go up before trying to connect to the saas proxy
Signed-off-by: Xe Iaso <me@xeiaso.net>
* blog: add Sine post/demo
Signed-off-by: Xe Iaso <me@xeiaso.net>
---------
Signed-off-by: Xe Iaso <me@xeiaso.net>
Co-authored-by: bri <284789+b-@users.noreply.github.com>
Co-authored-by: Connor Edwards <38229097+cedws@users.noreply.github.com>
Diffstat (limited to 'src')
35 files changed, 0 insertions, 3490 deletions
diff --git a/src/app/config.rs b/src/app/config.rs deleted file mode 100644 index a0f1273..0000000 --- a/src/app/config.rs +++ /dev/null @@ -1,391 +0,0 @@ -use crate::signalboost::Person; -use chrono::prelude::*; -use maud::{html, Markup, Render}; -use serde::{Deserialize, Serialize}; -use std::{ - collections::HashMap, - fmt::{self, Display}, -}; - -mod markdown_string; -use markdown_string::MarkdownString; - -#[derive(Clone, Deserialize, Default)] -pub struct Config { - pub signalboost: Vec<Person>, - pub authors: HashMap<String, Author>, - #[serde(rename = "defaultAuthor")] - pub default_author: Author, - pub port: u16, - #[serde(rename = "clackSet")] - pub clack_set: Vec<String>, - #[serde(rename = "miToken")] - pub mi_token: String, - #[serde(rename = "jobHistory")] - pub job_history: Vec<Job>, - #[serde(rename = "seriesDescriptions")] - pub series_descriptions: Vec<SeriesDescription>, - #[serde(rename = "seriesDescMap")] - pub series_desc_map: HashMap<String, String>, - #[serde(rename = "notableProjects")] - pub notable_projects: Vec<Link>, - #[serde(rename = "contactLinks")] - pub contact_links: Vec<Link>, - pub pronouns: Vec<PronounSet>, - pub characters: Vec<Character>, - pub vods: Vec<VOD>, -} - -#[derive(Clone, Deserialize, Serialize, Default)] -pub struct PronounSet { - pub nominative: String, - pub accusative: String, - #[serde(rename = "possessiveDeterminer")] - pub possessive_determiner: String, - pub possessive: String, - pub reflexive: String, - pub singular: bool, -} - -impl Render for PronounSet { - fn render(&self) -> Markup { - html! { - big { (self.nominative) "/" (self.accusative) } - table { - tr { - th { "Subject" } - td {(self.nominative)} - } - tr { - th { "Object" } - td {(self.accusative)} - } - tr { - th { "Dependent Possessive" } - td {(self.possessive_determiner)} - } - tr { - th { "Independent Possessive" } - td {(self.possessive)} - } - tr { - th { "Reflexive" } - td {(self.reflexive)} - } - } - p {"Here are some example sentences with these pronouns:"} - ul { - li { i{(self.nominative)} " went to the park." } - li { "I went with " i{(self.accusative)} "." } - li { i{(self.nominative)} " brought " i{(self.possessive_determiner)} " frisbee." } - li { "At least I think it was " i{(self.possessive)} "." } - li { i{(self.nominative)} " threw the frisbee to " i{(self.reflexive)} "." } - } - @if !self.singular { - p { - "Please note that this pronoun is normally a plural pronoun. It is used here to refer to a single person. For more information on this, see " - a href="https://www.merriam-webster.com/words-at-play/singular-nonbinary-they" {"this page from Merriam-Webster"} - " that will explain in more detail." - } - } - } - } -} - -#[derive(Clone, Deserialize, Serialize, Default)] -pub struct Character { - pub name: String, - #[serde(rename = "stickerName")] - pub sticker_name: String, - #[serde(rename = "defaultPose")] - pub default_pose: String, - pub description: MarkdownString, - pub pronouns: PronounSet, - pub stickers: Vec<String>, -} - -impl Render for Character { - fn render(&self) -> Markup { - html! { - h3 #(self.sticker_name) {(self.name)} - (xesite_templates::sticker(self.sticker_name.clone(), self.default_pose.clone())) - p {(self.description)} - details { - summary { "Pronouns (" (self.pronouns.nominative) "/" (self.pronouns.accusative) ")" } - (self.pronouns) - } - - details { - summary { "All stickers" } - .grid { - @for sticker in &self.stickers { - .cell."-3of12" { - (xesite_templates::sticker(self.sticker_name.clone(), sticker.clone())) - br; - (sticker) - } - } - } - } - } - } -} - -#[derive(Clone, Deserialize, Serialize, Default)] -pub struct Link { - pub url: String, - pub title: String, - pub description: String, -} - -impl Render for Link { - fn render(&self) -> Markup { - html! { - span { - a href=(self.url) {(self.title)} - @if !self.description.is_empty() { - ": " - (self.description) - } - } - } - } -} - -#[derive(Clone, Default, Deserialize, Serialize)] -pub enum StockKind { - Grant, - #[default] - Options, -} - -fn schema_context() -> String { - "http://schema.org/".to_string() -} - -fn schema_person_type() -> String { - "Person".to_string() -} - -#[derive(Clone, Deserialize, Serialize, Default)] -pub struct Author { - #[serde(rename = "@context", default = "schema_context")] - pub context: String, - #[serde(rename = "@type", default = "schema_person_type")] - pub schema_type: String, - pub name: String, - #[serde(skip_serializing)] - pub handle: String, - #[serde(rename = "image", skip_serializing_if = "Option::is_none")] - pub pic_url: Option<String>, - #[serde(rename = "inSystem", skip_serializing)] - pub in_system: bool, - #[serde(rename = "jobTitle")] - pub job_title: String, - #[serde(rename = "sameAs")] - pub same_as: Vec<String>, - #[serde(skip_serializing_if = "Option::is_none")] - pub url: Option<String>, -} - -#[derive(Clone, Deserialize, Serialize, Default)] -pub struct SeriesDescription { - pub name: String, - pub details: String, -} - -impl Render for SeriesDescription { - fn render(&self) -> Markup { - html! { - span { - a href={"/blog/series/" (self.name)} { (self.name) } - ": " - (self.details) - } - } - } -} - -#[derive(Clone, Deserialize, Serialize, Default)] -pub struct Stock { - pub amount: i32, - #[serde(rename = "cliffYears")] - pub cliff_years: i32, - pub kind: StockKind, - pub liquid: bool, - #[serde(rename = "vestingYears")] - pub vesting_years: i32, -} - -#[derive(Clone, Deserialize, Serialize, Default)] -pub struct Location { - pub city: String, - #[serde(rename = "stateOrProvince")] - pub state_or_province: String, - pub country: String, - pub remote: bool, -} - -#[derive(Clone, Deserialize, Serialize, Default)] -pub struct Salary { - pub amount: i32, - pub per: String, - pub currency: String, - pub stock: Option<Stock>, -} - -impl Display for Salary { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}${}/{}", self.currency, self.amount, self.per) - } -} - -impl Render for Salary { - fn render(&self) -> Markup { - if self.stock.is_none() { - return html! { (maud::display(self)) }; - } - - let stock = self.stock.as_ref().unwrap(); - html! { - details { - summary { - (maud::display(self)) - } - - p{ - (stock.amount) - " " - @if stock.liquid { - "liquid" - } - " " - @match stock.kind { - StockKind::Options => { - "options" - }, - StockKind::Grant => { - "granted shares" - } - } - ". Vesting for " - (stock.vesting_years) - " " - @if stock.vesting_years == 1 { - "year" - } @else { - "years" - } - " " - " with a cliff of " - (stock.cliff_years) - " " - @if stock.cliff_years == 1 { - "year" - } @else { - "years" - } - "." - } - } - } - } -} - -#[derive(Clone, Deserialize, Serialize, Default)] -pub struct Job { - pub company: Company, - pub title: String, - #[serde(rename = "startDate")] - pub start_date: String, - #[serde(rename = "endDate")] - pub end_date: Option<String>, - #[serde(rename = "daysWorked")] - pub days_worked: Option<i32>, - #[serde(rename = "daysBetween")] - pub days_between: Option<i32>, - pub salary: Salary, - #[serde(rename = "leaveReason")] - pub leave_reason: Option<String>, - pub locations: Vec<Location>, - pub highlights: Vec<String>, - #[serde(rename = "hideFromResume")] - pub hide_from_resume: bool, -} - -#[derive(Clone, Deserialize, Serialize, Default)] -pub struct Company { - pub name: String, - pub url: Option<String>, - pub tagline: String, - pub location: Location, - pub defunct: bool, -} - -impl Render for Job { - fn render(&self) -> Markup { - html! { - tr { - td { (self.title) } - td { (self.start_date) } - td { (self.end_date.as_ref().unwrap_or(&"current".to_string())) } - td { (if self.days_worked.is_some() { self.days_worked.as_ref().unwrap().to_string() } else { "n/a".to_string() }) } - td { (self.salary) } - td { (self.leave_reason.as_ref().unwrap_or(&"n/a".to_string())) } - } - } - } -} - -#[derive(Clone, Deserialize, Serialize, Default)] -pub struct VOD { - pub title: String, - pub slug: String, - pub date: NaiveDate, - pub description: MarkdownString, - #[serde(rename = "cdnPath")] - pub cdn_path: String, - pub tags: Vec<String>, -} - -impl VOD { - pub fn detri(&self) -> String { - self.date.format("M%m %d %Y").to_string() - } -} - -impl Render for VOD { - fn render(&self) -> Markup { - html! { - meta name="twitter:card" content="summary"; - meta name="twitter:site" content="@theprincessxena"; - meta name="twitter:title" content={(self.title)}; - meta property="og:type" content="website"; - meta property="og:title" content={(self.title)}; - meta property="og:site_name" content="Xe's Blog"; - meta name="description" content={(self.title) " - Xe's Blog"}; - meta name="author" content="Xe Iaso"; - - h1 {(self.title)} - small {"Streamed on " (self.detri())} - - (xesite_templates::advertiser_nag(Some(html!{ - (xesite_templates::conv("Cadey".into(), "coffee".into(), html!{ - "Hi. This page embeds a video file that is potentially multiple hours long. Hosting this stuff is not free. Bandwidth in particular is expensive. If you really want to continue to block ads, please consider donating via " - a href="https://patreon.com/cadey" {"Patreon"} - " because servers and bandwidth do not grow on trees." - })) - }))) - - (xesite_templates::video(self.cdn_path.clone())) - (self.description) - p { - "Tags: " - @for tag in &self.tags { - code{(tag)} - " " - } - } - } - } -} diff --git a/src/app/config/markdown_string.rs b/src/app/config/markdown_string.rs deleted file mode 100644 index 41a4ba5..0000000 --- a/src/app/config/markdown_string.rs +++ /dev/null @@ -1,63 +0,0 @@ -use maud::{html, Markup, PreEscaped, Render}; -use serde::{ - de::{self, Visitor}, - Deserialize, Deserializer, Serialize, -}; -use std::fmt; - -struct StringVisitor; - -impl<'de> Visitor<'de> for StringVisitor { - type Value = MarkdownString; - - fn visit_borrowed_str<E>(self, value: &'de str) -> Result<Self::Value, E> - where - E: de::Error, - { - Ok(MarkdownString(xesite_markdown::render(value).map_err( - |why| de::Error::invalid_value(de::Unexpected::Other(&format!("{why}")), &self), - )?)) - } - - fn visit_str<E>(self, value: &str) -> Result<Self::Value, E> - where - E: de::Error, - { - Ok(MarkdownString(xesite_markdown::render(value).map_err( - |why| de::Error::invalid_value(de::Unexpected::Other(&format!("{why}")), &self), - )?)) - } - - fn visit_string<E>(self, value: String) -> Result<Self::Value, E> - where - E: de::Error, - { - Ok(MarkdownString(xesite_markdown::render(&value).map_err( - |why| de::Error::invalid_value(de::Unexpected::Other(&format!("{why}")), &self), - )?)) - } - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("a string with xesite-flavored markdown") - } -} - -#[derive(Serialize, Clone, Default)] -pub struct MarkdownString(String); - -impl<'de> Deserialize<'de> for MarkdownString { - fn deserialize<D>(deserializer: D) -> Result<MarkdownString, D::Error> - where - D: Deserializer<'de>, - { - deserializer.deserialize_string(StringVisitor) - } -} - -impl Render for MarkdownString { - fn render(&self) -> Markup { - html! { - (PreEscaped(&self.0)) - } - } -} diff --git a/src/app/mod.rs b/src/app/mod.rs deleted file mode 100644 index 9648146..0000000 --- a/src/app/mod.rs +++ /dev/null @@ -1,159 +0,0 @@ -use crate::{post::Post, signalboost::Person}; -use chrono::prelude::*; -use color_eyre::eyre::Result; -use std::{path::PathBuf, sync::Arc}; -use tracing::{error, instrument}; - -pub mod config; -pub mod poke; - -pub use config::*; - -#[instrument] -async fn patrons() -> Result<Option<patreon::Users>> { - let mut p = dirs::home_dir().unwrap_or(".".into()); - p.push(".patreon.json"); - if !p.exists() { - info!("{:?} does not exist", p); - return Ok(None); - } - - let mut cli = patreon::Client::new()?; - - if let Err(why) = cli.refresh_token().await { - error!("error getting refresh token: {}", why); - } - - match cli.campaign().await { - Ok(camp) => { - let id = camp.data[0].id.clone(); - - match cli.pledges(id).await { - Ok(users) => Ok(Some(users)), - Err(why) => { - error!("error getting pledges: {}", why); - Ok(None) - } - } - } - Err(why) => { - error!("error getting patreon campaign: {}", why); - Ok(None) - } - } -} - -pub const ICON: &str = "https://xeiaso.net/static/img/avatar.png"; - -pub struct State { - pub cfg: Arc<Config>, - pub signalboost: Vec<Person>, - pub blog: Vec<Post>, - pub gallery: Vec<Post>, - pub talks: Vec<Post>, - pub everything: Vec<Post>, - pub jf: xe_jsonfeed::Feed, - pub sitemap: Vec<u8>, - pub patrons: Option<patreon::Users>, - pub mi: mi::Client, -} - -pub async fn init(cfg: PathBuf) -> Result<State> { - let cfg: Arc<Config> = Arc::new(serde_dhall::from_file(cfg).parse()?); - let sb = cfg.signalboost.clone(); - let mi = mi::Client::new( - cfg.clone().mi_token.clone(), - crate::APPLICATION_NAME.to_string(), - )?; - let blog = crate::post::load("blog").await?; - let gallery = crate::post::load("gallery").await?; - let talks = crate::post::load("talks").await?; - let mut everything: Vec<Post> = vec![]; - - { - let blog = blog.clone(); - let gallery = gallery.clone(); - let talks = talks.clone(); - everything.extend(blog.iter().cloned()); - everything.extend(gallery.iter().cloned()); - everything.extend(talks.iter().cloned()); - }; - - everything.sort(); - everything.reverse(); - - let today = Utc::now().date_naive(); - let everything: Vec<Post> = everything - .into_iter() - .filter(|p| today.num_days_from_ce() >= p.date.num_days_from_ce()) - .take(5) - .collect(); - - let mut jfb = xe_jsonfeed::Feed::builder() - .title("Xe's Blog") - .description("My blog posts and rants about various technology things.") - .author( - xe_jsonfeed::Author::new() - .name("Xe") - .url("https://xeiaso.net") - .avatar(ICON), - ) - .feed_url("https://xeiaso.net/blog.json") - .user_comment("This is a JSON feed of my blogposts. For more information read: https://jsonfeed.org/version/1") - .home_page_url("https://xeiaso.net") - .icon(ICON) - .favicon(ICON); - - for post in &everything { - let post = post.clone(); - jfb = jfb.item(post.clone().into()); - } - - let mut sm: Vec<u8> = vec![]; - let smw = sitemap::writer::SiteMapWriter::new(&mut sm); - let mut urlwriter = smw.start_urlset()?; - for url in &[ - "https://xeiaso.net/resume", - "https://xeiaso.net/contact", - "https://xeiaso.net/", - "https://xeiaso.net/blog", - "https://xeiaso.net/signalboost", - ] { - urlwriter.url(*url)?; - } - - for post in &blog { - urlwriter.url(format!("https://xeiaso.net/{}", post.link))?; - } - for post in &gallery { - urlwriter.url(format!("https://xeiaso.net/{}", post.link))?; - } - for post in &talks { - urlwriter.url(format!("https://xeiaso.net/{}", post.link))?; - } - - urlwriter.end()?; - - Ok(State { - mi, - cfg, - signalboost: sb, - blog, - gallery, - talks, - everything, - jf: jfb.build(), - sitemap: sm, - patrons: patrons().await?, - }) -} - -#[cfg(test)] -mod tests { - use color_eyre::eyre::Result; - #[tokio::test] - async fn init() -> Result<()> { - super::init("./config.dhall".into()).await?; - Ok(()) - } -} diff --git a/src/app/poke.rs b/src/app/poke.rs deleted file mode 100644 index 404b14d..0000000 --- a/src/app/poke.rs +++ /dev/null @@ -1,38 +0,0 @@ -use color_eyre::eyre::Result; -use std::{env, time::Duration}; -use tokio::time::sleep as delay_for; - -#[instrument(err)] -pub async fn the_cloud() -> Result<()> { - info!("waiting for things to settle"); - delay_for(Duration::from_secs(10)).await; - - info!("poking mi"); - mi().await?; - - info!("poking google"); - google().await?; - - Ok(()) -} - -#[instrument(err)] -async fn google() -> Result<()> { - let cli = reqwest::Client::new(); - cli.get("https://www.google.com/ping") - .query(&[("sitemap", "https://xeiaso.net/sitemap.xml")]) - .header("User-Agent", crate::APPLICATION_NAME) - .send() - .await? - .error_for_status()?; - - Ok(()) -} - -#[instrument(err)] -async fn mi() -> Result<()> { - let cli = mi::Client::new(env::var("MI_TOKEN")?, crate::APPLICATION_NAME.to_string())?; - cli.refresh().await?; - - Ok(()) -} diff --git a/src/bin/fetch_mastodon_post.rs b/src/bin/fetch_mastodon_post.rs deleted file mode 100644 index c4d981c..0000000 --- a/src/bin/fetch_mastodon_post.rs +++ /dev/null @@ -1,68 +0,0 @@ -use color_eyre::Result; -use std::{env, fs}; -use tracing::debug; -use xesite_types::mastodon::{Toot, User}; - -#[tokio::main] -async fn main() -> Result<()> { - color_eyre::install()?; - tracing_subscriber::fmt::init(); - - let args: Vec<String> = env::args().collect(); - debug!("{args:?}"); - if args.len() != 2 { - eprintln!("Usage: {} <mastodon post URL>", args[0]); - } - - let mut post_url = args[1].clone(); - - let cli = reqwest::Client::builder() - .user_agent("github.com/Xe/site fetch_mastodon_post") - .build()?; - - let toot: Toot = cli - .get(&post_url) - .header("Accept", "application/json") - .send() - .await? - .error_for_status()? - .json() - .await?; - - debug!("got post by {}", toot.attributed_to); - - fs::create_dir_all("./data/toots")?; - - if !post_url.ends_with(".json") { - post_url = format!("{post_url}.json"); - } - let post_hash = xesite::hash_string(post_url); - - debug!("wrote post to ./data/toots/{post_hash}.json"); - - let mut fout = fs::File::create(format!("./data/toots/{post_hash}.json"))?; - serde_json::to_writer_pretty(&mut fout, &toot)?; - - debug!("fetching {} ...", toot.attributed_to); - let user: User = cli - .get(&toot.attributed_to) - .header("Accept", "application/json") - .send() - .await? - .error_for_status()? - .json() - .await?; - - fs::create_dir_all("./data/users")?; - - debug!("got user {} ({})", user.preferred_username, user.name); - - let user_url = format!("{}.json", toot.attributed_to); - let user_hash = xesite::hash_string(user_url); - - debug!("wrote post to ./data/users/{user_hash}.json"); - let mut fout = fs::File::create(format!("./data/users/{user_hash}.json"))?; - serde_json::to_writer_pretty(&mut fout, &user)?; - - Ok(()) -} diff --git a/src/build.rs b/src/build.rs deleted file mode 100644 index ec42c41..0000000 --- a/src/build.rs +++ /dev/null @@ -1,25 +0,0 @@ -use ructe::{Result, Ructe}; -use std::process::Command; - -fn main() -> Result<()> { - Ructe::from_env()?.compile_templates("templates")?; - - let output = Command::new("git") - .args(["rev-parse", "HEAD"]) - .output() - .unwrap(); - - let out = std::env::var("out").unwrap_or("/fake".into()); - println!("cargo:rustc-env=out={}", out); - - let git_hash = String::from_utf8(output.stdout).unwrap(); - println!( - "cargo:rustc-env=GITHUB_SHA={}", - if git_hash.as_str() == "" { - out - } else { - git_hash - } - ); - Ok(()) -} diff --git a/src/domainsocket.rs b/src/domainsocket.rs deleted file mode 100644 index ef731f5..0000000 --- a/src/domainsocket.rs +++ /dev/null @@ -1,94 +0,0 @@ -use axum::extract::connect_info; -use futures::ready; -use hyper::{ - client::connect::{Connected, Connection}, - server::accept::Accept, -}; -use std::{ - io, - pin::Pin, |
