Skip to content

Commit

Permalink
Merge pull request #348 from lrug/calendar
Browse files Browse the repository at this point in the history
Generate ics file for recent events
  • Loading branch information
fcheung authored Sep 6, 2024
2 parents 720abd6 + 2f666fc commit 3ec2d10
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ gem 'builder'
gem 'git'
gem 'nokogiri'
gem 'pry'
gem 'icalendar'
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ GEM
hashie (3.6.0)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
icalendar (2.10.2)
ice_cube (~> 0.16)
ice_cube (0.17.0)
kramdown (2.4.0)
rexml
listen (3.0.8)
Expand Down Expand Up @@ -119,6 +122,7 @@ PLATFORMS
DEPENDENCIES
builder
git
icalendar
middleman
nokogiri
pry
Expand Down
1 change: 1 addition & 0 deletions config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

page '/.htaccess', layout: false
page '/version.json', layout: false
page '/meetings.ics', layout: false

ready do
sitemap.resources.
Expand Down
2 changes: 1 addition & 1 deletion data/redirects.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
{
"from":"meeting-calendar",
"to":"https://www.google.com/calendar/ical/[email protected]/public/basic.ics"
"to":"/meetings.ics"
},
{
"from":"speaking",
Expand Down
42 changes: 41 additions & 1 deletion lib/lrug_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def render_markdown(md)
end

def meeting_calendar_link
%{<span class="calendar-link"><a href="/meeting-calendar"><img src="https://assets.lrug.org/images/calendar_down.gif" alt="Calendar subscription" loading="lazy"> Meeting Calendar</a></span>}
%{<span class="calendar-link"><a href="/meetings.ics"><img src="https://assets.lrug.org/images/calendar_down.gif" alt="Calendar subscription" loading="lazy"> Meeting Calendar</a></span>}
end

def indent_xml(indent, xml_string)
Expand All @@ -215,6 +215,46 @@ def has_host?(page)
content_part_exists?('hosted_by', page) || page.data.has_key?('hosted_by')
end

def events_calendar(site_url:)
calendar = Icalendar::Calendar.new
calendar.timezone do |timezone|
timezone.tzid = 'Europe/London'
end
zone = ActiveSupport::TimeZone['Europe/London']

all_meetings = meeting_pages

upcoming = all_meetings.take_while {|page| page.metadata[:page][:meeting_date] >= Date.today}
next_12 = all_meetings.drop(upcoming.length).take(12)

(upcoming + next_12).each do |page|
url = URI.join(site_url, page.url)
date = page.metadata[:page][:meeting_date]
title = page.metadata[:page][:title]
hosts = page.metadata[:page][:hosted_by]

calendar.event do |event|
event.uid = "lrug-monthly-#{date.strftime('%Y-%m')}"
event.dtstart = date.in_time_zone(zone).change(hour:18)
event.dtend = date.in_time_zone(zone).change(hour:20)
event.summary = "London Ruby User Group - #{title}"
event.url = URI.join(site_url, page.url)

if hosts.present?
hosted_by = "Hosted by: #{hosts.map {|h| h[:name]}.join(', ')}"
end

event.description = <<~DESC
London Ruby User Group - #{title}
#{hosted_by}
DESC
end
end

calendar
end

private
def inline_content_render(content, fake_pathname, locals: {})
# create a middleman filerenderer to do the work, the extension in
Expand Down
1 change: 1 addition & 0 deletions source/meetings.ics.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= events_calendar(site_url: "https://lrug.org/").to_ical %>

0 comments on commit 3ec2d10

Please sign in to comment.