render event content into event description as plain text

This commit is contained in:
teuserer 2024-03-13 23:14:55 +01:00
parent 2bb2b2ddb8
commit 7f7e6abaaa
2 changed files with 23 additions and 5 deletions

View file

@ -1,3 +1,4 @@
source "https://rubygems.org" source "https://rubygems.org"
gemspec gemspec
gem 'icalendar' gem 'icalendar'
gem 'redcarpet'

View file

@ -1,4 +1,6 @@
require 'icalendar' require 'icalendar'
require 'redcarpet'
require 'redcarpet/render_strip'
module Jekyll module Jekyll
class IcsGenerator < Generator class IcsGenerator < Generator
@ -7,17 +9,32 @@ module Jekyll
def generate(site) def generate(site)
events = site.collections['events'].docs events = site.collections['events'].docs
organizer = "Netz39 Team <kontakt@netz39.de>"
location = "Netz39 e.V., Leibnizstraße 32, 39104 Magdeburg"
cal = Icalendar::Calendar.new cal = Icalendar::Calendar.new
events.each do |event| events.each do |event|
title = event.data['title'] title = event.data['title']
date = event.data['event_date'] date = event.data['event_date']
event = Icalendar::Event.new
event.dtstart = date # Remove image URLs from description
event.dtend = date content = event.content
event.summary = title content.gsub!(/\!\[.*?\]\((.*?)\)/, '')
cal.add_event(event)
# Render Markdown content to plain text
markdown_parser = Redcarpet::Markdown.new(Redcarpet::Render::StripDown)
description = markdown_parser.render(content)
# Create new event and set its properties
ical_event = Icalendar::Event.new
ical_event.dtstart = Icalendar::Values::Date.new(date)
ical_event.dtend = Icalendar::Values::Date.new(date)
ical_event.summary = title
ical_event.description = description
ical_event.organizer = organizer
ical_event.location = location
cal.add_event(ical_event)
end end
site.pages << IcalPage.new(site, site.source, 'feed/eo-events', "events.ics", cal) site.pages << IcalPage.new(site, site.source, 'feed/eo-events', "events.ics", cal)