Bläddra i källkod

Handle drafts (future dates)

master
David Larlet 4 år sedan
förälder
incheckning
a08ee5ec57
Ingen känd nyckel hittad för denna signaturen i databasen
2 ändrade filer med 11 tillägg och 5 borttagningar
  1. 1
    1
      david/templates/article_2020.html
  2. 10
    4
      site.py

+ 1
- 1
david/templates/article_2020.html Visa fil

@@ -7,7 +7,7 @@
<nav>
<a rel="prev" href="{{ prev.url }}" title="Publication précédente : {{ prev.title }}">←</a> •
<a href="/david/2020/" title="Liste des publications récentes">↑</a>
{% if next %} • <a rel="next" href="{{ next.url }}" title="Publication suivante : {{ next.title }}">→</a>{% endif %}
{% if next and not next.is_draft %} • <a rel="next" href="{{ next.url }}" title="Publication suivante : {{ next.title }}">→</a>{% endif %}
</nav>
<hr>
{{ page.content }}

+ 10
- 4
site.py Visa fil

@@ -99,7 +99,7 @@ class Page:
return self.date < other.date

@staticmethod
def all(source: Path):
def all(source: Path, only_published=True):
"""Retrieve all pages sorted by desc."""
page_list = []
for file_path in each_markdown_from(source):
@@ -108,9 +108,15 @@ class Page:
h1_opening_size = len("<h1>")
title = title[h1_opening_size:]
page = Page(title, content, file_path)
if only_published and page.is_draft:
continue
page_list.append(page)
return sorted(page_list, reverse=True)

@property
def is_draft(self):
return self.date > date.today()


@cli
def fragment(title: str):
@@ -124,9 +130,9 @@ def fragment(title: str):
def pages():
"""Build the agregations from fragments."""
root_path = DAVID / "2020"
page_list = Page.all(source=root_path)
for previous, page, next_ in neighborhood(
page_list, last={"url": "/david/stream/", "title": "Streams 2009-2019"}
Page.all(source=root_path, only_published=False),
last={"url": "/david/stream/", "title": "Streams 2009-2019"},
):
template = environment.get_template("article_2020.html")
content = template.render(page=page, next=previous, prev=next_,)
@@ -134,7 +140,7 @@ def pages():
target_path.mkdir(parents=True, exist_ok=True)
open(target_path / "index.html", "w").write(content)
template = environment.get_template("archives_2020.html")
content = template.render(page_list=page_list)
content = template.render(page_list=Page.all(source=root_path))
open(root_path / "index.html", "w").write(content)



Laddar…
Avbryt
Spara