Commit 207381f1 authored by berumuron's avatar berumuron
Browse files

Separate articles listing and writing

parent 9b4f622f
......@@ -30,7 +30,9 @@ class ProgramError(Exception):
class Article:
def __init__(self, article_content):
def __init__(self, slug, article_content):
self.slug = slug
# We convert the file's content into HTML
md = markdown.Markdown(extensions=["meta", "fenced_code", "attr_list"])
self.content = md.convert(article_content)
......@@ -98,21 +100,23 @@ def main():
# If not, just stop here
# And copy the files from ./articles to ./site
# List files from ./articles
articles = []
for filename in dir_tree(articles_path):
base, ext = os.path.splitext(filename)
slug, ext = os.path.splitext(filename)
if ext != ".md":
# Don't consider files which are not Markdown
article_filepath = os.path.join(articles_path, filename)
output_filepath = os.path.join(output_path, f"{base}.html")
# We read the article file and initialize an Article from it
article_filepath = os.path.join(articles_path, filename)
with open(article_filepath, "r") as article_file:
article = Article(
article = Article(slug,
# And we write the content in the output file
# And write them in the ./site folder
for article in articles:
output_filepath = os.path.join(output_path, f"{article.slug}.html")
with open(output_filepath, "w") as output_file:
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