From e00b1772211c3c98971cfa230820ccf3d5bbe000 Mon Sep 17 00:00:00 2001 From: eclipse Date: Mon, 17 Feb 2025 21:05:18 +0100 Subject: [PATCH] lots of work around extracting, parsing and presenting events --- pelicanconf.py | 6 +-- theme/static/css/custom.css | 12 ++++-- theme/templates/termine.noformat.html | 53 ++++++++++++++++----------- utils/refresh-events.py | 51 +++++++------------------- 4 files changed, 56 insertions(+), 66 deletions(-) diff --git a/pelicanconf.py b/pelicanconf.py index ad7ad12..9a1c45e 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -8,11 +8,8 @@ SITESUBTITLE = "Schriftsteller" SITEURL = "" TIMEZONE = 'Europe/Berlin' -DATE_FORMATS = { - 'de': '%a, %d. %b %y', - 'en': '%Y-%m-%d(%a)', -} DEFAULT_LANG = 'de' +#DEFAULT_DATE_FORMAT = '%d.%m.%Y' (doesn't seem to work) THEME = "theme/" @@ -84,6 +81,7 @@ SOCIAL = ( # Technical Settings # ############################################################################### +PLUGINS = ["pelican.plugins.yaml_metadata"] JINJA_ENVIRONMENT = { "extensions": ["jinja2.ext.debug", "jinja2.ext.do"] } diff --git a/theme/static/css/custom.css b/theme/static/css/custom.css index 8192da8..4f7c919 100644 --- a/theme/static/css/custom.css +++ b/theme/static/css/custom.css @@ -227,9 +227,15 @@ a { } /* grid settings for event list */ -.event-grid { - display: grid; - grid-template-columns: minmax(auto, 250px) minmax(60%, auto); +.events {} + +.event-info { + vertical-align: top; + max-width: 240px; +} + +.event-detail { + vertical-align: top; } /* flex settings for layout of cards */ diff --git a/theme/templates/termine.noformat.html b/theme/templates/termine.noformat.html index 3e6ea34..44fa86a 100644 --- a/theme/templates/termine.noformat.html +++ b/theme/templates/termine.noformat.html @@ -1,25 +1,34 @@ {% extends "page.html" %} - -{% block content_body %} +{# note that this template's filename is ''termine.noformat.html'' and not ''termine.html''. This is because vscodium's auto-format breaks the ''replace'' filters in the summary line, which is bad. The double file extension enables an exlude rule for all "noformat.html" files from within vscodium's settings.json file. #} {% if page.termine is defined %} -
-
-
Termin
-
Veranstaltung
-
-
- {% for t in page.termine %} -
{{ t.startdate }}{% if t.enddate is defined %}–{{t.enddate }}{% elif t.starttime is defined %}, {{ t.starttime }}{% endif %}
-
-
- {{ t.summary }} - {% if t.description is defined %}

{{ t.description | replace("\n\n", "

") | replace("\n", "
") | replace("


", "

")}}

{% endif %} - {% if t.location is defined %}

Ort: {{ t.location }}

{% endif %} -
-
- {% endfor %} -
- {% if page.date is defined %}
Letzte Aktualisierung: {{ page.date }}
{% endif %} -
+{% set date_format = "%d.%m." %} +{% set time_format = "%H:%M" %} +{% block content_body %} + + + + + + + + + {% for t in page.termine %} + + + + + {% endfor %} + +
Wann & WoWas & Wieso
{{ t.startdate | strftime(date_format) }}{% if t.enddate is defined %}–{{t.enddate | strftime(date_format) }}{% elif t.starttime is defined %} {{ t.starttime | strftime(time_format) }}{% endif %}
{{ t.location }}
+

{{ t.summary }} {% if "Moderation" in t.categories %}(Moderation){%endif%}

+ {% if t.description is defined %}

{{ t.description | replace("\n\n", "

") | replace("\n", "
") | replace("


", "

")}}

{% endif %} + {% if t.attach is defined %}

Mehr Infos

{% endif %} +
+{% endblock content_body %} + +{% if page.written_at is defined %} +{% block content_footer %} +

Letzte Aktualisierung: {{ page.written_at | strftime("%d.%m.%Y, %H:%M Uhr") }}

+{% endblock content_footer %} +{% endif %} {% endif %} -{% endblock content_body %} \ No newline at end of file diff --git a/utils/refresh-events.py b/utils/refresh-events.py index d4ee99e..6270e73 100755 --- a/utils/refresh-events.py +++ b/utils/refresh-events.py @@ -4,11 +4,6 @@ from datetime import datetime, date, time, timedelta import yaml import os -import locale -import threading -from contextlib import contextmanager - - """CalDAV server url""" server_url = "https://***REMOVED*** """CalDAV calendar url""" @@ -84,7 +79,7 @@ def extractEventData(events): if len(v) == 1: d[k] = v[0].value # but sometimes the list has more than one item; this only ever happens for the property "categories" - # and in this case, each list item's value is itself a one item list (which is stupid but that's how vobject handles categories) + # and in this case, each list item's value is itself a one item list (which is stupid but that's how vobject handles categories …) else: d[k] = [v[i].value[0] for i in range(len(v))] e_tmp.append(d) @@ -129,47 +124,29 @@ events = [e for e in events if e["dtstart"] >= now] # sort by start date events.sort(key=lambda e: e["dtstart"]) +# add start date to metadata, also start time and/or end date +for e in events: + # start date + e["startdate"] = e["dtstart"].astimezone() + # start time (if not the default time) + if e["dtstart"].timetz() != time(23, 59, 59, tzinfo=now.tzinfo): + e["starttime"] = e["dtstart"].astimezone() + # end date (if different from start date) + if e["dtstart"].date() < e["dtend"].date(): + e["enddate"] = e["dtend"].astimezone() + # read default metadata if present default_metadata = None if os.path.isfile(result_file + ".metadata"): with open(result_file + ".metadata", "r") as f: default_metadata = yaml.safe_load(f) -# set up a context manager in order to threadsafely format dates and times with the German locale -# source: https://stackoverflow.com/a/24070673 -LOCALE_LOCK = threading.Lock() - -@contextmanager -def setlocale(name): - with LOCALE_LOCK: - saved = locale.setlocale(locale.LC_TIME) - try: - yield locale.setlocale(locale.LC_TIME, name) - finally: - locale.setlocale(locale.LC_TIME, saved) - -# temporary set locale to de_DE (category "time" only) and format start date as well as start time or end date -with setlocale('de_DE.UTF-8'): - for e in events: - # start date - e["startdate"] = e["dtstart"].strftime("%a, %d.%m.") - # start time (if not the default time) - if e["dtstart"].timetz() != time(23, 59, 59, tzinfo=now.tzinfo): - e["starttime"] = e["dtstart"].strftime("%H:%M Uhr") - # end date (if different from start date) - if e["dtstart"].date() < e["dtend"].date(): - e["enddate"] = e["dtend"].date().strftime("%a, %d.%m.") - - # add current date to default metadata while we're at it - if default_metadata: - default_metadata["date"] = now.strftime("%Y-%m-%d %H:%M") - # write data as YAML with open(result_file, 'w') as f: f.write("---\n") if default_metadata: yaml.dump(default_metadata, f) yaml.dump({"termine": events}, f) + # write current datetime to file + yaml.dump({"written_at": now}, f) f.write("---\n") - f.write("written at " + datetime.today().isoformat(" ")) -