aboutsummaryrefslogtreecommitdiff
path: root/src/koszko_org_website/app.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/koszko_org_website/app.py')
-rw-r--r--src/koszko_org_website/app.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/koszko_org_website/app.py b/src/koszko_org_website/app.py
index e3e6339..84be22a 100644
--- a/src/koszko_org_website/app.py
+++ b/src/koszko_org_website/app.py
@@ -5,6 +5,7 @@
# Copyright (C) 2021, 2022 Wojtek Kosior
import gettext
+import re
import dataclasses as dc
import typing as t
@@ -38,6 +39,55 @@ def raise_exception(msg) -> t.NoReturn:
raise Exception(msg)
+post_titles_pl = {
+ 'gospel-despite-no-enthusiasm': 'Dobra Nowina pomimo zniechęcenia'
+}
+
+post_titles_en = {
+ 'gospel-despite-no-enthusiasm': 'Gospel despite lack of enthusiasm'
+}
+
+post_titles = {'en': post_titles_en, 'pl': post_titles_pl}
+
+@dc.dataclass(frozen=True)
+class PostData:
+ date: str
+ page_path: str
+ title: str
+
+ def __lt__(self, other: 'PostData') -> bool:
+ return (other.date, self.page_path) < (self.date, other.page_path)
+
+post_filename_re = re.compile(
+ r'''
+ ^
+ (?P<date>20[0-9][0-9]-[0-1][0-9]-[0-3][0-9])
+ -
+ (?P<post_identifier>.*)
+ \.html\.jinja
+ $
+ ''',
+ re.VERBOSE
+)
+
+def get_posts(lang: str) -> t.Sequence[PostData]:
+ lang_dir = here / 'templates' / lang
+ posts_data = []
+
+ for template_path in (lang_dir / 'posts').glob('20*'):
+ filename_match = post_filename_re.match(template_path.name)
+ assert filename_match is not None
+
+ date = filename_match.group('date')
+ post_identifier = filename_match.group('post_identifier')
+ page_path = f'posts/{date}-{post_identifier}.html'
+ title = post_titles[lang][post_identifier]
+
+ posts_data.append(PostData(date=date, page_path=page_path, title=title))
+
+ return sorted(posts_data)
+
+
@dc.dataclass(init=False)
class Website(flask.Flask):
def __init__(self) -> None:
@@ -56,6 +106,7 @@ class Website(flask.Flask):
}
self.jinja_env.globals['raise'] = raise_exception
+ self.jinja_env.globals['get_posts'] = get_posts
def koszko_install_translations(self, locale: str) -> None:
translations = gettext.translation(