Rakefire / jekyll-ical-tag

Pull ICS feed and provide a for-like loop of calendar events in jekyll's liquid tag
7 stars 6 forks source link

Recurring events only showing initial event #45

Closed whatnotery closed 1 month ago

whatnotery commented 1 month ago

Hi! I'm running into a use case where if there's a recurring event it doesn't display any of them but the initial one in the Jekyll site.

I've been trying to develop a pr introducing icalendar-recurrence to allow for recurrence. I think the easiest way to do this would be in the parsed_feed method by iterating over each of the events in the feed and then using the occurrences_between method from icalendar-recurrence to get recurring events and then merging them into the existing array created by Icalendar::Event.parse(@raw_feed). A problem I'm running into is that the reoccurrence objects are of a different type struct than the Event.parse objects and I'm also not sure what the best way to make this optional via arguments in the template tag.

Any thoughts you have or suggestions would be appreciated!

rickychilcott commented 1 month ago

Hi @whatnotery -- I'd be happy for this gem to support recurring events.

Do you have a public feed we can pull from for a test? Additionally, do you want to push up what you have?

We might end up changing the way we iterate -- either by providing a decorator over each event to either provide an occurance (even for a single event) or something else.

A test feed, tests, and what you've got will help me get closer to something shippable

whatnotery commented 1 month ago

This is what I've got so far which isn't really working in a meaningful way but is getting somewhere I hope.

This is a public ical link with two recurring events, one monthly and one weekly and three non recurring events spread through july and august

Thanks for the quick response! and let me know if theres anything else I can do to help :)

rickychilcott commented 1 month ago

Thanks. I'm using what you started with. I'm going to time-box for about 15 more minutes and then push up what I've got so far.

rickychilcott commented 1 month ago

Mind trying out my branch?

gem 'jekyll-ical-tag', github: "Rakefire/jekyll-ical-tag", branch: 'feature/recurring-events'

whatnotery commented 1 month ago

Awesome! I'll test it out shortly! thanks so much for your work on this!

whatnotery commented 1 month ago

Sorry for the delay! in both apps I've tested this with I've gotten the following error when trying to build

