Commit 3f235329 authored by Marien Fressinaud's avatar Marien Fressinaud

Load configuration at the beginning

parent 61b3d16d
......@@ -144,6 +144,36 @@ def main(environment):
os.remove(output_path)
os.mkdir(output_path)
# Load the configuration (it can be overidden by a configuration.yml file)
configuration = {
"SITE_URL": "filesystem",
"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():
if key == "development":
continue
site_key = f"SITE_{key.upper()}"
configuration[site_key] = value
if environment == Environment.DEVELOPMENT and "development" in conf_data:
for key, value in conf_data["development"].items():
site_key = f"SITE_{key.upper()}"
configuration[site_key] = value
configuration["SITE_UUID"] = str(
uuid.uuid5(uuid.NAMESPACE_URL, configuration["SITE_URL"])
)
if "SITE_AUTHOR" not in configuration:
configuration["SITE_AUTHOR"] = f"{configuration['SITE_TITLE']}'s author"
if configuration["SITE_URL"] == "filesystem":
configuration["SITE_URL"] = f"file://{os.path.abspath(output_path)}/"
# Check that index file exists and copy it under the ./site folder
index_filepath = os.path.join(os.curdir, "index.html")
if not os.path.exists(index_filepath):
......@@ -183,36 +213,6 @@ def main(environment):
# If not, just stop here
return
# Load the configuration (it can be overidden by a configuration.yml file)
configuration = {
"SITE_URL": "filesystem",
"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():
if key == "development":
continue
site_key = f"SITE_{key.upper()}"
configuration[site_key] = value
if environment == Environment.DEVELOPMENT and "development" in conf_data:
for key, value in conf_data["development"].items():
site_key = f"SITE_{key.upper()}"
configuration[site_key] = value
configuration["SITE_UUID"] = str(
uuid.uuid5(uuid.NAMESPACE_URL, configuration["SITE_URL"])
)
if "SITE_AUTHOR" not in configuration:
configuration["SITE_AUTHOR"] = f"{configuration['SITE_TITLE']}'s author"
if configuration["SITE_URL"] == "filesystem":
configuration["SITE_URL"] = f"file://{os.path.abspath(output_path)}/"
# List files from ./articles
articles = []
for filename in dir_tree(articles_path):
......
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