style
This commit is contained in:
parent
9a1a106e0e
commit
b471b76bec
|
@ -3,15 +3,18 @@ use std::collections::BTreeMap;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct CalendarOptions {
|
pub struct CalendarOptions {
|
||||||
pub url: String,
|
pub url: String,
|
||||||
|
pub color: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub db_url: String,
|
pub db_url: String,
|
||||||
pub calendars: BTreeMap<String, CalendarOptions>,
|
pub calendars: BTreeMap<String, CalendarOptions>,
|
||||||
|
pub weekdays: Vec<String>,
|
||||||
|
pub months: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
|
|
@ -8,7 +8,7 @@ use mime::TEXT_HTML;
|
||||||
|
|
||||||
use typed_html::{html, text, dom::DOMTree};
|
use typed_html::{html, text, dom::DOMTree};
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use chrono::{offset::Local, NaiveDate};
|
use chrono::{offset::Local, Datelike, NaiveDate};
|
||||||
|
|
||||||
use libticker::{
|
use libticker::{
|
||||||
schema::{self, events::dsl::events},
|
schema::{self, events::dsl::events},
|
||||||
|
@ -63,18 +63,33 @@ fn render_index(app_state: &AppState) -> String {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let days = group_by_day(&es);
|
let days = group_by_day(&es);
|
||||||
|
|
||||||
|
let config = &app_state.config;
|
||||||
|
|
||||||
let doc: DOMTree<String> = html!(
|
let doc: DOMTree<String> = html!(
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>"Ticker"</title>
|
<title>"Ticker"</title>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
|
<link rel="stylesheet" title="Style" type="text/css" href="static/style.css"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{ days.iter().map(|day| html!(<div>
|
{ days.iter().map(|day| html!(<div>
|
||||||
<nav><h2>{ text!("{}", &day.date) }</h2></nav>
|
<h2>
|
||||||
|
<span class="date">
|
||||||
|
<span class="day">
|
||||||
|
{ text!("{}", day.date.day()) }
|
||||||
|
</span>
|
||||||
|
<span class="month">
|
||||||
|
{ text!("{}", &config.months[day.date.month0() as usize]) }
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
<span class="weekday">
|
||||||
|
{ text!("{}", &config.weekdays[day.date.weekday().num_days_from_monday() as usize]) }
|
||||||
|
</span>
|
||||||
|
</h2>
|
||||||
|
|
||||||
{ day.events.iter().map(|e| html!(
|
{ day.events.iter().map(|e| html!(
|
||||||
<article class="event">
|
<article class="event" style={ format!("border-left: 1.5rem solid {}", &config.calendars.get(&e.calendar).map(|o| &o.color[..]).unwrap_or("white")) }>
|
||||||
{ match &e.url {
|
{ match &e.url {
|
||||||
None => html!(
|
None => html!(
|
||||||
<h3>{ text!("{}", &e.summary) }</h3>
|
<h3>{ text!("{}", &e.summary) }</h3>
|
||||||
|
@ -88,9 +103,11 @@ fn render_index(app_state: &AppState) -> String {
|
||||||
),
|
),
|
||||||
} }
|
} }
|
||||||
|
|
||||||
<p class="dtstart">{ text!("{}", &e.dtstart) }</p>
|
<p class="dtstart" title={ format!("{}", e.dtstart.format("%c")) }>
|
||||||
|
{ text!("{}", &e.dtstart.format("%H:%S")) }
|
||||||
|
</p>
|
||||||
{ e.location.as_ref().map(|location| html!(
|
{ e.location.as_ref().map(|location| html!(
|
||||||
<p>
|
<p class="location">
|
||||||
{ text!("{}", location) }
|
{ text!("{}", location) }
|
||||||
</p>
|
</p>
|
||||||
)) }
|
)) }
|
||||||
|
|
|
@ -20,6 +20,7 @@ mod index;
|
||||||
#[derive(Clone, StateData)]
|
#[derive(Clone, StateData)]
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
pub db: Arc<Mutex<PgConnection>>,
|
pub db: Arc<Mutex<PgConnection>>,
|
||||||
|
pub config: Config,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -28,7 +29,8 @@ fn main() {
|
||||||
.expect("DB");
|
.expect("DB");
|
||||||
|
|
||||||
let state = AppState {
|
let state = AppState {
|
||||||
db: Arc::new(Mutex::new(db))
|
db: Arc::new(Mutex::new(db)),
|
||||||
|
config,
|
||||||
};
|
};
|
||||||
let (chain, pipelines) = single_pipeline(
|
let (chain, pipelines) = single_pipeline(
|
||||||
single_middleware(
|
single_middleware(
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -258,7 +258,7 @@ impl std::fmt::Display for Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let config = Config::read_yaml_file("config.yaml");
|
let config = Config::read_yaml_file("../config.yaml");
|
||||||
let res = Resources::new(
|
let res = Resources::new(
|
||||||
config.db_url,
|
config.db_url,
|
||||||
config.calendars.into_iter()
|
config.calendars.into_iter()
|
||||||
|
|
Loading…
Reference in New Issue