Commit 4d969ab9 authored by berumuron's avatar berumuron
Browse files

Build blog page as the other pages

parent a9e8e816
...@@ -8,7 +8,6 @@ import datetime ...@@ -8,7 +8,6 @@ import datetime
import pytz import pytz
import boop.boopsy as boopsy
import boop.boopfeed as boopfeed import boop.boopfeed as boopfeed
import boop.environment as environment import boop.environment as environment
import boop.configuration as config import boop.configuration as config
...@@ -98,32 +97,26 @@ def main(environment): ...@@ -98,32 +97,26 @@ def main(environment):
if serie: if serie:
articles_by_series[serie].append(article) articles_by_series[serie].append(article)
# STEP 2: we write all the pages and articles
for page in pages:
utils.write_content(page, output_path)
print(f"Written page: {page.url()}")
# We want to sort the articles by publication date first # We want to sort the articles by publication date first
articles.sort(key=lambda article: article.date(), reverse=True) articles.sort(key=lambda article: article.date(), reverse=True)
for serie_articles in articles_by_series.values(): for serie_articles in articles_by_series.values():
serie_articles.sort(key=lambda article: article.date(), reverse=True) serie_articles.sort(key=lambda article: article.date(), reverse=True)
# 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):
blog_page = utils.build_blog_page(articles, configuration)
pages.append(blog_page)
# STEP 2: we write all the pages and articles
for page in pages:
utils.write_content(page, output_path)
print(f"Written page: {page.url()}")
for article in articles: for article in articles:
utils.write_content(article, output_path) utils.write_content(article, output_path)
print(f"Written article: {article.url()}") print(f"Written article: {article.url()}")
# Write the page with the list of articles if blog template exists
blog_template_filepath = os.path.join("templates", "blog.html")
if os.path.exists(blog_template_filepath):
blog_template = boopsy.Template(blog_template_filepath)
context = {}
context.update(configuration)
context["ARTICLES"] = articles
blog_output_filepath = os.path.join(output_path, f"blog.html")
with open(blog_output_filepath, "w") as output_file:
output_file.write(blog_template.render(context))
print(f"Written page: {configuration['SITE_URL']}blog.html")
# STEP 3: we write also the Atom feeds (the main one + the series'). # STEP 3: we write also the Atom feeds (the main one + the series').
# Just create some variables so it's easier to manipulate after # Just create some variables so it's easier to manipulate after
site_url = configuration["SITE_URL"] site_url = configuration["SITE_URL"]
......
...@@ -67,6 +67,13 @@ def build_page_from_filepath(filepath, configuration, basename=None, slug=None): ...@@ -67,6 +67,13 @@ 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):
blog_page = Page("blog", "", configuration=configuration)
blog_page.meta["PAGE_TEMPLATE"] = "blog"
blog_page.meta["ARTICLES"] = articles
return blog_page
templates_cache = {} templates_cache = {}
......
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