From 7f7e6abaaad984e00a111c398e6ff864bd2fc845 Mon Sep 17 00:00:00 2001 From: teuserer Date: Wed, 13 Mar 2024 23:14:55 +0100 Subject: [PATCH] render event content into event description as plain text --- Gemfile | 1 + _plugins/events_to_ics.rb | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index a941335..43eab55 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,4 @@ source "https://rubygems.org" gemspec gem 'icalendar' +gem 'redcarpet' diff --git a/_plugins/events_to_ics.rb b/_plugins/events_to_ics.rb index c422b64..4d15774 100644 --- a/_plugins/events_to_ics.rb +++ b/_plugins/events_to_ics.rb @@ -1,4 +1,6 @@ require 'icalendar' +require 'redcarpet' +require 'redcarpet/render_strip' module Jekyll class IcsGenerator < Generator @@ -7,17 +9,32 @@ module Jekyll def generate(site) events = site.collections['events'].docs + organizer = "Netz39 Team " + location = "Netz39 e.V., Leibnizstraße 32, 39104 Magdeburg" cal = Icalendar::Calendar.new events.each do |event| title = event.data['title'] date = event.data['event_date'] - event = Icalendar::Event.new - event.dtstart = date - event.dtend = date - event.summary = title - cal.add_event(event) + + # Remove image URLs from description + content = event.content + content.gsub!(/\!\[.*?\]\((.*?)\)/, '') + + # 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 site.pages << IcalPage.new(site, site.source, 'feed/eo-events', "events.ics", cal)