Class: Jekyll::ICalendarGenerator

Inherits:
Generator
  • Object
show all
Defined in:
lib/seminima/calendar.rb

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/seminima/calendar.rb', line 50

def generate(site)
  calendar = make_calendar site, {}

  PageWithoutAFile.new(site, __dir__, "", "calendar.ics").tap do |file|
    file.content = calendar.to_ical
    site.pages << file
  end
end

#make_calendar(site, config) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/seminima/calendar.rb', line 10

def make_calendar(site, config)
  
  cal = Icalendar::Calendar.new

  tzid = "Europe/Amsterdam"
  tz = TZInfo::Timezone.get(tzid)
  timezone = tz.ical_timezone Time.now
  cal.add_timezone timezone

  upcoming_talks = site.collections['talks'].docs.select do |talk|
    date = talk.date
    if date.is_a?(String)
      date = Date.parse(date)
    end
    date >= Time::now
  end
  upcoming_talks.each do |talk|
    cal.event do |e|
      date = talk.date
      if date.is_a?(String)
        date = Date.parse(date)
      end
      e.uid = SecureRandom.uuid
      zone = TZInfo::Timezone.get("Europe/Amsterdam")
      start_hour, start_min = talk.data["start_time"].split(":").map(&:to_i)
      end_hour, end_min = talk.data["end_time"].split(":").map(&:to_i)
      start_time = Time.new(date.year, date.month, date.day, start_hour, start_min, 0)
      end_time = Time.new(date.year, date.month, date.day, end_hour, end_min, 0)
      e.dtstart = Icalendar::Values::DateTime.new start_time, 'tzid' => tzid
      e.dtend = Icalendar::Values::DateTime.new end_time, 'tzid' => tzid
      e.summary = talk.data['speaker'] + ": " + talk.data['title']
      e.description = talk.data['abstract']
      e.location = talk.data['location']
      e.url = talk.data['redirectURL']
    end
  end
  
  cal
end