From 9288f135b374e28dac31040755d30651189ea331 Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Sun, 1 Feb 2026 02:28:06 +0100 Subject: [PATCH] feat: enable single-event calendar files Enable a given event to also generate the appropriate ics/xcs files at the desired routes. Resolves #313 Resolves #335 Signed-off-by: Mike Fiedler --- Rules | 6 ++++++ layouts/schedule/event.html | 9 +++++++++ lib/data_sources/schedule.rb | 14 ++++++++++++++ lib/helpers/schedule_helpers.rb | 6 +++--- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Rules b/Rules index 634c7c32..24b35533 100644 --- a/Rules +++ b/Rules @@ -376,6 +376,12 @@ end route '/schedule/ical/track/*' do "#{$prefix}/schedule/track/#{item.identifier.split('/')[-1]}.ics" end +route '/schedule/xcal/event/*' do + "#{$prefix}/schedule/event/#{item.identifier.split('/')[-1]}.xcs" +end +route '/schedule/ical/event/*' do + "#{$prefix}/schedule/event/#{item.identifier.split('/')[-1]}.ics" +end route '/schedule/pentabarf/' do "#{$prefix}/schedule/xml" end diff --git a/layouts/schedule/event.html b/layouts/schedule/event.html index 43034128..75f64296 100644 --- a/layouts/schedule/event.html +++ b/layouts/schedule/event.html @@ -9,6 +9,15 @@
  • Day: <%= l day(item[:day]) %>
  • Start (UTC+1): <%= ltt item, :start %>
  • End (UTC+1): <%= ltt item, :end %>
  • +
  • + Calendar: + <%= + [ + { name: 'iCal', identifier: "/schedule/ical/event/#{item[:slug]}/" }, + { name: 'xCal', identifier: "/schedule/xcal/event/#{item[:slug]}/" }, + ].map{|cal| l(cal[:identifier], cal[:name], show_subtitle: false) }.join(", ") + %> +
  • <% if item[:live_video_link] %>
  • Video only: diff --git a/lib/data_sources/schedule.rb b/lib/data_sources/schedule.rb index cd2ce928..71ca5943 100644 --- a/lib/data_sources/schedule.rb +++ b/lib/data_sources/schedule.rb @@ -70,6 +70,20 @@ def to_items(hash, name) end end + # create ical and xcal items for each event + cache.fetch('events').each do |event_slug, event| + [ + { title: 'iCal', mime: 'text/calendar', item: "/schedule/ical/event/#{event_slug}/" }, + { title: 'xCal', mime: 'text/xml', item: "/schedule/xcal/event/#{event_slug}/" }, + ].each do |alt| + meta = event.dup + meta[:events] = [event_slug] + r << Nanoc3::Item.new('', meta, alt[:item], mtime) + event[:alternative_representations] = [] unless event.has_key? :alternative_representations + event[:alternative_representations] << alt + end + end + memory = {} { attachments: 'attachment', diff --git a/lib/helpers/schedule_helpers.rb b/lib/helpers/schedule_helpers.rb index 69d89b06..de597ced 100644 --- a/lib/helpers/schedule_helpers.rb +++ b/lib/helpers/schedule_helpers.rb @@ -47,14 +47,14 @@ def img(item, attr = {}) %Q!! end - def l(item, title = :title, sep = ", ", detail = nil, klass = nil) + def l(item, title = :title, sep = ", ", detail = nil, klass = nil, show_subtitle: true) if item.is_a? String and item.start_with? '/' item = $item_by_id.fetch(item) end case item when Array - item.map { |i| l(i, title, sep, detail, klass) }.join(sep) + item.map { |i| l(i, title, sep, detail, klass, show_subtitle: show_subtitle) }.join(sep) when Nanoc::Item text = case title when Symbol @@ -89,7 +89,7 @@ def l(item, title = :title, sep = ", ", detail = nil, klass = nil) if klass args[:class] = (klass.is_a? Array) ? klass.join(" ") : klass end - subtitle = '
    ' + henc(item[:subtitle]) + '' if item[:subtitle] + subtitle = show_subtitle && item[:subtitle] ? '
    ' + henc(item[:subtitle]) + '' : nil %Q!#{henc text}#{subtitle if subtitle}! else raise "unsupported object of type #{item.class}"