moldu

Python script using Flask to generate a simple ssg
Log | Files | Refs

commit 3d22d194c7ef66e53f7bbb1c5fa7b9b17734ce43
parent 3f3992255f574cebf22fcc73d67cc104f5e3bf74
Author: Justin Bridouz <justin.bridouz@zaclys.net>
Date:   Thu, 19 Sep 2019 10:54:26 +0200

add section archives, rework layout

Diffstat:
moldu.py | 30++++++++++++++++++++++++++++--
static/css/style.css | 3++-
templates/_list.html | 13+++++++++----
templates/archives.html | 13++-----------
templates/base.html | 2++
templates/index.html | 9++++++++-
templates/tag.html | 4+---
7 files changed, 52 insertions(+), 22 deletions(-)

diff --git a/moldu.py b/moldu.py @@ -46,6 +46,11 @@ def to_rfc2822(dt): def inject_now(): return {'now': datetime.datetime.now().strftime("%d/%m/%Y %H:%M")} +def get_years(pages): + years = list(set([page.meta.get('date').year for page in pages])) + years.reverse() + return years + @app.route('/') def index(): posts = [page for page in pages if "date" in page.meta] @@ -57,14 +62,35 @@ def index(): def tag(tag): tagged = [p for p in pages if tag in p.meta.get('tags', [])] hpages = [page for page in pages if "date" not in page.meta] - return render_template('tag.html', pages=tagged, tag=tag, hpages=hpages) + years = get_years(tagged) + return render_template('tag.html', pages=tagged, tag=tag, hpages=hpages, years = years) @app.route('/archives/') def archives(): posts = [page for page in pages if "date" in page.meta] latest = sorted(posts, reverse=True, key=lambda p: p.meta['date']) hpages = [page for page in pages if "date" not in page.meta] - return render_template('archives.html', pages=latest, hpages=hpages) + years = get_years(posts) + archives_title = "Archives" + return render_template('archives.html', pages=latest, hpages=hpages, years = years, archives_title = archives_title) + +@app.route('/blog/') +def blog_archives(): + posts = [page for page in pages if page.path.startswith("blog")] + latest = sorted(posts, reverse=True, key=lambda p: p.meta['date']) + hpages = [page for page in pages if "date" not in page.meta] + years = get_years(posts) + archives_title = "Blog" + return render_template('archives.html', pages=latest, hpages=hpages, years = years, archives_title = archives_title) + +@app.route('/notes/') +def notes_archives(): + posts = [page for page in pages if page.path.startswith("notes")] + latest = sorted(posts, reverse=True, key=lambda p: p.meta['date']) + hpages = [page for page in pages if "date" not in page.meta] + years = get_years(posts) + archives_title = "Notes" + return render_template('archives.html', pages=latest, hpages=hpages, years = years, archives_title = archives_title) @app.route("/<path:path>/") def page(path): diff --git a/static/css/style.css b/static/css/style.css @@ -1,6 +1,6 @@ html { background: #f2f2f2; - color: #2e3440; + color: #4a4a4a; } body { @@ -53,6 +53,7 @@ code { } time { + display: inline-block; padding-right: 1ch; font-style: italic; color: #da4453; diff --git a/templates/_list.html b/templates/_list.html @@ -1,10 +1,15 @@ +{% for year in years %} +<h2>{{ year }}</h2> +{% with pages=pages %} <ul> {% for page in pages %} - <li> - <time datetime="{{ page.date|to_rfc2822 }}">{{ page.date|date('%d %B %Y') }}</time> +{% if page.date.year == year %} + <li> + <time datetime="{{ page.date|to_rfc2822 }}" style="width: 3rem;">{{ page.date|date('%d %b') }}</time> <a href="{{ url_for("page", path=page.path) }}">{{ page.title }}</a> </li> -{% else %} - <li>No page.</li> +{% endif %} {% endfor %} +{% endwith %} </ul> +{% endfor %} diff --git a/templates/archives.html b/templates/archives.html @@ -2,20 +2,11 @@ {% block content %} <header> - <h1>Archives<h1> + <h1>{{ archives_title }}<h1> </header> <article> <input type="text" id="archivefilter" onkeyup="FilterArchive()" placeholder="?" autofocus> - {% with pages=pages %} - <ul> -{% for page in pages %} - <li> - <time datetime="{{ page.date|to_rfc2822 }}">{{ page.date|date('%d %b %Y') }}</time> - <a href="{{ url_for("page", path=page.path) }}">{{ page.title }}</a> - </li> -{% endfor %} - - {% endwith %} + {% include "_list.html" %} </article> {% endblock content %} diff --git a/templates/base.html b/templates/base.html @@ -12,6 +12,8 @@ <nav> <a href="{{ url_for("index") }}">~/</a> · <a href="{{ url_for("archives") }}">Archives</a> · + <a href="{{ url_for("blog_archives") }}">Blog</a> · + <a href="{{ url_for("notes_archives") }}">Notes</a> · <a href="{{ url_for("feed") }}">Rss</a> · {% for page in hpages %} <a href="{{ url_for("page", path=page.path)}}"> diff --git a/templates/index.html b/templates/index.html @@ -11,7 +11,14 @@ <p>Bonne visite et, si cela te plaît, il est possible de venir me déposer un petit truc sur ma <a href="/mysterybox"><code>Mystery Box</code></a>.</p> <h2>Derniers billets</h2> {% with pages=pages %} - {% include "_list.html" %} + <ul> +{% for page in pages %} + <li> + <time datetime="{{ page.date|to_rfc2822 }}" style="width: 8rem;">{{ page.date|date('%d %B %Y') }}</time> + <a href="{{ url_for("page", path=page.path) }}">{{ page.title }}</a> + </li> + {% endfor %} + </ul> {% endwith %} </article> {% endblock content %} diff --git a/templates/tag.html b/templates/tag.html @@ -5,8 +5,6 @@ <h1>List of stuff tagged <em>{{ tag }}</em></h1> </header> <article> - {% with pages=pages %} - {% include "_list.html" %} - {% endwith %} + {% include "_list.html" %} </article> {% endblock content %}