xesite/src/app.rs

50 lines
1.2 KiB
Rust
Raw Normal View History

2020-07-12 18:42:09 +00:00
use crate::signalboost::Person;
use anyhow::Result;
2020-07-13 00:11:26 +00:00
use comrak::{markdown_to_html, ComrakOptions};
2020-07-12 18:42:09 +00:00
use serde::Deserialize;
2020-07-12 23:26:53 +00:00
use std::{fs, path::PathBuf};
2020-07-12 18:42:09 +00:00
#[derive(Clone, Deserialize)]
pub struct Config {
2020-07-13 00:11:26 +00:00
#[serde(rename = "clackSet")]
2020-07-12 18:42:09 +00:00
clack_set: Vec<String>,
2020-07-13 00:11:26 +00:00
signalboost: Vec<Person>,
2020-07-12 18:42:09 +00:00
port: u16,
2020-07-13 00:11:26 +00:00
#[serde(rename = "resumeFname")]
2020-07-12 23:26:53 +00:00
resume_fname: PathBuf,
2020-07-12 18:42:09 +00:00
}
2020-07-12 23:30:01 +00:00
pub fn markdown(inp: &str) -> String {
let mut options = ComrakOptions::default();
options.extension.autolink = true;
options.extension.table = true;
options.extension.description_lists = true;
options.extension.superscript = true;
options.extension.strikethrough = true;
options.extension.footnotes = true;
options.render.unsafe_ = true;
markdown_to_html(inp, &options)
}
2020-07-12 18:42:09 +00:00
pub struct State {
pub cfg: Config,
pub signalboost: Vec<Person>,
2020-07-12 23:26:53 +00:00
pub resume: String,
2020-07-12 18:42:09 +00:00
}
2020-07-13 00:11:26 +00:00
pub fn init(cfg: PathBuf) -> Result<State> {
let cfg: Config = serde_dhall::from_file(cfg).parse()?;
let sb = cfg.signalboost.clone();
2020-07-12 23:26:53 +00:00
let resume = fs::read_to_string(cfg.resume_fname.clone())?;
2020-07-12 23:30:01 +00:00
let resume: String = markdown(&resume);
2020-07-12 18:42:09 +00:00
Ok(State {
cfg: cfg,
signalboost: sb,
2020-07-12 23:26:53 +00:00
resume: resume,
2020-07-12 18:42:09 +00:00
})
}