-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Setting up iCal feed * Pipping in real data into this ical * Switching to .ics filename * Adding timezones definition to UTC * Adding tzinfo gem * Ditching .utc * Converting these dates to UTC also * Ditching timezones - it's breaking & I'm not sure now * I think this might work for Google Calendar * Changing URL to see if google refreshes * happy_gemfile all * Using builder to generate ical * Removing fileutil requirement * Bumping gems to latest seems to solve build issue locally * Timezones were off - looking into that * Setting mime-type for .ics file * Setting timezones to be UTC more explicitly * Standardrb --fix * I think google caches the .cal file - so changing it to check * It was caching - sorted now * Setting correct content-type * Ditching the feed file in src
- Loading branch information
1 parent
5785174
commit b1e088c
Showing
5 changed files
with
96 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require "icalendar" | ||
|
||
class IcalBuilder < SiteBuilder | ||
def build | ||
hook :site, :post_write do | ||
generate(site) | ||
end | ||
end | ||
|
||
private | ||
|
||
# Main plugin action, called by Bridgetown-core | ||
def generate(site) | ||
@site = site | ||
return if file_exists?(file_path) | ||
make_ical_file | ||
end | ||
|
||
def make_ical_file | ||
File.write(file_path, ical_output) | ||
end | ||
|
||
def file_path | ||
File.join(site.dest, "ical.ical") | ||
end | ||
|
||
# Checks if a file already exists in the site source | ||
def file_exists?(file_path) | ||
File.exist? @site.in_source_dir(file_path) | ||
end | ||
|
||
def ical_output | ||
cal = Icalendar::Calendar.new | ||
cal.prodid = "-//Ruby Meetup Calendar//Calendar 1.0//EN" | ||
cal.append_custom_property("X-WR-CALNAME", "Ruby Meetup Calendar") | ||
cal.append_custom_property("X-WR-TIMEZONE", "Etc/UTC") | ||
cal.append_custom_property("X-PUBLISHED-TTL", "PT24H") | ||
cal.append_custom_property("X-WR-CALDESC", "Find Ruby Meetup Events") | ||
|
||
@site.collections.events.docs.each do |event| | ||
ical_event = Icalendar::Event.new | ||
ical_event.uid = event.url | ||
ical_event.dtstart = Icalendar::Values::DateTime.new(event[:datetime].to_datetime.utc, tzid: "UTC") | ||
ical_event.summary = event[:title] | ||
ical_event.description = event[:external_url] | ||
ical_event.url = event[:external_url] | ||
ical_event.status = "CONFIRMED" | ||
ical_event.transp = "OPAQUE" | ||
ical_event.sequence = 0 | ||
cal.add_event(ical_event) | ||
end | ||
|
||
cal.publish | ||
cal.to_ical | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters