From 9ebc0c9736dc4de5fb0a311f72fd7be7b675a778 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Thu, 11 Sep 2025 02:25:45 +0000 Subject: [PATCH] wip: adding RSS feeds --- src/main.rs | 11 +++++++++-- src/output.rs | 17 +++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4db5ce4..8a833b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -308,7 +308,7 @@ struct CliDebugRss { } /// Wraps rss::Item in our own type suitable for merging -struct RssItem { +pub(crate) struct FeedItem { channel_title: String, date: chrono::DateTime, inner: rss::Item, @@ -316,6 +316,7 @@ struct RssItem { fn main_debug_rss(cli: CliDebugRss) -> Result<()> { let mut items = Vec::new(); + let now = Utc::now(); for path in &cli.paths { let s = std::fs::read(path)?; @@ -329,7 +330,7 @@ fn main_debug_rss(cli: CliDebugRss) -> Result<()> { .context("Every RSS Item should have a pub_date")?, )?; - let item = RssItem { + let item = FeedItem { channel_title: channel_title.clone(), date, inner: item, @@ -348,6 +349,12 @@ fn main_debug_rss(cli: CliDebugRss) -> Result<()> { println!(); } + std::fs::create_dir_all("output")?; + output::atomic_write( + "output/feed.html", + &output::feed_page(&items, now.with_timezone(&chrono_tz::UTC)), + )?; + Ok(()) } diff --git a/src/output.rs b/src/output.rs index 90f4219..b7dd4f6 100644 --- a/src/output.rs +++ b/src/output.rs @@ -110,11 +110,15 @@ fn calendars_page(upstreams: &[crate::CalendarUi], now: DateTime) .into_string() } +pub(crate) fn feed_page(feed_items: &[crate::FeedItem], now: DateTime) -> String { + todo!() +} + fn index_page( config: &Config, instances: &[EventInstance], now: DateTime, -) -> Result { +) -> String { let today = now.date_naive(); let mut last_month_printed: Option = None; let mut last_date_printed = None; @@ -216,7 +220,7 @@ fn index_page( let description = &config.description; let title = &config.title; - let s = maud::html! { + maud::html! { (maud::PreEscaped("")) html lang="en" { head { @@ -245,11 +249,10 @@ fn index_page( } } } - .into_string(); - Ok(s) + .into_string() } -fn atomic_write(path: &str, content: &str) -> Result<()> { +pub(crate) fn atomic_write(path: &str, content: &str) -> Result<()> { let mut file = atomic_write_file::AtomicWriteFile::options().open(path)?; file.write_all(content.as_bytes())?; file.commit()?; @@ -258,6 +261,7 @@ fn atomic_write(path: &str, content: &str) -> Result<()> { pub(crate) fn write_html( config: &Config, + // feed_items: &[crate::FeedItem], upstreams: &[crate::CalendarUi], instances: &[EventInstance], now: DateTime, @@ -265,7 +269,8 @@ pub(crate) fn write_html( std::fs::create_dir_all("output")?; atomic_write("output/calendars.html", &calendars_page(upstreams, now))?; - atomic_write("output/index.html", &index_page(config, instances, now)?)?; + // atomic_write("output/feed.html", &feed_page(feed_items, now)?)?; + atomic_write("output/index.html", &index_page(config, instances, now))?; Ok(()) }