Commit 0132472c authored by berumuron's avatar berumuron
Browse files

Add articles and feed to the serie template

parent f53dc7d3
......@@ -389,9 +389,12 @@ feed obviously contains only the articles from the serie. You can also access
the serie object from the article template with `ARTICLE_SERIE`. The two most
interesting functions to use on this object are `title()` and `url()`.
Please note for the moment, you cannot access the list of serie's articles in
the `page` template nor from the `ARTICLE_SERIE` object so you'll have to
create the links to the articles manually.
To finish, you can create a template specific to series. For that, you'll have
to set a `template: serie` variable in your `serie.html` files. The series have
access to two additional variables: `ARTICLES` (such in the `blog` template but
they are sorted from the older to the newer) and `FEED` which represent the
Atom feed associated to your serie. You can call `FEED.url()` to create a link
to your feed.
## Template syntax
......
......@@ -93,7 +93,8 @@ def main(environment):
serie_articles.append(article)
# If the directory contains a serie and there is at least one
# article, we load a feed for the serie.
# article, we load a feed for the serie and we let know the serie
# about its articles and feed.
if serie and serie_articles:
feed_slug = f"feeds/{dirname}"
feed_title = f"{serie.title()} - {configuration['SITE_TITLE']}"
......@@ -105,6 +106,9 @@ def main(environment):
)
feeds.append(serie_feed)
serie.set_articles(serie_articles)
serie.set_feed(serie_feed)
# Load a "blog" page which has access to the list of articles
blog_template_filepath = os.path.join("templates", "blog.html")
if os.path.exists(blog_template_filepath):
......
......@@ -36,6 +36,13 @@ class Page:
def template(self):
return self.meta["PAGE_TEMPLATE"]
def set_articles(self, articles):
articles.sort(key=lambda article: article.date(), reverse=False)
self.meta["ARTICLES"] = articles
def set_feed(self, feed):
self.meta["FEED"] = feed
YAML_FRONT_MATTER_REGEX = re.compile("(---\n.*\n)(---\n)(.*)", re.M | re.S)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment