This project was built as part of my answer to a question on StackOverflow. It illustrates how to read ics
files using a custom Jekyll plugin written in Ruby, and expose the extracted data to a liquid variable.
Usage
Add icalendar
to your Gemfile
and install it:
bundle add icalendar
bundle install
Get the calendar_reader.rb
file and place it under the _plugins
directory.
Take an example ics file my_calendar.ics
and put it into the _data
folder.
Now you can use the plugin filter from your markdown/html:
{% assign events = "_data/my_calendar.ics" | read_calendar %}
Here read_calendar
is the function defined in _plugins/calendar_reader.rb
and _data/my_calendar.ics
is the file you want to get the data from. The plugin gets the input
file name, reads it and returns a hash
which is stored into the events
variable itself.
You can now use {{ events }}
to access the hash of the data that you return from the function in the plugin file.
// {{ events }}
{0=>{"summary"=>"This is a really long summary to test the method of unfolding lines, so I'm just going to make it a whole bunch of lines.", "dtstart"=>#<DateTime: 2005-01-20T17:00:00+00:00 ((2453391j,61200s,0n),+0s,2299161j)>, "dtend"=>#<DateTime: 2005-01-20T18:45:00+00:00 ((2453391j,67500s,0n),+0s,2299161j)>, "description"=>nil}, 1=>{"summary"=>"This is a very short summary.", "dtstart"=>#<DateTime: 2011-01-20T17:00:00+00:00 ((2455582j,61200s,0n),+0s,2299161j)>, "dtend"=>#<DateTime: 2011-01-20T18:45:00+00:00 ((2455582j,67500s,0n),+0s,2299161j)>, "description"=>nil}}
// {{ events[0] }}:
{"summary"=>"This is a really long summary to test the method of unfolding lines, so I'm just going to make it a whole bunch of lines.", "dtstart"=>#<DateTime: 2005-01-20T17:00:00+00:00 ((2453391j,61200s,0n),+0s,2299161j)>, "dtend"=>#<DateTime: 2005-01-20T18:45:00+00:00 ((2453391j,67500s,0n),+0s,2299161j)>, "description"=>nil}
// {{ events[1] }}:
{"summary"=>"This is a very short summary.", "dtstart"=>#<DateTime: 2011-01-20T17:00:00+00:00 ((2455582j,61200s,0n),+0s,2299161j)>, "dtend"=>#<DateTime: 2011-01-20T18:45:00+00:00 ((2455582j,67500s,0n),+0s,2299161j)>, "description"=>nil}
For more information, checkout the project repository at GitHub.