summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@gmail.com>2022-07-09 15:18:29 +0200
committerKévin Le Gouguec <kevin.legouguec@gmail.com>2022-07-09 15:18:29 +0200
commit8efb5b6772282e11e212edf67c8befe22ea8c06f (patch)
tree2a29179a85698973fe2724ce9fc601ca96a4f944
parent1dd8b8f4e036d2ef10a2504df1a281966f454b04 (diff)
downloadquatuorbellefeuille.com-8efb5b6772282e11e212edf67c8befe22ea8c06f.tar.xz
Add plumbing to update next concert on the frontpage
-rw-r--r--Makefile5
-rwxr-xr-xadmin/build-indexes.sh15
-rwxr-xr-xadmin/update-index.py51
-rwxr-xr-xbuild-concerts.py12
-rw-r--r--helpers.py11
5 files changed, 82 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index ca01374..05616cd 100644
--- a/Makefile
+++ b/Makefile
@@ -40,7 +40,7 @@ scripts_folders = $(call dirnames,$(scripts))
.PHONY: all clean site
# Maintenance:
-.PHONY: feeds upload
+.PHONY: feeds indexes upload
#################### Recipes.
@@ -49,6 +49,9 @@ all: site
feeds:
./admin/feeds/build-feeds.sh $(feeds_src)
+indexes:
+ ./admin/build-indexes.sh . $(languages)
+
upload: site
./upload.sh $(OUTDIR)
diff --git a/admin/build-indexes.sh b/admin/build-indexes.sh
new file mode 100755
index 0000000..9dcbda7
--- /dev/null
+++ b/admin/build-indexes.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+set -eu
+
+HERE=$(dirname "$0")
+ROOT=${HERE}/..
+
+for directory
+do
+ concert="${directory}"/concerts.in
+ index="${directory}"/index.html
+
+ PYTHONPATH="${ROOT}" \
+ "${HERE}"/update-index.py "${concert}" "${index}"
+done
diff --git a/admin/update-index.py b/admin/update-index.py
new file mode 100755
index 0000000..5946433
--- /dev/null
+++ b/admin/update-index.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python3
+
+from datetime import datetime
+from sys import argv
+
+from helpers import (
+ guess_language,
+ read_concerts,
+ split_concerts,
+ tmplocale,
+)
+
+
+CALENDAR_LAYOUT = {
+ 'en': '<span id="month">%B</span><br><span id="day">%d</span>',
+ 'fr': '<span id="day">%d</span><br><span id="month">%B</span>',
+}
+
+INDEX_TEMPLATE = '''\
+<main>
+ <a id="next-concert" href="concerts.html#concert-%F">
+ <p>
+ {CALENDAR}
+ </p>
+ </a>
+</main>
+'''
+
+
+def main(concerts_src, index_dst):
+ today = datetime.fromordinal(
+ datetime.today().date().toordinal()
+ )
+ past_concerts, next_concerts = split_concerts(
+ read_concerts(concerts_src), today
+ )
+
+ concert = next_concerts[0] if next_concerts else past_concerts[-1]
+
+ lang = guess_language(concerts_src)
+ template = INDEX_TEMPLATE.format(CALENDAR=CALENDAR_LAYOUT[lang])
+
+ with tmplocale(lang):
+ index = concert.time.strftime(template)
+
+ with open(index_dst, 'w') as index_file:
+ index_file.write(index)
+
+
+if __name__ == '__main__':
+ main(*argv[1:])
diff --git a/build-concerts.py b/build-concerts.py
index 6e99673..ed37864 100755
--- a/build-concerts.py
+++ b/build-concerts.py
@@ -9,6 +9,7 @@ from helpers import (
guess_language,
read_concerts,
relative_path,
+ split_concerts,
tmplocale,
touchup_plaintext,
)
@@ -19,17 +20,6 @@ from helpers import (
# - canceled => warning
-def split_concerts(concerts, threshold):
- cutoff = len(concerts)
-
- for i, c in enumerate(concerts):
- if c.time > threshold:
- cutoff = i
- break
-
- return reversed(concerts[:cutoff]), concerts[cutoff:]
-
-
LOCALIZED_TEXT = {
'en': {
'past': 'Past concerts',
diff --git a/helpers.py b/helpers.py
index e3ce938..e5c089f 100644
--- a/helpers.py
+++ b/helpers.py
@@ -135,6 +135,17 @@ def read_concerts(filename):
return tuple(sorted(concerts, key=attrgetter('time')))
+def split_concerts(concerts, threshold):
+ cutoff = len(concerts)
+
+ for i, c in enumerate(concerts):
+ if c.time > threshold:
+ cutoff = i
+ break
+
+ return reversed(concerts[:cutoff]), concerts[cutoff:]
+
+
_TOUCHUPS = (
(re.compile('([0-9])(st|nd|rd|th|er|ère|nde|ème)'), r'\1<sup>\2</sup>'),
(re.compile('<(https?://[^ ]+)>'), r'<a href="\1" target="_blank">\1</a>'),