fixed ics generation

This commit is contained in:
Marek Krug 2025-03-12 17:41:44 +01:00
parent 4068fab565
commit 2b5277a3a0
7 changed files with 98 additions and 56 deletions

View file

@ -42,8 +42,8 @@ enableEmoji = true
[outputs] [outputs]
home = ["HTML", "RSS", "JSON"] home = ["HTML", "RSS", "JSON"]
section = ["HTML", "Calendar", "RSS", "XML"] section = ["HTML", "Calendar", "RSS", "XML", "ICS"]
page = ["HTML", "Calendar"] page = ["HTML", "Calendar", "ICS"]
# Output Formats Configuration # Output Formats Configuration
[outputFormats.Calendar] [outputFormats.Calendar]

23
layouts/_default/list.ics Normal file
View file

@ -0,0 +1,23 @@
{{- $time_zone := "Europe/Berlin" -}}
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CCCB//Calendar//DE
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:CCCB Calendar
X-WR-TIMEZONE:{{ $time_zone }}
{{ range .Pages }}
{{ if and .Params.dtstart .Params.dtend }}
BEGIN:VEVENT
UID:{{ .File.BaseFileName }}@berlin.ccc.de
SUMMARY:{{ .Title }}
{{ with .Params.subtitle }}DESCRIPTION:{{ . }}{{ end }}
URL:https://berlin.ccc.de{{ .RelPermalink }}
{{ with .Params.dtstart }}DTSTART:{{ . }}{{ end }}
{{ with .Params.dtend }}DTEND:{{ . }}{{ end }}
{{ with .Params.rrule }}RRULE:{{ . }}{{ end }}
DTSTAMP:{{ now.Format "20060102T150405Z" }}
END:VEVENT
{{ end }}
{{ end }}
END:VCALENDAR

View file

@ -19,36 +19,20 @@ TZNAME:CET
DTSTART:19701025T030000 DTSTART:19701025T030000
END:STANDARD END:STANDARD
END:VTIMEZONE END:VTIMEZONE
{{ range .Pages }}
BEGIN:VEVENT BEGIN:VEVENT
ORGANIZER;CN="CCCB":mailto:datengarten@berlin.ccc.de ORGANIZER;CN="CCCB":mailto:datengarten@berlin.ccc.de
SUMMARY:Datengarten SUMMARY:{{ .Title }}{{ with .Params.subtitle }}: {{ . }}{{ end }}
UID: 0@datengarten.berlin.ccc.de UID:{{ .Params.no }}@datengarten.berlin.ccc.de
SEQUENCE:0 SEQUENCE:0
STATUS:CONFIRMED STATUS:CONFIRMED
DTSTAMP:20180508T200000Z DTSTAMP:{{ dateFormat "20060102T150405Z" .Params.event.start }}
DTSTART;TZID=Europe/Berlin:20180508T200000 DTSTART;TZID=Europe/Berlin:{{ dateFormat "20060102T150405" .Params.event.start }}
DTEND;TZID=Europe/Berlin:20180508T220000 DTEND;TZID=Europe/Berlin:{{ dateFormat "20060102T150405" .Params.event.end }}
RRULE:FREQ=MONTHLY;BYSETPOS=2;BYDAY=TU;INTERVAL=1;UNTIL=20190409T220000 LOCATION:{{ with .Params.location }}{{ . }}{{ else }}CCCB{{ end }}
{{range .Pages -}} URL:{{ .Permalink }}
EXDATE;TZID=Europe/Berlin:{{dateFormat "20060102T150405" .Params.event.start}} DESCRIPTION:{{ .Permalink }}
{{end -}}
LOCATION:{{with .Params.location}}{{.}}{{else}}CCCB{{end}}
URL:{{.Permalink}}
DESCRIPTION:{{.Permalink}}
END:VEVENT END:VEVENT
{{range .Pages -}} {{ end }}
BEGIN:VEVENT
ORGANIZER;CN="CCCB":mailto:datengarten@berlin.ccc.de
SUMMARY:{{.Title}}{{with .Params.subtitle}}: {{.}}{{end}}
UID:{{.Params.no}}@datengarten.berlin.ccc.de
SEQUENCE:0
STATUS:CONFIRMED
DTSTAMP:{{dateFormat "20060102T150405Z" .Params.event.start}}
DTSTART;TZID=Europe/Berlin:{{dateFormat "20060102T150405" .Params.event.start}}
DTEND;TZID=Europe/Berlin:{{dateFormat "20060102T150405" .Params.event.end}}
LOCATION:{{with .Params.location}}{{.}}{{else}}CCCB{{end}}
URL:{{.Permalink}}
DESCRIPTION:{{.Permalink}}
END:VEVENT
{{end -}}
END:VCALENDAR END:VCALENDAR

