Browse Source

Handle drafts (future dates)

master
David Larlet 4 years ago
parent
commit
a08ee5ec57
No known key found for this signature in database
2 changed files with 11 additions and 5 deletions
  1. 1
    1
      david/templates/article_2020.html
  2. 10
    4
      site.py

+ 1
- 1
david/templates/article_2020.html View File

<nav> <nav>
<a rel="prev" href="{{ prev.url }}" title="Publication précédente : {{ prev.title }}">←</a> • <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> <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> </nav>
<hr> <hr>
{{ page.content }} {{ page.content }}

+ 10
- 4
site.py View File

return self.date < other.date return self.date < other.date


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


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



@cli @cli
def fragment(title: str): def fragment(title: str):
def pages(): def pages():
"""Build the agregations from fragments.""" """Build the agregations from fragments."""
root_path = DAVID / "2020" root_path = DAVID / "2020"
page_list = Page.all(source=root_path)
for previous, page, next_ in neighborhood( 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") template = environment.get_template("article_2020.html")
content = template.render(page=page, next=previous, prev=next_,) content = template.render(page=page, next=previous, prev=next_,)
target_path.mkdir(parents=True, exist_ok=True) target_path.mkdir(parents=True, exist_ok=True)
open(target_path / "index.html", "w").write(content) open(target_path / "index.html", "w").write(content)
template = environment.get_template("archives_2020.html") 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) open(root_path / "index.html", "w").write(content)





Loading…
Cancel
Save