Commit 9a2c6459 authored by berumuron's avatar berumuron
Browse files

Extract function to build an article from filepath

parent e3c382ae
......@@ -180,6 +180,17 @@ def extract_yaml_configuration(content):
return {}, content
def build_article_from_filepath(filepath, configuration, serie=None):
"""Read a file and initialize an Article from it.
"""
filepath_no_ext, _ = os.path.splitext(filepath)
slug = os.path.basename(filepath_no_ext)
with open(filepath, "r") as article_file:
return Article(
slug, article_file.read(), configuration=configuration, serie=serie
)
def list_dirs(path):
"""List all the directories within a path.
"""
......@@ -335,32 +346,18 @@ def main(environment):
articles_by_series[serie] = []
for filename in list_files(dirpath, only=["md"]):
# We read the article file and initialize an Article from it
filename_no_ext, _ = os.path.splitext(filename)
slug = os.path.basename(filename_no_ext)
article_filepath = os.path.join(dirpath, filename)
with open(article_filepath, "r") as article_file:
article = Article(
slug,
article_file.read(),
configuration=configuration,
serie=serie,
)
articles.append(article)
if serie:
articles_by_series[serie].append(article)
article = build_article_from_filepath(
article_filepath, configuration, serie
)
articles.append(article)
if serie:
articles_by_series[serie].append(article)
for filename in list_files(articles_path, only=["md"]):
# We read the article file and initialize an Article from it
filename_no_ext, _ = os.path.splitext(filename)
slug = os.path.basename(filename_no_ext)
article_filepath = os.path.join(articles_path, filename)
with open(article_filepath, "r") as article_file:
article = Article(
slug, article_file.read(), configuration=configuration
)
articles.append(article)
article = build_article_from_filepath(article_filepath, configuration)
articles.append(article)
# STEP 2: we write all the pages and articles
for page in pages:
......
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