Generating...
       Jekyll Feed: Generating feed for posts
  Liquid Exception: undefined local variable or method `context' for #<Jekyll::IcalTag:0x00000001094bce40 @tag_name="ical", @markup="url: https://calendar.google.com/calendar/ical/64dbc9200e64d520220ae7169fbe8b43dc149b3b17eef6de8cdc7ee1505a8f12%40group.calendar.google.com/public/basic.ics ", @parse_context=#<Liquid::ParseContext:0x00000001092162e0 @template_options={:line_numbers=>true, :locale=>#<Liquid::I18n:0x00000001092f03f0 @path="/Users/jos/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/liquid-4.0.4/lib/liquid/locales/en.yml">}, @locale=#<Liquid::I18n:0x00000001092f03f0 @path="/Users/jos/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/liquid-4.0.4/lib/liquid/locales/en.yml">, @warnings=[], @depth=0, @partial=false, @options={:line_numbers=>true, :locale=>#<Liquid::I18n:0x00000001092f03f0 @path="/Users/jos/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/liquid-4.0.4/lib/liquid/locales/en.yml">}, @error_mode=:warn, @line_number=2, @trim_whitespace=false>, @line_number=2, @blank=true, @attributes={"url"=>"https://calendar.google.com/calendar/ical/64dbc9200e64d520220ae7169fbe8b43dc149b3b17eef6de8cdc7ee1505a8f12%40group.calendar.google.com/public/basic.ics"}, @limit=nil, @reverse=false, @only=:all> in index.markdown
                    ------------------------------------------------
      Jekyll 4.3.3   Please append `--trace` to the `serve` command
                     for any additional information or backtrace.
                    ------------------------------------------------
/Users/jos/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/bundler/gems/jekyll-ical-tag-822e2fe4fef6/lib/jekyll-ical-tag.rb:164:in `set_recurring_dates!': undefined local variable or method `context' for #<Jekyll::IcalTag:0x00000001094bce40 @tag_name="ical", @markup="url: https://calendar.google.com/calendar/ical/64dbc9200e64d520220ae7169fbe8b43dc149b3b17eef6de8cdc7ee1505a8f12%40group.calendar.google.com/public/basic.ics  ", @parse_context=#<Liquid::ParseContext:0x00000001092162e0 @template_options={:line_numbers=>true, :locale=>#<Liquid::I18n:0x00000001092f03f0 @path="/Users/jos/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/liquid-4.0.4/lib/liquid/locales/en.yml">}, @locale=#<Liquid::I18n:0x00000001092f03f0 @path="/Users/jos/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/liquid-4.0.4/lib/liquid/locales/en.yml">, @warnings=[], @depth=0, @partial=false, @options={:line_numbers=>true, :locale=>#<Liquid::I18n:0x00000001092f03f0 @path="/Users/jos/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/liquid-4.0.4/lib/liquid/locales/en.yml">}, @error_mode=:warn, @line_number=2, @trim_whitespace=false>, @line_number=2, @blank=true, @attributes={"url"=>"https://calendar.google.com/calendar/ical/64dbc9200e64d520220ae7169fbe8b43dc149b3b17eef6de8cdc7ee1505a8f12%40group.calendar.google.com/public/basic.ics"}, @limit=nil, @reverse=false, @only=:all> (NameError)

         dereferenced_liquid_val(context, "recurring_end_date")
                                 ^^^^^^^
    from /Users/jos/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/bundler/gems/jekyll-ical-tag-822e2fe4fef6/lib/jekyll-ical-tag.rb:26:in `initialize'
    from /Users/jos/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/liquid-4.0.4/lib/liquid/tag.rb:9:in `new'
    from /Users/jos/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/liquid-4.0.4/lib/liquid/tag.rb:9:in `parse'
rickychilcott commented 1 month ago

I don't have good integration tests on the jekyll side of things. Sorry about that. I think I have it fixed (just pushed), but I'm not 100% positive until I can try with a real test harness. Mind doing a bundle update? If that doesn't work then I may get to it this weekend -- tomorrow is out.

I suspect it's pretty close.

whatnotery commented 1 month ago

It's super close! I've got a dummy Jekyll app here pulling from the same calendar from above (That I've added additional events to). Below is the template code and a screenshot of the page.

the only issue I'm seeing is that with recurring events where the first occurrence hasn't happened yet it shows the initial one from the ics and then also displays it again likely as the first of the event.occurrences_between(@recurring_start_date, @recurring_end_date) so I think if you skip the first index from that array it will solve that initial duplication issue but that's just a guess?

# all events
{% ical url: https://calendar.google.com/calendar/ical/64dbc9200e64d520220ae7169fbe8b43dc149b3b17eef6de8cdc7ee1505a8f12%40group.calendar.google.com/public/basic.ics
 limit: 10  %}
# {{ event.summary }}
## {{ event.start_time | date: '%A %B %d %Y' America/New_York }}
### {{ event.start_time | date: '%-I:%M %P' America/New_York }} - {{ event.end_time | date: '%-I:%M %P' America/New_York }}
    {{ event.description }}
{% endical %}

---

# future events
{% ical url: https://calendar.google.com/calendar/ical/64dbc9200e64d520220ae7169fbe8b43dc149b3b17eef6de8cdc7ee1505a8f12%40group.calendar.google.com/public/basic.ics 
limit: 10 only_future: true %}
# {{ event.summary }}
## {{ event.start_time | date: '%A %B %d %Y' America/New_York }}
### {{ event.start_time | date: '%-I:%M %P' America/New_York }} - {{ event.end_time | date: '%-I:%M %P' America/New_York }}
    {{ event.description }}
{% endical %}

image

whatnotery commented 1 month ago

Just saw your changes on #46 ! I'll test them as soon as I can, likely this evening or tomorrow and let you know how it works. it looks like it should solve it!

whatnotery commented 1 month ago

@rickychilcott It works!!!

rickychilcott commented 1 month ago

Woot!