Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deploy site to GitHub Pages

on:
push:
branches: [master]
branches: [main]
pull_request:
workflow_dispatch:

Expand Down
29 changes: 23 additions & 6 deletions ics_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
6 changes: 5 additions & 1 deletion themes/hpc_math_theme/templates/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ <h1 class="page_title">Événements</h1>
<p class="well">Cette page réunit toutes les informations concernant les
événements promus par l'équipe.</p>
<p>Il est possible de s'abonner aux évènements via le lien <a
href="{{ SITEURL }}/hpcmaths_seminars.ics">{{ SITE_DOMAIN }}{{
href="{{ SITE_DOMAIN|replace('https://', 'webcal://') }}{{ SITEURL }}/hpcmaths_seminars.ics">{{ SITE_DOMAIN }}{{
SITEURL }}/hpcmaths_seminars.ics <i class="bi bi-calendar2-week"></i></a></p>
<p class="text-muted small">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 &gt; À partir de l'URL » et collez l'adresse ci-dessus. La mise à jour
peut prendre quelques heures.</p>

{%for p in pages|sort(attribute='date', reverse=True) %}
{% if p.category == 'event' %}
Expand Down
Loading