Commit 61b3d16d authored by berumuron's avatar berumuron
Browse files

imp: Improve site URL support

parents fa2f5f47 af29c5bb
......@@ -186,7 +186,29 @@ 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_`.
the article template, uppercased and prepended by `SITE_`. `url` can be set to
`filesystem` for development (it will generate paths to the output directory).
If you want to use a different configuration in development, you can specify
different options under a `development` section:
title: My website
author: Dale Cooper
timezone: Europe/Paris
url: filesystem
By default, `` command generates the website with production
configuration. To use the development one you should pass the `--development`
$ --development
You might find yourself limited by the article-only system. If you want to
create additional pages, just put HTML files under a `pages` folder. The
......@@ -8,6 +8,7 @@ import locale
import yaml
import datetime
import uuid
from enum import Enum
import markdown
import pytz
......@@ -19,6 +20,11 @@ import boopfeed
locale.setlocale(locale.LC_ALL, "")
class Environment(Enum):
class ProgramError(Exception):
"""Exception raised during the program execution.
......@@ -127,7 +133,7 @@ def mkdirs_for_file(filepath):
os.makedirs(path, exist_ok=True)
def main():
def main(environment):
# Make sure ./site folder is empty
output_path = os.path.join(os.curdir, "site")
if os.path.isdir(output_path):
......@@ -179,7 +185,7 @@ def main():
# Load the configuration (it can be overidden by a configuration.yml file)
configuration = {
"SITE_URL": "http://localhost",
"SITE_URL": "filesystem",
"SITE_TITLE": "A website",
......@@ -189,14 +195,23 @@ def main():
with open(configuration_path) as conf_file:
conf_data = yaml.load(conf_file)
for key, value in conf_data.items():
if key == "development":
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 = []
......@@ -276,8 +291,12 @@ def main():
if __name__ == "__main__":
environment = Environment.PRODUCTION
if len(sys.argv) == 2 and sys.argv[1] == "--development":
environment = Environment.DEVELOPMENT
except ProgramError as e:
print(e.args[0], file=sys.stderr)
Supports Markdown
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