Commit af29c5bb authored by Marien Fressinaud's avatar Marien Fressinaud

Add support for development section in configuration

parent 2fdeddef
......@@ -189,6 +189,27 @@ You can declare as many variables as you want, they all will be accessible in
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:
```yaml
url: http://my-website.org/
title: My website
author: Dale Cooper
timezone: Europe/Paris
development:
url: filesystem
```
By default, `boop.py` command generates the website with production
configuration. To use the development one you should pass the `--development`
argument:
```console
$ boop.py --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
directory structure will be preserved.
......
......@@ -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):
DEVELOPMENT = 1
PRODUCTION = 2
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):
......@@ -189,9 +195,16 @@ 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":
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"])
)
......@@ -278,8 +291,12 @@ def main():
if __name__ == "__main__":
environment = Environment.PRODUCTION
if len(sys.argv) == 2 and sys.argv[1] == "--development":
environment = Environment.DEVELOPMENT
try:
main()
main(environment)
print("Boop!")
except ProgramError as e:
print(e.args[0], file=sys.stderr)
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