diff options
Diffstat (limited to 'src/app')
| -rw-r--r-- | src/app/config.rs | 90 | ||||
| -rw-r--r-- | src/app/mod.rs | 8 |
2 files changed, 80 insertions, 18 deletions
diff --git a/src/app/config.rs b/src/app/config.rs index e0a4d90..6499e72 100644 --- a/src/app/config.rs +++ b/src/app/config.rs @@ -1,7 +1,8 @@ use crate::signalboost::Person; -use maud::{html, Markup}; +use maud::{html, Markup, Render}; use serde::{Deserialize, Serialize}; use std::{ + collections::HashMap, fmt::{self, Display}, path::PathBuf, }; @@ -9,7 +10,9 @@ use std::{ #[derive(Clone, Deserialize, Default)] pub struct Config { pub signalboost: Vec<Person>, - pub authors: Vec<Author>, + pub authors: HashMap<String, Author>, + #[serde(rename = "defaultAuthor")] + pub default_author: Author, pub port: u16, #[serde(rename = "clackSet")] pub clack_set: Vec<String>, @@ -19,6 +22,35 @@ pub struct Config { 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>, +} + +#[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, Deserialize, Serialize)] @@ -33,17 +65,51 @@ impl Default for StockKind { } } +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 = "picUrl")] + #[serde(rename = "image", skip_serializing_if = "Option::is_none")] pub pic_url: Option<String>, - pub link: Option<String>, - pub twitter: Option<String>, - pub default: bool, - #[serde(rename = "inSystem")] + #[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)] @@ -80,8 +146,8 @@ impl Display for Salary { } } -impl Salary { - pub fn html(&self) -> Markup { +impl Render for Salary { + fn render(&self) -> Markup { if self.stock.is_none() { return html! { (maud::display(self)) }; } @@ -162,15 +228,15 @@ pub struct Company { pub defunct: bool, } -impl Job { - pub fn pay_history_row(&self) -> Markup { +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.html()) } + td { (self.salary) } td { (self.leave_reason.as_ref().unwrap_or(&"n/a".to_string())) } } } diff --git a/src/app/mod.rs b/src/app/mod.rs index 73320e1..6753ff0 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1,7 +1,7 @@ use crate::{post::Post, signalboost::Person}; use chrono::prelude::*; use color_eyre::eyre::Result; -use std::{fs, path::PathBuf, sync::Arc}; +use std::{path::PathBuf, sync::Arc}; use tracing::{error, instrument}; pub mod config; @@ -48,7 +48,6 @@ pub const ICON: &'static str = "https://xeiaso.net/static/img/avatar.png"; pub struct State { pub cfg: Arc<Config>, pub signalboost: Vec<Person>, - pub resume: String, pub blog: Vec<Post>, pub gallery: Vec<Post>, pub talks: Vec<Post>, @@ -62,8 +61,6 @@ pub struct State { 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 resume = fs::read_to_string(cfg.clone().resume_fname.clone())?; - let resume: String = xesite_markdown::render(&resume)?; let mi = mi::Client::new( cfg.clone().mi_token.clone(), crate::APPLICATION_NAME.to_string(), @@ -85,7 +82,7 @@ pub async fn init(cfg: PathBuf) -> Result<State> { everything.sort(); everything.reverse(); - let today = Utc::today(); + 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()) @@ -141,7 +138,6 @@ pub async fn init(cfg: PathBuf) -> Result<State> { mi, cfg, signalboost: sb, - resume, blog, gallery, talks, |
