mirror of
https://github.com/netz39/www.netz39.de.git
synced 2025-01-31 09:33:18 +01:00
add ics generator
This commit is contained in:
parent
f61f3f4fce
commit
1de152dbd0
2 changed files with 43 additions and 0 deletions
1
Gemfile
1
Gemfile
|
@ -1,2 +1,3 @@
|
||||||
source "https://rubygems.org"
|
source "https://rubygems.org"
|
||||||
gemspec
|
gemspec
|
||||||
|
gem 'icalendar'
|
||||||
|
|
42
_plugins/events_to_ics.rb
Normal file
42
_plugins/events_to_ics.rb
Normal 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
|
Loading…
Add table
Reference in a new issue