cosmetic updates

This commit is contained in:
_ 2025-08-12 22:11:34 +00:00
parent 7a2fba6804
commit a4e4c89e15
2 changed files with 58 additions and 31 deletions

View file

@ -15,7 +15,7 @@ struct ConfigIcal {
google_id: Option<String>,
/// A canonical webpage we can direct users to
html_url: url::Url,
html_url: Option<url::Url>,
/// Very short name for putting on each event
short_name: String,
@ -26,10 +26,16 @@ struct ConfigIcal {
#[derive(Deserialize)]
struct ConfigOutput {
/// Used as the OpenGraph description in meta tags
description: String,
/// Timezone to use for output (e.g. "Antarctica/South_Pole")
///
/// <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>
timezone: chrono_tz::Tz,
/// Used as the page title and OpenGraph title in meta tags
title: String,
}
#[derive(Deserialize)]
@ -359,7 +365,11 @@ fn process_data(data: &Data, now: DateTime<chrono_tz::Tz>) -> Result<Vec<EventWi
}
// FIXME: Don't print to stdout / stderr
fn output_html(instances: &[EventWithUrl], now: DateTime<chrono_tz::Tz>) -> Result<()> {
fn output_html(
config: &ConfigOutput,
instances: &[EventWithUrl],
now: DateTime<chrono_tz::Tz>,
) -> Result<()> {
let today = now.date_naive();
let mut last_month_printed: Option<String> = None;
let mut last_date_printed = None;
@ -437,10 +447,16 @@ fn output_html(instances: &[EventWithUrl], now: DateTime<chrono_tz::Tz>) -> Resu
li class="past" { (time) " - " (summary) }
});
} else {
let calendar_link = if let Some(html_url) = &ei.calendar.html_url {
maud::html! { a href=(html_url) { (ei.calendar.short_name) } }
} else {
maud::html! { (ei.calendar.short_name)}
};
day_list.push(maud::html! {
li { p { (time) " - " (summary) }
ul {
li { a href=(ei.calendar.html_url) { (ei.calendar.short_name) } }
li { (calendar_link) " calendar" }
@if let Some(location) = location {
li { "Location: " (location) }
}
@ -476,12 +492,33 @@ fn output_html(instances: &[EventWithUrl], now: DateTime<chrono_tz::Tz>) -> Resu
}
</style>
"#;
let description = &config.description;
let title = &config.title;
let s = maud::html! {
(maud::PreEscaped(css))
h1 { "Wide-Angle Calendar" }
p { "Written at: " (now.to_rfc3339()) }
@for entry in html_list {
(entry)
html lang="en" {
head {
meta http-equiv="Content-Type" content="text/html; charset=utf-8" {}
meta name="viewport" content="width=device-width, initial-scale=1" {}
(maud::PreEscaped(css))
meta property="og:locale" content="en" {}
meta property="og:type" content="website" {}
meta property="description" content=(description) {}
meta property="og:description" content=(description) {}
title { (title) }
met property="og:title" content=(title) {}
}
body {
h1 { (title) }
p { "Written at: " (now.to_rfc3339()) }
@for entry in html_list {
(entry)
}
}
}
}
.into_string();
@ -525,10 +562,13 @@ async fn do_everything(cli: &CliAuto) -> Result<()> {
let tz = &config.output.timezone;
let now = Utc::now().with_timezone(tz);
let instances = process_data(&data, now)?;
output_html(&instances, now)?;
output_html(&config.output, &instances, now)?;
Ok(())
}
/// Seconds to sleep between auto cycles
const SLEEP_SECS: u64 = 9000;
fn main_auto(cli: CliAuto) -> Result<()> {
tracing_subscriber::fmt::init();
loop {
@ -539,7 +579,7 @@ fn main_auto(cli: CliAuto) -> Result<()> {
})?;
rt.shutdown_timeout(Duration::from_secs(10));
tracing::info!("The service is eeping");
std::thread::sleep(Duration::from_secs(5823));
std::thread::sleep(Duration::from_secs(SLEEP_SECS));
}
}
@ -552,7 +592,7 @@ fn main_ics_debug(cli: CliIcsDebug) -> Result<()> {
let tz = &config.output.timezone;
let now = Utc::now().with_timezone(tz);
let instances = process_data(&data, now)?;
output_html(&instances, now)?;
output_html(&config.output, &instances, now)?;
Ok(())
}