Skip to content
Open
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
30 changes: 26 additions & 4 deletions blag/blag.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,39 @@ def process_markdown(
# everything else are just pages
if meta and "date" in meta:
articles.append((dst, context))
result = article_template.render(context)
# articles will be rendered after sorting,
# to add next&prev metadata
else:
pages.append((dst, context))
# we are can already render pages (no sorting needed)
result = page_template.render(context)
with open(f"{output_dir}/{dst}", "w") as fh_dest:
fh_dest.write(result)
with open(f"{output_dir}/{dst}", "w") as fh_dest:
fh_dest.write(result)

# sort articles by date, descending
articles = sorted(articles, key=lambda x: x[1]["date"], reverse=True)
return articles, pages

# with the sorted list of articles
# add metadata for previous and next pages
for i in range(0,len(articles)):

if (i>0):
articles[i][1]["prv"]="/" + articles[i-1][0]
else:
articles[i][1]["prv"]="/"

if (i<(len(articles)-1)):
articles[i][1]["nxt"]="/" + articles[i+1][0]
else:
articles[i][1]["nxt"]="/"

# generate articles html files
result = article_template.render(articles[i][1])
dst=articles[i][0]
with open(f"{output_dir}/{dst}", "w") as fh_dest:
fh_dest.write(result)

return articles, pages

def generate_feed(
articles: list[tuple[str, dict[str, Any]]],
Expand Down
22 changes: 22 additions & 0 deletions blag/templates/article.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

{% block content %}

{% if prv or nxt %}
<header><nav><ul>
{% if prv %}
<li><h2><a href="{{ prv }}">zurück</a><h2></li>
{% endif %}
{% if nxt %}
<li><h2><a href="{{ nxt }}">weiter</a><h2></li>
{% endif %}
</ul></nav></header>
{% endif %}

{% if title %}
<h2>{{ title }}</h2>
{% endif %}
Expand All @@ -24,4 +35,15 @@ <h2>{{ title }}</h2>

{{ content }}

{% if prv or nxt %}
<header><nav><ul>
{% if prv %}
<li><h2><a href="{{ prv }}">zurück</a><h2></li>
{% endif %}
{% if nxt %}
<li><h2><a href="{{ nxt }}">weiter</a><h2></li>
{% endif %}
</ul></nav></header>
{% endif %}

{% endblock %}