2020-07-16 19:32:30 +00:00
|
|
|
use crate::{post::Post, signalboost::Person};
|
2020-09-19 15:33:46 +00:00
|
|
|
use color_eyre::eyre::Result;
|
2020-07-16 19:32:30 +00:00
|
|
|
use serde::Deserialize;
|
|
|
|
use std::{fs, path::PathBuf};
|
2020-11-18 17:18:24 +00:00
|
|
|
use tracing::{error, instrument};
|
2020-07-16 19:32:30 +00:00
|
|
|
|
2020-09-19 15:33:46 +00:00
|
|
|
pub mod markdown;
|
2021-01-17 02:38:22 +00:00
|
|
|
pub mod poke;
|
2020-09-19 15:33:46 +00:00
|
|
|
|
2020-07-16 19:32:30 +00:00
|
|
|
#[derive(Clone, Deserialize)]
|
|
|
|
pub struct Config {
|
|
|
|
#[serde(rename = "clackSet")]
|
2020-11-18 17:18:24 +00:00
|
|
|
pub(crate) clack_set: Vec<String>,
|
|
|
|
pub(crate) signalboost: Vec<Person>,
|
|
|
|
pub(crate) port: u16,
|
2020-07-16 19:32:30 +00:00
|
|
|
#[serde(rename = "resumeFname")]
|
2020-11-18 17:18:24 +00:00
|
|
|
pub(crate) resume_fname: PathBuf,
|
|
|
|
#[serde(rename = "webMentionEndpoint")]
|
|
|
|
pub(crate) webmention_url: String,
|
2020-12-02 21:16:58 +00:00
|
|
|
#[serde(rename = "miToken")]
|
|
|
|
pub(crate) mi_token: String,
|
2020-07-16 19:32:30 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 22:36:57 +00:00
|
|
|
#[instrument]
|
2020-07-16 19:32:30 +00:00
|
|
|
async fn patrons() -> Result<Option<patreon::Users>> {
|
|
|
|
use patreon::*;
|
2020-11-18 17:18:24 +00:00
|
|
|
let creds: Credentials = envy::prefixed("PATREON_")
|
|
|
|
.from_env()
|
|
|
|
.unwrap_or(Credentials::default());
|
2020-07-16 19:32:30 +00:00
|
|
|
let cli = Client::new(creds);
|
|
|
|
|
|
|
|
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) => {
|
2020-10-02 22:36:57 +00:00
|
|
|
error!("error getting pledges: {}", why);
|
2020-07-16 19:32:30 +00:00
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(why) => {
|
2020-10-02 22:36:57 +00:00
|
|
|
error!("error getting patreon campaign: {}", why);
|
2020-07-16 19:32:30 +00:00
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub const ICON: &'static str = "https://christine.website/static/img/avatar.png";
|
|
|
|
|
|
|
|
pub struct State {
|
|
|
|
pub cfg: Config,
|
|
|
|
pub signalboost: Vec<Person>,
|
|
|
|
pub resume: String,
|
|
|
|
pub blog: Vec<Post>,
|
|
|
|
pub gallery: Vec<Post>,
|
|
|
|
pub talks: Vec<Post>,
|
|
|
|
pub everything: Vec<Post>,
|
|
|
|
pub jf: jsonfeed::Feed,
|
|
|
|
pub sitemap: Vec<u8>,
|
|
|
|
pub patrons: Option<patreon::Users>,
|
2020-12-02 21:16:58 +00:00
|
|
|
pub mi: mi::Client,
|
2020-07-16 19:32:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn init(cfg: PathBuf) -> Result<State> {
|
|
|
|
let cfg: Config = serde_dhall::from_file(cfg).parse()?;
|
|
|
|
let sb = cfg.signalboost.clone();
|
|
|
|
let resume = fs::read_to_string(cfg.resume_fname.clone())?;
|
2020-09-19 15:33:46 +00:00
|
|
|
let resume: String = markdown::render(&resume)?;
|
2020-12-02 21:16:58 +00:00
|
|
|
let mi = mi::Client::new(cfg.mi_token.clone(), crate::APPLICATION_NAME.to_string())?;
|
|
|
|
let blog = crate::post::load("blog", Some(&mi)).await?;
|
|
|
|
let gallery = crate::post::load("gallery", None).await?;
|
|
|
|
let talks = crate::post::load("talks", None).await?;
|
2020-07-16 19:32:30 +00:00
|
|
|
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();
|
|
|
|
|
2021-01-15 03:36:34 +00:00
|
|
|
let everything: Vec<Post> = everything.into_iter().take(20).collect();
|
|
|
|
|
2020-07-16 19:32:30 +00:00
|
|
|
let mut jfb = jsonfeed::Feed::builder()
|
|
|
|
.title("Christine Dodrill's Blog")
|
|
|
|
.description("My blog posts and rants about various technology things.")
|
|
|
|
.author(
|
|
|
|
jsonfeed::Author::new()
|
|
|
|
.name("Christine Dodrill")
|
|
|
|
.url("https://christine.website")
|
|
|
|
.avatar(ICON),
|
|
|
|
)
|
|
|
|
.feed_url("https://christine.website/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://christine.website")
|
|
|
|
.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://christine.website/resume",
|
|
|
|
"https://christine.website/contact",
|
|
|
|
"https://christine.website/",
|
|
|
|
"https://christine.website/blog",
|
|
|
|
"https://christine.website/signalboost",
|
|
|
|
] {
|
|
|
|
urlwriter.url(*url)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
for post in &everything {
|
|
|
|
urlwriter.url(format!("https://christine.website/{}", post.link))?;
|
|
|
|
}
|
|
|
|
|
|
|
|
urlwriter.end()?;
|
|
|
|
|
|
|
|
Ok(State {
|
2020-12-02 21:16:58 +00:00
|
|
|
mi: mi,
|
2020-07-16 19:32:30 +00:00
|
|
|
cfg: cfg,
|
|
|
|
signalboost: sb,
|
|
|
|
resume: resume,
|
|
|
|
blog: blog,
|
|
|
|
gallery: gallery,
|
|
|
|
talks: talks,
|
|
|
|
everything: everything,
|
|
|
|
jf: jfb.build(),
|
|
|
|
sitemap: sm,
|
|
|
|
patrons: patrons().await?,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-09-19 15:33:46 +00:00
|
|
|
use color_eyre::eyre::Result;
|
2020-07-16 19:32:30 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn init() -> Result<()> {
|
|
|
|
super::init("./config.dhall".into()).await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|