www.netz39.de/_plugins/events_to_ics.rb

43 lines
918 B
Ruby
Raw Normal View History

2024-03-13 22:19:48 +01:00
require 'icalendar'
module Jekyll
class IcsGenerator < Generator
safe true
priority :low
def generate(site)
events = site.collections['events'].docs
cal = Icalendar::Calendar.new
events.each do |event|
title = event.data['title']
date = event.data['event_date']
event = Icalendar::Event.new
event.dtstart = date
event.dtend = date
event.summary = title
cal.add_event(event)
end
site.pages << IcalPage.new(site, site.source, 'feed', "events.ics", cal)
puts "Generated .ics page from #{events.length} events"
end
end
class IcalPage < Page
def initialize(site, base, dir, name, calendar)
@site = site
@base = base
@dir = dir
@name = name
self.process(name)
self.content = calendar.to_ical
self.data = {
'layout' => nil
}
end
end
end