Commit 39c7a809 authored by Marien Fressinaud's avatar Marien Fressinaud

Accept a yaml configuration file

parent 96cd2873
...@@ -153,6 +153,19 @@ $ tree ...@@ -153,6 +153,19 @@ $ tree
└── index.html └── index.html
``` ```
Finally, you might want to create a `./configuration.yml` file. Four
information are used by the Atom feed, so you might want to declare them:
```yaml
url: http://my-website.org/
title: My website
author: Dale Cooper
timezone: Europe/Paris
```
You can declare as many variables as you want, they all will be accessible in
the article template, uppercased and prepended by `SITE_`.
## Tests ## Tests
There are some tests (i.e. doctests) that can be run to check that everything There are some tests (i.e. doctests) that can be run to check that everything
......
...@@ -5,6 +5,7 @@ import sys ...@@ -5,6 +5,7 @@ import sys
import shutil import shutil
import distutils.dir_util import distutils.dir_util
import locale import locale
import yaml
import markdown import markdown
...@@ -108,6 +109,24 @@ def main(): ...@@ -108,6 +109,24 @@ def main():
# If not, just stop here # If not, just stop here
return return
# Load the configuration (it can be overidden by a configuration.yml file)
configuration = {
"SITE_URL": "http://localhost",
"SITE_TITLE": "A website",
"SITE_TIMEZONE": "UTC",
}
configuration_path = os.path.join(os.curdir, "configuration.yml")
if os.path.exists(configuration_path):
with open(configuration_path) as conf_file:
conf_data = yaml.load(conf_file)
for key, value in conf_data.items():
site_key = f"SITE_{key.upper()}"
configuration[site_key] = value
if "SITE_AUTHOR" not in configuration:
configuration["SITE_AUTHOR"] = f"{configuration['SITE_TITLE']}'s author"
# List files from ./articles # List files from ./articles
articles = [] articles = []
for filename in dir_tree(articles_path): for filename in dir_tree(articles_path):
...@@ -119,7 +138,7 @@ def main(): ...@@ -119,7 +138,7 @@ def main():
# We read the article file and initialize an Article from it # We read the article file and initialize an Article from it
article_filepath = os.path.join(articles_path, filename) article_filepath = os.path.join(articles_path, filename)
with open(article_filepath, "r") as article_file: with open(article_filepath, "r") as article_file:
article = Article(slug, article_file.read()) article = Article(slug, article_file.read(), configuration=configuration)
articles.append(article) articles.append(article)
# And write them in the ./site folder # And write them in the ./site folder
......
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