diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index d95f0ed..0860223 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -2,7 +2,7 @@ name: Deploy site to GitHub Pages on: push: - branches: [master] + branches: [main] pull_request: workflow_dispatch: diff --git a/ics_generator.py b/ics_generator.py index 64e6a7e..b262d7d 100644 --- a/ics_generator.py +++ b/ics_generator.py @@ -15,17 +15,21 @@ reader = readers.RstReader(settings=DEFAULT_CONFIG.copy()) calendar = ics.Calendar(creator="HPC@Maths") - -for event_file in glob.glob(f"{EVENTS_PATH}/*.rst"): +# Sorted so that the output does not depend on the filesystem order. +for event_file in sorted(glob.glob(f"{EVENTS_PATH}/*.rst")): content, metadata = reader.read(event_file) event = ics.Event() + # The UID must stay the same from one build to the next, otherwise + # subscribed calendars treat every event as new at each refresh. + slug = os.path.splitext(os.path.basename(event_file))[0] + event.uid = f"{slug}@{SITE_DOMAIN.split('://')[-1]}" # event.replace_timezone(tzinfo=tz.gettz("Europe/Paris")) if 'speaker' in metadata: event.summary = f"{metadata['title']} - {metadata['speaker']}" else: event.summary = f"{metadata['title']}" - event.description = f"More information: {SITE_DOMAIN}{SITEURL}/pages/{os.path.splitext(os.path.basename(event_file))[0]}.html" + event.description = f"More information: {SITE_DOMAIN}{SITEURL}/pages/{slug}.html" d = datetime.datetime( year=metadata['date'].year, month=metadata['date'].month, @@ -41,6 +45,19 @@ calendar.events.append(event) -with open(OUTPUT_ICS, "w", newline='') as f: - f.write("\n".join([line.replace('/ics.py/2020.1/', '') - for line in calendar.serialize().split(r"\n")])) +# Hints for subscribed clients. Not all of them honour these (Google ignores +# them), but Apple Calendar and Outlook do. RFC 5545 wants calendar properties +# before the components, so they are inserted right after the header instead of +# going through calendar.extra, which ics writes at the end of the file. +SUBSCRIPTION_HINTS = [ + "X-WR-CALNAME:Séminaires HPC@Maths", + "REFRESH-INTERVAL;VALUE=DURATION:PT6H", + "X-PUBLISHED-TTL:PT6H", +] + +lines = calendar.serialize().replace('/ics.py/2020.1/', '').splitlines() +header_end = lines.index("BEGIN:VTIMEZONE") +lines[header_end:header_end] = SUBSCRIPTION_HINTS + +with open(OUTPUT_ICS, "w", newline='', encoding="utf-8") as f: + f.write("\r\n".join(lines) + "\r\n") diff --git a/themes/hpc_math_theme/templates/events.html b/themes/hpc_math_theme/templates/events.html index 25f6486..4c94967 100644 --- a/themes/hpc_math_theme/templates/events.html +++ b/themes/hpc_math_theme/templates/events.html @@ -5,8 +5,12 @@
Cette page réunit toutes les informations concernant les événements promus par l'équipe.
Il est possible de s'abonner aux évènements via le lien {{ SITE_DOMAIN }}{{ + href="{{ SITE_DOMAIN|replace('https://', 'webcal://') }}{{ SITEURL }}/hpcmaths_seminars.ics">{{ SITE_DOMAIN }}{{ SITEURL }}/hpcmaths_seminars.ics
+Abonnez-vous à ce lien plutôt que d'importer le fichier : votre agenda + recevra alors automatiquement les nouveaux séminaires. Avec Google Agenda, utilisez + « Autres agendas > À partir de l'URL » et collez l'adresse ci-dessus. La mise à jour + peut prendre quelques heures.
{%for p in pages|sort(attribute='date', reverse=True) %} {% if p.category == 'event' %}