serve: colorize sat+sun

This commit is contained in:
Astro 2020-10-26 20:14:04 +01:00
parent b471b76bec
commit 72d4a34015
2 ha cambiato i file con 55 aggiunte e 41 eliminazioni

Vedi File

@ -1,3 +1,4 @@
use std::convert::TryInto;
use gotham::{
helpers::http::response::create_response,
hyper::{Body, Response},
@ -6,7 +7,7 @@ use gotham::{
use http::status::StatusCode;
use mime::TEXT_HTML;
use typed_html::{html, text, dom::DOMTree};
use typed_html::{html, text, dom::DOMTree, types::{Class, SpacedSet}};
use diesel::prelude::*;
use chrono::{offset::Local, Datelike, NaiveDate};
@ -73,47 +74,52 @@ fn render_index(app_state: &AppState) -> String {
<link rel="stylesheet" title="Style" type="text/css" href="static/style.css"/>
</head>
<body>
{ days.iter().map(|day| html!(<div>
<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>
{ days.iter().map(|day| {
let mut day_class: SpacedSet<Class> = ["date"].try_into().unwrap();
day_class.add(&format!("wd{}", day.date.weekday().num_days_from_monday())[..]);
html!(
<div>
<h2>
<span class={ day_class }>
<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!(
<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 {
None => html!(
<h3>{ text!("{}", &e.summary) }</h3>
),
Some(url) => html!(
<h3>
<a href={ fix_url(url) }>
{ text!("{}", &e.summary) }
</a>
</h3>
),
} }
{ day.events.iter().map(|e| html!(
<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 {
None => html!(
<h3>{ text!("{}", &e.summary) }</h3>
),
Some(url) => html!(
<h3>
<a href={ fix_url(url) }>
{ text!("{}", &e.summary) }
</a>
</h3>
),
} }
<p class="dtstart" title={ format!("{}", e.dtstart.format("%c")) }>
{ text!("{}", &e.dtstart.format("%H:%S")) }
</p>
{ e.location.as_ref().map(|location| html!(
<p class="location">
{ text!("{}", location) }
</p>
)) }
</article>
)) }
</div>)) }
<p class="dtstart" title={ format!("{}", e.dtstart.format("%c")) }>
{ text!("{}", &e.dtstart.format("%H:%S")) }
</p>
{ e.location.as_ref().map(|location| html!(
<p class="location">
{ text!("{}", location) }
</p>
)) }
</article>
)) }
</div>)
}) }
</body>
</html>
);

Vedi File

@ -23,6 +23,14 @@ h2 {
text-align: center;
width: 4rem;
}
/* saturday */
.date.wd5 {
color: #999;
}
/* sunday */
.date.wd6 {
color: #d33;
}
.date .day {
align-self: center;
font-size: 140%;
@ -40,7 +48,7 @@ article {
background-color: #f7f7f7;
color: #222;
margin: 0;
padding: 0.5rem 0 0.5rem 1rem;
padding: 0.8rem 0 0.8rem 1rem;
clear: both;
line-height: 1.3rem;
/*box-shadow: 0 -0.3rem 0.5rem 0.5rem #373737;*/