diff --git a/libticker/src/config.rs b/libticker/src/config.rs index 6bb2226..47b56f0 100644 --- a/libticker/src/config.rs +++ b/libticker/src/config.rs @@ -3,15 +3,18 @@ use std::collections::BTreeMap; use serde::{Serialize, Deserialize}; -#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct CalendarOptions { pub url: String, + pub color: String, } -#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Config { pub db_url: String, pub calendars: BTreeMap, + pub weekdays: Vec, + pub months: Vec, } impl Config { diff --git a/ticker-serve/src/index.rs b/ticker-serve/src/index.rs index 7ff8ba3..8f8d9d7 100644 --- a/ticker-serve/src/index.rs +++ b/ticker-serve/src/index.rs @@ -8,7 +8,7 @@ use mime::TEXT_HTML; use typed_html::{html, text, dom::DOMTree}; use diesel::prelude::*; -use chrono::{offset::Local, NaiveDate}; +use chrono::{offset::Local, Datelike, NaiveDate}; use libticker::{ schema::{self, events::dsl::events}, @@ -63,18 +63,33 @@ fn render_index(app_state: &AppState) -> String { .unwrap(); let days = group_by_day(&es); + let config = &app_state.config; + let doc: DOMTree = html!( "Ticker" + { days.iter().map(|day| html!(
- +

+ + + { text!("{}", day.date.day()) } + + + { text!("{}", &config.months[day.date.month0() as usize]) } + + + + { text!("{}", &config.weekdays[day.date.weekday().num_days_from_monday() as usize]) } + +

{ day.events.iter().map(|e| html!( -
+
{ match &e.url { None => html!(

{ text!("{}", &e.summary) }

@@ -88,9 +103,11 @@ fn render_index(app_state: &AppState) -> String { ), } } -

{ text!("{}", &e.dtstart) }

+

+ { text!("{}", &e.dtstart.format("%H:%S")) } +

{ e.location.as_ref().map(|location| html!( -

+

{ text!("{}", location) }

)) } diff --git a/ticker-serve/src/main.rs b/ticker-serve/src/main.rs index b1d4327..c45ae85 100644 --- a/ticker-serve/src/main.rs +++ b/ticker-serve/src/main.rs @@ -20,6 +20,7 @@ mod index; #[derive(Clone, StateData)] pub struct AppState { pub db: Arc>, + pub config: Config, } fn main() { @@ -28,7 +29,8 @@ fn main() { .expect("DB"); let state = AppState { - db: Arc::new(Mutex::new(db)) + db: Arc::new(Mutex::new(db)), + config, }; let (chain, pipelines) = single_pipeline( single_middleware( diff --git a/ticker-serve/static/style.css b/ticker-serve/static/style.css new file mode 100644 index 0000000..a91e0bc --- /dev/null +++ b/ticker-serve/static/style.css @@ -0,0 +1,72 @@ +body { + font-family: sans-serif; + margin: 0 auto; + padding: 1rem 0; + background-color: #373737; + color: #e7e7e7; + max-width: 40rem; +} + +h2 { + margin: 0 0; +} + +.date { + display: inline-flex; + flex-flow: column nowrap; + border: 1px solid black; + background-color: #ffffff; + color: #444; + font-weight: 900; + width: 4rem; + margin-left: -1.5rem; + text-align: center; + width: 4rem; +} +.date .day { + align-self: center; + font-size: 140%; +} +.date .month { + align-self: center; + font-size: 50%; + font-variant-caps: small-caps; +} +.weekday { + padding-left: 1rem; +} + +article { + background-color: #f7f7f7; + color: #222; + margin: 0; + padding: 0.5rem 0 0.5rem 1rem; + clear: both; + line-height: 1.3rem; + /*box-shadow: 0 -0.3rem 0.5rem 0.5rem #373737;*/ +} + +article p { + margin: 0 0; +} + +a { + text-decoration: none; + color: #000; +} + +h3 { + margin: 0; +} + +h3 a { + color: #222; +} + +.dtstart { + margin-right: 1.3em; +} +.dtstart, .location { + line-height: 1.1em; + display: inline; +} diff --git a/ticker-update/src/main.rs b/ticker-update/src/main.rs index b4baecd..585f05d 100644 --- a/ticker-update/src/main.rs +++ b/ticker-update/src/main.rs @@ -258,7 +258,7 @@ impl std::fmt::Display for Error { } fn main() { - let config = Config::read_yaml_file("config.yaml"); + let config = Config::read_yaml_file("../config.yaml"); let res = Resources::new( config.db_url, config.calendars.into_iter()