浏览代码

Handle drafts (future dates)

master
David Larlet 4 年前
父节点
当前提交
a08ee5ec57
找不到此签名对应的密钥
共有 2 个文件被更改,包括 11 次插入5 次删除
  1. 1
    1
      david/templates/article_2020.html
  2. 10
    4
      site.py

+ 1
- 1
david/templates/article_2020.html 查看文件

@@ -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 查看文件

@@ -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)



正在加载...
取消
保存