mirror of
https://github.com/netz39/www.netz39.de.git
synced 2025-01-18 20:10:12 +01:00
render event content into event description as plain text
This commit is contained in:
parent
2bb2b2ddb8
commit
7f7e6abaaa
2 changed files with 23 additions and 5 deletions
1
Gemfile
1
Gemfile
|
@ -1,3 +1,4 @@
|
|||
source "https://rubygems.org"
|
||||
gemspec
|
||||
gem 'icalendar'
|
||||
gem 'redcarpet'
|
||||
|
|
|
@ -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 <kontakt@netz39.de>"
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue