@angus Well, I thought I would go one better
I was trying to understand the code and started tinkering with it a little and came up with this (see commented lines):
def event_ics(opts = {})
guardian.ensure_can_see!(@category) if @category
name_prefix = @category ? "#{SiteSetting.title} - #{@category.name}" : SiteSetting.title
base_url = @category ? @category.url : Discourse.base_url
calendar_name = "#{name_prefix} #{I18n.t("webcal_description.events")}"
calendar_url = "#{base_url}/calendar"
list_opts = {}
list_opts[:category] = @category.id if @category
tzid = params[:time_zone]
tz = TZInfo::Timezone.get tzid
cal = Icalendar::Calendar.new
cal.x_wr_calname = calendar_name
cal.x_wr_timezone = tzid
#added following lines
event_now = DateTime.now
timezone = tz.ical_timezone event_now
cal.add_timezone timezone
@topic_list = TopicQuery.new(current_user, list_opts).list_calendar
@topic_list.topics.each do |t|
if t.event && t.event[:start]
event = CalendarEvents::Helper.localize_event(t.event, tzid)
timezone = tz.ical_timezone event[:start]
#removed following line: only add timezone once
# cal.add_timezone timezone
## to do: check if working later
if event[:format] == :date_only
event[:start] = event[:start].to_date
event[:end] = event[:end].to_date if event[:end]
end
cal.event do |e|
e.dtstart = Icalendar::Values::DateTime.new event[:start], 'tzid' => tzid
if event[:end]
e.dtend = Icalendar::Values::DateTime.new event[:end], 'tzid' => tzid
end
e.summary = t.title
#added url to event body: most calendar clients don't display url field
e.description = t.url << "\n\n" << t.excerpt
e.url = t.url
end
end
end
cal.publish
render body: cal.to_ical, formats: [:ics], content_type: Mime::Type.lookup("text/calendar") unless performed?
end
end
I tested it locally on my server and on Office 365 and it seems to work as desired.
I have also taken the liberty to add the url to event body, since I haven’t found a single web or app calendar client that displays the url field included in the webcal .ics file.
It works really well for me as a quick back link to the forum, but if you feel it doesn’t belong there, please remove it.
Thanks for all your work on these fantastic plugins, I hope this will lessen your burden a tiny bit 