Commit db113d6b authored by berumuron's avatar berumuron
Browse files

Give access to series in blog template

parent 0132472c
...@@ -389,6 +389,9 @@ feed obviously contains only the articles from the serie. You can also access ...@@ -389,6 +389,9 @@ 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 the serie object from the article template with `ARTICLE_SERIE`. The two most
interesting functions to use on this object are `title()` and `url()`. interesting functions to use on this object are `title()` and `url()`.
Series are accessible through the `blog` template with the `SERIES` variable. A
serie is just a basic page.
To finish, you can create a template specific to series. For that, you'll have 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 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 access to two additional variables: `ARTICLES` (such in the `blog` template but
......
...@@ -40,6 +40,7 @@ def main(environment): ...@@ -40,6 +40,7 @@ def main(environment):
# STEP 1: we load all the Articles, Pages and Feeds # STEP 1: we load all the Articles, Pages and Feeds
pages = [] pages = []
series = []
articles = [] articles = []
feeds = [] feeds = []
...@@ -80,7 +81,7 @@ def main(environment): ...@@ -80,7 +81,7 @@ def main(environment):
serie = utils.build_page_from_filepath( serie = utils.build_page_from_filepath(
serie_filepath, configuration, slug=slug serie_filepath, configuration, slug=slug
) )
pages.append(serie) series.append(serie)
# Let's collect all the articles from the directory # Let's collect all the articles from the directory
serie_articles = [] serie_articles = []
...@@ -112,7 +113,7 @@ def main(environment): ...@@ -112,7 +113,7 @@ def main(environment):
# Load a "blog" page which has access to the list of articles # Load a "blog" page which has access to the list of articles
blog_template_filepath = os.path.join("templates", "blog.html") blog_template_filepath = os.path.join("templates", "blog.html")
if os.path.exists(blog_template_filepath): if os.path.exists(blog_template_filepath):
blog_page = utils.build_blog_page(articles, configuration) blog_page = utils.build_blog_page(articles, series, configuration)
pages.append(blog_page) pages.append(blog_page)
# And load the main feed # And load the main feed
...@@ -121,7 +122,7 @@ def main(environment): ...@@ -121,7 +122,7 @@ def main(environment):
feeds.append(feed) feeds.append(feed)
# STEP 2: we write all the pages, articles and feeds # STEP 2: we write all the pages, articles and feeds
for page in pages: for page in pages + series:
utils.write_content(page, output_path) utils.write_content(page, output_path)
print(f"Written page: {page.url()}") print(f"Written page: {page.url()}")
......
...@@ -47,8 +47,9 @@ def build_page_from_filepath(filepath, configuration, basename=None, slug=None): ...@@ -47,8 +47,9 @@ def build_page_from_filepath(filepath, configuration, basename=None, slug=None):
return Page(final_slug, page_file.read(), configuration=configuration) return Page(final_slug, page_file.read(), configuration=configuration)
def build_blog_page(articles, configuration): def build_blog_page(articles, series, configuration):
articles.sort(key=lambda article: article.date(), reverse=True) articles.sort(key=lambda article: article.date(), reverse=True)
series.sort(key=lambda serie: serie.title(), reverse=False)
blog_page = Page("blog", "", configuration=configuration) blog_page = Page("blog", "", configuration=configuration)
blog_page.meta["PAGE_TEMPLATE"] = "blog" blog_page.meta["PAGE_TEMPLATE"] = "blog"
...@@ -56,6 +57,7 @@ def build_blog_page(articles, configuration): ...@@ -56,6 +57,7 @@ def build_blog_page(articles, configuration):
blog_page.meta["ARTICLES_BY_YEAR"] = itertools.groupby( blog_page.meta["ARTICLES_BY_YEAR"] = itertools.groupby(
articles, key=lambda article: article.date().year articles, key=lambda article: article.date().year
) )
blog_page.meta["SERIES"] = series
return blog_page return blog_page
......
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