View file

@ -1,31 +1,35 @@
{{ $style := resources.Get "css/calendar.css" | resources.ToCSS | resources.Fingerprint }} {{ $js := resources.Get "js/calendar.js" }}
<link rel="stylesheet" href="{{ $style.RelPermalink }}"> {{ $css := resources.Get "css/calendar.css" }}
{{ $js := resources.Get "js/calendar.js" | resources.Fingerprint }}
<script src="{{ $js.RelPermalink }}" defer></script>
<div class="calendar-container"> <div class="calendar-container">
<div id="calendar"> {{ with $css }}
<div id="calendar-controls"> <link rel="stylesheet" href="{{ .RelPermalink }}">
<button id="prev-month">&larr;</button> {{ end }}
<span id="current-month"></span> {{ with $js }}
<button id="next-month">&rarr;</button> <script src="{{ .RelPermalink }}"></script>
</div> {{ end }}
<table id="calendar-table">
<thead> <div id="calendar">
<tr> <div id="calendar-controls">
<th>Mo</th> <button id="prev-month">&larr;</button>
<th>Di</th> <span id="current-month"></span>
<th>Mi</th> <button id="next-month">&rarr;</button>
<th>Do</th>
<th>Fr</th>
<th>Sa</th>
<th>So</th>
</tr>
</thead>
<tbody id="calendar-body"></tbody>
</table>
</div> </div>
<table id="calendar-table">
<thead>
<tr>
<th>Mo</th>
<th>Di</th>
<th>Mi</th>
<th>Do</th>
<th>Fr</th>
<th>Sa</th>
<th>So</th>
</tr>
</thead>
<tbody id="calendar-body"></tbody>
</table>
</div>
<div id="event-panel"> <div id="event-panel">
<div id="event-date"></div> <div id="event-date"></div>
<div id="event-details"></div> <div id="event-details"></div>

View file

@ -0,0 +1,25 @@
{{- $time_zone := "Europe/Berlin" -}}
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CCCB//Calendar//DE
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:CCCB Veranstaltungen
X-WR-TIMEZONE:{{ $time_zone }}
{{ range .Pages }}
BEGIN:VEVENT
UID:{{ .File.BaseFileName }}@berlin.ccc.de
SUMMARY:{{ .Title }}
{{ with .Params.subtitle }}
DESCRIPTION:{{ . }}
Link: https://berlin.ccc.de{{ $.RelPermalink }}
{{ end }}
URL:https://berlin.ccc.de{{ .RelPermalink }}
{{ with .Params.dtstart }}DTSTART:{{ . }}{{ end }}
{{ with .Params.dtend }}DTEND:{{ . }}{{ end }}
{{ with .Params.rrule }}RRULE:{{ . }}{{ end }}
DTSTAMP:{{ now.Format "20060102T150405Z" }}
END:VEVENT
{{ end }}
END:VCALENDAR

View file

@ -56,8 +56,10 @@ def find_events(icsfilestr, start, end, num):
if event.name == "VEVENT": if event.name == "VEVENT":
if "RRULE" in event.keys(): if "RRULE" in event.keys():
events.extend(parse_recurring_event(event, start, end)) events.extend(parse_recurring_event(event, start, end))
elif ev := parse_single_event(event, start, end) != None: else:
events.append(ev) ev = parse_single_event(event, start, end)
if ev is not None:
events.append(ev)
events = sorted(events, key=lambda k: k["begin"]) events = sorted(events, key=lambda k: k["begin"])
events = events[0:num] events = events[0:num]

View file

@ -18,6 +18,10 @@ for icsfilestr in glob("public/*/**/*.ics", recursive=True):
for calendar in calendars: for calendar in calendars:
for event in calendar.subcomponents: for event in calendar.subcomponents:
if event.name != "VEVENT":
continue
if "DTSTART" not in event:
continue
merged.add_component(event) merged.add_component(event)
outfile = "static/all.ics" outfile = "static/all.ics"