Commit 20af2ee3 authored by berumuron's avatar berumuron
Browse files

tec: Extract functions from main function

The main function begins to be a bit heavy, this first step only
extracts confusing code in named functions so they are a bit more clear.
parent 954e4051
......@@ -189,9 +189,9 @@ def mkdirs_for_file(filepath):
os.makedirs(path, exist_ok=True)
def main(environment):
# Make sure ./site folder is empty
output_path = os.path.join(os.curdir, "site")
def init_output_folder(output_path):
"""Create the output directory, empty it if it contains files.
"""
if os.path.isdir(output_path):
# it should be a directory...
shutil.rmtree(output_path)
......@@ -200,14 +200,14 @@ def main(environment):
os.remove(output_path)
os.mkdir(output_path)
# Load the configuration (it can be overidden by a configuration.yml file)
def load_configuration(configuration_path, output_path):
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)
......@@ -230,6 +230,18 @@ def main(environment):
if configuration["SITE_URL"] == "filesystem":
configuration["SITE_URL"] = f"file://{os.path.abspath(output_path)}/"
return configuration
def main(environment):
# Make sure ./site folder is empty
output_path = os.path.join(os.curdir, "site")
init_output_folder(output_path)
# Load the configuration (it can be overidden by a configuration.yml file)
configuration_path = os.path.join(os.curdir, "configuration.yml")
configuration = load_configuration(configuration_path, output_path)
# Check that index file exists and load a Page from it
index_filepath = os.path.join(os.curdir, "index.html")
if not os.path.exists(index_filepath):
......
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