Files
discourse/plugins/discourse-events/app/views/discourse_post_event/events/index.ics.erb
T
David Battersby 629c919eb2 DEV: rename Discourse Calendar to Discourse Events (#42021)
Moves the plugin directory and associated files, along with updating
various import references.
2026-08-12 11:34:15 +04:00

29 lines
1.4 KiB
ERB

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Discourse//<%= Discourse.current_hostname %>//<%= Discourse.full_version %>//EN
X-WR-CALNAME:<%= IcalEncoder.encode(@calendar_name) %>
<%- @ics_events.each do |entry| -%>
<%- event = entry[:event] -%>
<%- starts_at = entry[:starts_at] -%>
<%- ends_at = entry[:ends_at] -%>
<%- next if starts_at.nil? -%>
BEGIN:VEVENT
UID:calendar_event_#<%= event.id %>_<%= starts_at.to_i %>@<%= Discourse.current_hostname %>
DTSTAMP:<%= Time.now.utc.strftime("%Y%m%dT%H%M%SZ") %>
<%- if event.all_day -%>
<%- last_day = (ends_at.present? ? ends_at.utc - 1.second : starts_at.utc).to_date -%>
DTSTART;VALUE=DATE:<%= starts_at.utc.strftime("%Y%m%d") %>
DTEND;VALUE=DATE:<%= (last_day + 1).strftime("%Y%m%d") %>
<%- else -%>
DTSTART:<%= starts_at.utc.strftime("%Y%m%dT%H%M%SZ") %>
DTEND:<%= ends_at.presence ? ends_at.utc.strftime("%Y%m%dT%H%M%SZ") : (starts_at + 1.hour).utc.strftime("%Y%m%dT%H%M%SZ") %>
<%- end -%>
SUMMARY:<%= IcalEncoder.encode(event.name.presence || event.post.topic.title) %>
<%- if event.location.present? -%>LOCATION:<%= IcalEncoder.encode(event.location) %>
<%- end -%>
DESCRIPTION:<%= IcalEncoder.encode([(event.description.presence || event.post.excerpt), event.post.full_url].compact.join("\n")) %>
URL:<%= IcalEncoder.encode_uri(event.url.presence || event.post.topic.url(event.post.post_number)) %>
END:VEVENT
<%- end -%>
END:VCALENDAR