Commit f53dc7d3 authored by berumuron's avatar berumuron
Browse files

Load serie feeds while loading articles

parent 68d1df83
......@@ -41,7 +41,6 @@ def main(environment):
# STEP 1: we load all the Articles, Pages and Feeds
pages = []
articles = []
articles_by_series = {}
feeds = []
# Check that index file exists
......@@ -67,33 +66,44 @@ def main(environment):
# Check that articles directory exists and load Articles from it
articles_path = os.path.join(os.curdir, "articles")
if os.path.isdir(articles_path):
# We iterate on the directories of articles dir. If they contain
# "serie.html" file, it means they contain a serie. Otherwise, we list
# articles as usual.
dirs_with_articles = list(utils.list_dirs(articles_path)) + ["."]
for dirname in dirs_with_articles:
dirpath = os.path.realpath(os.path.join(articles_path, dirname))
serie_filepath = os.path.join(dirpath, "serie.html")
serie = None
# If the directory contains a `serie.html` file, it means it
# contains a serie so we load a page from it.
if dirname != "." and os.path.exists(serie_filepath):
# We have a serie Page! Each article of the directory must be
# considered part of the serie.
slug = f"serie/{dirname}"
serie = utils.build_page_from_filepath(
serie_filepath, configuration, slug=slug
)
pages.append(serie)
articles_by_series[serie] = []
# Let's collect all the articles from the directory
serie_articles = []
for filename in utils.list_files(dirpath, only=["md"]):
article_filepath = os.path.join(dirpath, filename)
article = utils.build_article_from_filepath(
article_filepath, configuration, serie
)
articles.append(article)
if serie:
articles_by_series[serie].append(article)
serie_articles.append(article)
# If the directory contains a serie and there is at least one
# article, we load a feed for the serie.
if serie and serie_articles:
feed_slug = f"feeds/{dirname}"
feed_title = f"{serie.title()} - {configuration['SITE_TITLE']}"
serie_feed = Feed(
feed_slug,
serie_articles,
{"title": feed_title, "site_link": serie.url()},
configuration=configuration,
)
feeds.append(serie_feed)
# Load a "blog" page which has access to the list of articles
blog_template_filepath = os.path.join("templates", "blog.html")
......@@ -101,27 +111,11 @@ def main(environment):
blog_page = utils.build_blog_page(articles, configuration)
pages.append(blog_page)
# And load the feeds
# And load the main feed
if len(articles) > 0:
# The main one...
feed = Feed("feeds/all", articles, configuration=configuration)
feeds.append(feed)
for serie, serie_articles in articles_by_series.items():
# And the series' ones
if len(serie_articles) == 0:
continue
slug = f"feeds/{os.path.basename(serie.slug())}"
feed_title = f"{serie.title()} - {configuration['SITE_TITLE']}"
feed = Feed(
slug,
serie_articles,
{"title": feed_title, "site_link": serie.url()},
configuration=configuration,
)
feeds.append(feed)
# STEP 2: we write all the pages, articles and feeds
for page in pages:
utils.write_content(page, output_path)
......@@ -131,12 +125,9 @@ def main(environment):
utils.write_content(article, output_path)
print(f"Written article: {article.url()}")
if len(feeds) > 0:
# If we have collected feeds (i.e. we have at least one article), we
# write them.
for feed in feeds:
utils.write_feed(feed, output_path)
print(f"Written feed: {feed.url()}")
for feed in feeds:
utils.write_feed(feed, output_path)
print(f"Written feed: {feed.url()}")
# STEP 3: and we finish by copying the static folder.
static_dirpath = os.path.join(os.curdir, "static")
......
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