wip: adding RSS feeds

This commit is contained in:
_ 2025-09-11 02:25:45 +00:00
parent 70f302b5b5
commit 9ebc0c9736
2 changed files with 20 additions and 8 deletions

View file

@ -308,7 +308,7 @@ struct CliDebugRss {
} }
/// Wraps rss::Item in our own type suitable for merging /// Wraps rss::Item in our own type suitable for merging
struct RssItem { pub(crate) struct FeedItem {
channel_title: String, channel_title: String,
date: chrono::DateTime<chrono::FixedOffset>, date: chrono::DateTime<chrono::FixedOffset>,
inner: rss::Item, inner: rss::Item,
@ -316,6 +316,7 @@ struct RssItem {
fn main_debug_rss(cli: CliDebugRss) -> Result<()> { fn main_debug_rss(cli: CliDebugRss) -> Result<()> {
let mut items = Vec::new(); let mut items = Vec::new();
let now = Utc::now();
for path in &cli.paths { for path in &cli.paths {
let s = std::fs::read(path)?; 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")?, .context("Every RSS Item should have a pub_date")?,
)?; )?;
let item = RssItem { let item = FeedItem {
channel_title: channel_title.clone(), channel_title: channel_title.clone(),
date, date,
inner: item, inner: item,
@ -348,6 +349,12 @@ fn main_debug_rss(cli: CliDebugRss) -> Result<()> {
println!(); println!();
} }
std::fs::create_dir_all("output")?;
output::atomic_write(
"output/feed.html",
&output::feed_page(&items, now.with_timezone(&chrono_tz::UTC)),
)?;
Ok(()) Ok(())
} }

View file

@ -110,11 +110,15 @@ fn calendars_page(upstreams: &[crate::CalendarUi], now: DateTime<chrono_tz::Tz>)
.into_string() .into_string()
} }
pub(crate) fn feed_page(feed_items: &[crate::FeedItem], now: DateTime<chrono_tz::Tz>) -> String {
todo!()
}
fn index_page( fn index_page(
config: &Config, config: &Config,
instances: &[EventInstance], instances: &[EventInstance],
now: DateTime<chrono_tz::Tz>, now: DateTime<chrono_tz::Tz>,
) -> Result<String> { ) -> String {
let today = now.date_naive(); let today = now.date_naive();
let mut last_month_printed: Option<String> = None; let mut last_month_printed: Option<String> = None;
let mut last_date_printed = None; let mut last_date_printed = None;
@ -216,7 +220,7 @@ fn index_page(
let description = &config.description; let description = &config.description;
let title = &config.title; let title = &config.title;
let s = maud::html! { maud::html! {
(maud::PreEscaped("<!DOCTYPE html>")) (maud::PreEscaped("<!DOCTYPE html>"))
html lang="en" { html lang="en" {
head { head {
@ -245,11 +249,10 @@ fn index_page(
} }
} }
} }
.into_string(); .into_string()
Ok(s)
} }
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)?; let mut file = atomic_write_file::AtomicWriteFile::options().open(path)?;
file.write_all(content.as_bytes())?; file.write_all(content.as_bytes())?;
file.commit()?; file.commit()?;
@ -258,6 +261,7 @@ fn atomic_write(path: &str, content: &str) -> Result<()> {
pub(crate) fn write_html( pub(crate) fn write_html(
config: &Config, config: &Config,
// feed_items: &[crate::FeedItem],
upstreams: &[crate::CalendarUi], upstreams: &[crate::CalendarUi],
instances: &[EventInstance], instances: &[EventInstance],
now: DateTime<chrono_tz::Tz>, now: DateTime<chrono_tz::Tz>,
@ -265,7 +269,8 @@ pub(crate) fn write_html(
std::fs::create_dir_all("output")?; std::fs::create_dir_all("output")?;
atomic_write("output/calendars.html", &calendars_page(upstreams, now))?; 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(()) Ok(())
} }