This commit is contained in:
_ 2025-08-14 03:14:37 +00:00
parent 49f48acaf1
commit d4d0adaacc
2 changed files with 22 additions and 58 deletions

View file

@ -277,38 +277,7 @@ fn google_url(
link.query_pairs_mut().append_pair("eid", &eid);
Ok(Some(link.to_string()))
}
/*
impl EventInstance {
fn url(&self, google_id: Option<&str>) -> Result<Option<String>> {
if let Some(url) = self.ev.get_url() {
return Ok(Some(url.to_string()));
}
if let Some(google_id) = google_id {
return self.google_url(google_id);
}
Ok(None)
}
}
struct EventWithUrl<'a> {
calendar: &'a ConfigIcal,
dtstart: DatePerhapsTime,
ev: &'a icalendar::Event,
url: Option<String>,
}
impl<'a> EventWithUrl<'a> {
fn from_ei(calendar: &'a ConfigIcal, ei: EventInstance<'a>) -> Result<EventWithUrl<'a>> {
let url = ei.url(calendar.google_id.as_deref())?;
Ok(Self {
calendar,
dtstart: ei.dtstart,
ev: ei.ev,
url,
})
}
}
*/
fn ical_event_instances(
config_ical: &ConfigIcal,
params: &Parameters,
@ -358,6 +327,9 @@ fn ical_event_instances(
struct ICal {
/// The parsed ics file
cal: icalendar::Calendar,
/// The config used to load this calendar
config: ConfigIcal,
}
/// Used to link recurrence exceptions to the original events they replace
@ -368,15 +340,15 @@ struct RecurrenceKey<'a> {
}
impl ICal {
fn read_from_str(s: &str) -> Result<Self> {
fn read_from_str(config: ConfigIcal, s: &str) -> Result<Self> {
let cal = s.parse().map_err(|s| anyhow!("parse error {s}"))?;
let cal = Self { cal };
let cal = Self { cal, config };
Ok(cal)
}
fn read_from_downloadable(dl: &Downloadable) -> Result<Self> {
let s = std::fs::read_to_string(&dl.file_path)?;
Self::read_from_str(&s)
fn read_from_downloadable(config: ConfigIcal) -> Result<Self> {
let s = std::fs::read_to_string(&config.dl.file_path)?;
Self::read_from_str(config, &s)
}
fn events(&self) -> impl Iterator<Item = &icalendar::Event> {
@ -390,16 +362,12 @@ impl ICal {
}
/// Returns an unsorted list of event instances for this calendar
fn event_instances(
&self,
config_ical: &ConfigIcal,
params: &Parameters,
) -> Result<Vec<EventInstance>> {
fn event_instances(&self, params: &Parameters) -> Result<Vec<EventInstance>> {
let mut instances = vec![];
let mut recurrence_exceptions = BTreeSet::new();
for ev in self.events() {
let eis = match ical_event_instances(config_ical, params, ev)
let eis = match ical_event_instances(&self.config, params, ev)
.with_context(|| format!("Failed to process event with UID '{:?}'", ev.get_uid()))
{
Ok(x) => x,
@ -456,14 +424,14 @@ impl ICal {
#[derive(Default)]
struct Data {
icals: Vec<(ICal, ConfigIcal)>,
icals: Vec<ICal>,
}
fn read_data_from_disk(config: &Config) -> Result<Data> {
let mut data = Data::default();
for config in &config.icals {
let cal = ICal::read_from_downloadable(&config.dl)?;
data.icals.push((cal, config.clone()));
for config_ical in &config.icals {
let cal = ICal::read_from_downloadable(config_ical.clone())?;
data.icals.push(cal);
}
Ok(data)
@ -477,8 +445,8 @@ fn process_data<'a>(
let params = Parameters::new(now)?;
let mut instances = vec![];
for (ical, config) in &data.icals {
for ei in ical.event_instances(config, &params)? {
for ical in &data.icals {
for ei in ical.event_instances(&params)? {
if let Some(uid) = &ei.uid
&& config_output.hide_uids.contains(uid)
{
@ -489,7 +457,6 @@ fn process_data<'a>(
{
continue;
}
// let ei = EventWithUrl::from_ei(config, ei)?;
instances.push(ei);
}
}
@ -498,7 +465,6 @@ fn process_data<'a>(
Ok(instances)
}
// FIXME: Don't print to stdout / stderr
fn output_html(
config: &ConfigOutput,
instances: &[EventInstance],
@ -533,8 +499,6 @@ fn output_html(
}
}
if last_date_printed != Some(date) {
// println!("{date}");
// FIXME: De-dupe
if !day_list.is_empty() {
html_list.push(maud::html! {