add resume rendering support
This commit is contained in:
parent
6a375cb218
commit
160b2ea74e
|
@ -213,9 +213,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "comrak"
|
name = "comrak"
|
||||||
version = "0.7.0"
|
version = "0.8.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e17058cc536cf290563e88787d7b9e6030ce4742943017cc2ffb71f88034021c"
|
checksum = "b818732a109eeabbe99fee28030ff8ecbd606889fcd25509ed933e6c69b7aa69"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"entities",
|
"entities",
|
||||||
|
|
|
@ -9,11 +9,11 @@ build = "src/build.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
comrak = "0.7"
|
comrak = "0.8"
|
||||||
envy = "0.4"
|
envy = "0.4"
|
||||||
log = "0"
|
log = "0"
|
||||||
pretty_env_logger = "0"
|
|
||||||
mime = "0.3.0"
|
mime = "0.3.0"
|
||||||
|
pretty_env_logger = "0"
|
||||||
rand = "0"
|
rand = "0"
|
||||||
ructe = "0.11"
|
ructe = "0.11"
|
||||||
serde_dhall = "0.5.3"
|
serde_dhall = "0.5.3"
|
||||||
|
|
28
src/app.rs
28
src/app.rs
|
@ -1,7 +1,8 @@
|
||||||
use crate::signalboost::Person;
|
use crate::signalboost::Person;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::path::PathBuf;
|
use std::{fs, path::PathBuf};
|
||||||
|
use comrak::{markdown_to_html, ComrakOptions};
|
||||||
|
|
||||||
mod defaults {
|
mod defaults {
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -13,9 +14,14 @@ mod defaults {
|
||||||
pub fn signalboost_fname() -> PathBuf {
|
pub fn signalboost_fname() -> PathBuf {
|
||||||
"./signalboost.dhall".into()
|
"./signalboost.dhall".into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn port() -> u16 {
|
pub fn port() -> u16 {
|
||||||
34252
|
34252
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn resume_fname() -> PathBuf {
|
||||||
|
"./static/resume/resume.md".into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize)]
|
#[derive(Clone, Deserialize)]
|
||||||
|
@ -26,20 +32,38 @@ pub struct Config {
|
||||||
signalboost_fname: PathBuf,
|
signalboost_fname: PathBuf,
|
||||||
#[serde(default = "defaults::port")]
|
#[serde(default = "defaults::port")]
|
||||||
port: u16,
|
port: u16,
|
||||||
|
#[serde(default = "defaults::resume_fname")]
|
||||||
|
resume_fname: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct State {
|
pub struct State {
|
||||||
pub cfg: Config,
|
pub cfg: Config,
|
||||||
pub signalboost: Vec<Person>,
|
pub signalboost: Vec<Person>,
|
||||||
|
pub resume: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init<'a>() -> Result<State> {
|
pub fn init<'a>() -> Result<State> {
|
||||||
let cfg: Config = envy::from_env()?;
|
let cfg: Config = envy::from_env()?;
|
||||||
let sb = serde_dhall::from_file(cfg.signalboost_fname.clone()).parse()?;
|
let sb = serde_dhall::from_file(cfg.signalboost_fname.clone()).parse()?;
|
||||||
|
let resume = fs::read_to_string(cfg.resume_fname.clone())?;
|
||||||
|
let resume: 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(&resume, &options)
|
||||||
|
};
|
||||||
|
|
||||||
Ok(State {
|
Ok(State {
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
signalboost: sb,
|
signalboost: sb,
|
||||||
|
resume: resume,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
use crate::templates::{self, RenderRucte};
|
use crate::{
|
||||||
|
app::State,
|
||||||
|
templates::{self, RenderRucte, Html},
|
||||||
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
use warp::{
|
use warp::{
|
||||||
http::{Response, StatusCode},
|
http::{Response, StatusCode},
|
||||||
path, Filter, Rejection, Reply,
|
path, Filter, Rejection, Reply,
|
||||||
|
@ -15,3 +19,8 @@ pub async fn contact() -> Result<impl Reply, Rejection> {
|
||||||
pub async fn feeds() -> Result<impl Reply, Rejection> {
|
pub async fn feeds() -> Result<impl Reply, Rejection> {
|
||||||
Response::builder().html(|o| templates::feeds_html(o))
|
Response::builder().html(|o| templates::feeds_html(o))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn resume(state: Arc<State>) -> Result<impl Reply, Rejection> {
|
||||||
|
let state = state.clone();
|
||||||
|
Response::builder().html(|o| templates::resume_html(o, Html(state.resume.clone())))
|
||||||
|
}
|
||||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -1,22 +1,34 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use std::sync::Arc;
|
||||||
use warp::{path, Filter};
|
use warp::{path, Filter};
|
||||||
|
|
||||||
pub mod app;
|
pub mod app;
|
||||||
pub mod handlers;
|
pub mod handlers;
|
||||||
pub mod signalboost;
|
pub mod signalboost;
|
||||||
|
|
||||||
|
use app::State;
|
||||||
|
|
||||||
const APPLICATION_NAME: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
const APPLICATION_NAME: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
|
fn with_state(
|
||||||
|
state: Arc<State>,
|
||||||
|
) -> impl Filter<Extract = (Arc<State>,), Error = std::convert::Infallible> + Clone {
|
||||||
|
warp::any().map(move || state.clone())
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
|
|
||||||
let state = app::init()?;
|
let state = Arc::new(app::init()?);
|
||||||
|
|
||||||
let routes = warp::get()
|
let routes = warp::get()
|
||||||
.and(path::end().and_then(handlers::index))
|
.and(path::end().and_then(handlers::index))
|
||||||
.or(warp::path!("contact").and_then(handlers::contact))
|
.or(warp::path!("contact").and_then(handlers::contact))
|
||||||
.or(warp::path!("feeds").and_then(handlers::feeds));
|
.or(warp::path!("feeds").and_then(handlers::feeds))
|
||||||
|
.or(warp::path!("resume")
|
||||||
|
.and(with_state(state.clone()))
|
||||||
|
.and_then(handlers::resume));
|
||||||
|
|
||||||
let files = warp::path("static")
|
let files = warp::path("static")
|
||||||
.and(warp::fs::dir("./static"))
|
.and(warp::fs::dir("./static"))
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
@use super::{header_html, footer_html};
|
||||||
|
|
||||||
|
@(resume: impl ToHtml)
|
||||||
|
|
||||||
|
@:header_html(Some("Resume"), None)
|
||||||
|
|
||||||
|
@resume
|
||||||
|
|
||||||
|
@:footer_html()
|
Loading…
Reference in New Issue