aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-11-29 12:18:06 +0100
committerWojtek Kosior <koszko@koszko.org>2022-11-29 12:29:22 +0100
commit169d6925b6a246db528b69b67ef9a49b0a1ed474 (patch)
tree2dbba236f1cd5bc59e6915ba6260708ac6d9252f
parent9e46a15a271d81e802b7670f1123d7344a64903d (diff)
downloadkoszko-org-website-169d6925b6a246db528b69b67ef9a49b0a1ed474.tar.gz
koszko-org-website-169d6925b6a246db528b69b67ef9a49b0a1ed474.zip
list blog posts on koszko.html
-rw-r--r--src/koszko_org_website/app.py51
-rw-r--r--src/koszko_org_website/templates/en/koszko.html.jinja6
-rw-r--r--src/koszko_org_website/templates/koszko.html.jinja11
-rw-r--r--src/koszko_org_website/templates/pl/koszko.html.jinja6
4 files changed, 74 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(
diff --git a/src/koszko_org_website/templates/en/koszko.html.jinja b/src/koszko_org_website/templates/en/koszko.html.jinja
index ecf94dc..b6ce215 100644
--- a/src/koszko_org_website/templates/en/koszko.html.jinja
+++ b/src/koszko_org_website/templates/en/koszko.html.jinja
@@ -153,4 +153,10 @@ Copyright (C) 2021,2022 Wojtek Kosior <koszko@koszko.org>
{{ request_table() }}
{% endcall %}
+
+ {% call section('posts') %}
+ {{ header(2, 'Posts') }}
+
+ {{ posts() }}
+ {% endcall %}
{% endblock %}
diff --git a/src/koszko_org_website/templates/koszko.html.jinja b/src/koszko_org_website/templates/koszko.html.jinja
index 4253329..14b5bd5 100644
--- a/src/koszko_org_website/templates/koszko.html.jinja
+++ b/src/koszko_org_website/templates/koszko.html.jinja
@@ -64,3 +64,14 @@ Copyright (C) 2021,2022 Wojtek Kosior <koszko@koszko.org>
</tbody>
</table>
{% endmacro %}
+
+{% macro posts() %}
+ {% call unordered_list() %}
+ {% for post_data in get_posts(lang_short) %}
+ {% call list_entry() %}
+ {{ link(same_lang_url(post_data.page_path), post_data.title) }}
+ {{ italic('(' ~ post_data.date ~ ')') }}
+ {% endcall %}
+ {% endfor %}
+ {% endcall %}
+{% endmacro %}
diff --git a/src/koszko_org_website/templates/pl/koszko.html.jinja b/src/koszko_org_website/templates/pl/koszko.html.jinja
index 7828c4a..6dae783 100644
--- a/src/koszko_org_website/templates/pl/koszko.html.jinja
+++ b/src/koszko_org_website/templates/pl/koszko.html.jinja
@@ -159,4 +159,10 @@ Copyright (C) 2021,2022 Wojtek Kosior <koszko@koszko.org>
{{ request_table() }}
{% endcall %}
+
+ {% call section('posts') %}
+ {{ header(2, 'Posty') }}
+
+ {{ posts() }}
+ {% endcall %}
{% endblock %}