add ics generator

This commit is contained in:
teuserer 2024-03-13 22:19:48 +01:00
parent f61f3f4fce
commit 1de152dbd0
2 changed files with 43 additions and 0 deletions

View file

@ -1,2 +1,3 @@
source "https://rubygems.org" source "https://rubygems.org"
gemspec gemspec
gem 'icalendar'

42
_plugins/events_to_ics.rb Normal file
View file

@ -0,0 +1,42 @@
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