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
struct RssItem {
pub(crate) struct FeedItem {
channel_title: String,
date: chrono::DateTime<chrono::FixedOffset>,
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(())
}

View file

@ -110,11 +110,15 @@ fn calendars_page(upstreams: &[crate::CalendarUi], now: DateTime<chrono_tz::Tz>)
.into_string()
}
pub(crate) fn feed_page(feed_items: &[crate::FeedItem], now: DateTime<chrono_tz::Tz>) -> String {
todo!()
}
fn index_page(
config: &Config,
instances: &[EventInstance],
now: DateTime<chrono_tz::Tz>,
) -> Result<String> {
) -> String {
let today = now.date_naive();
let mut last_month_printed: Option<String> = 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("<!DOCTYPE html>"))
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<chrono_tz::Tz>,
@ -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(())
}