Browse Source

Move links to config and pass to renderer, remove broken watch argument and fix build/serve command.

develop
Sam Black 3 years ago
parent
commit
0bac8e35c6
  1. 4
      README.rst
  2. 40
      build.py
  3. 5
      templates/_menu.html
  4. 5
      templates/index.html

4
README.rst

@ -1,5 +1,5 @@
Lapwing.Org/website
==================
===================
About
-----
@ -20,7 +20,7 @@ Email Sam Black: samwwwblack AT lapwing DOT org
Licence
-------
(c) Copyright Sam Black 2012, 2017.
(c) Copyright Sam Black 2012, 2017, 2018.
Most code is licensed under the AGPL3.

40
build.py

@ -44,11 +44,24 @@ config = {
"name": "Lapwing.Org",
"email": "contact@lapwing.org",
},
"menu": (
("Blog", "https://samwwwblack.lapwing.org"),
("Code", "https://code.lapwing.org")
),
"projects": (
("Vowel", "Virtual Online Workspace for Education and Learning.",
"https://code.lapwing.org/vowel/vowel"),
("Sponson",
"Sponson is a tool to create and setup systemd-nspawn containers in "
"a Docker-like way, without using Docker.",
"https://code.lapwing.org/devops/sponson"),
),
"output": os.path.join(pwd, "build", "html"),
"templates": os.path.join(pwd, "templates"),
"assets": os.path.join(pwd, "assets"),
"asset_cache": os.path.join(pwd, "build", "webassets-cache")
}
paths = ["output", "templates", "assets", "asset_cache"]
def generate_assets(assets_path, output_path, debug=False):
@ -110,20 +123,18 @@ def safe_copy(src, dest):
shutil.copy2(src, dest)
def build_website(minimize=False, watch=False, lock=None):
def build_website(minimize=False, lock=None):
"""
Build website.
:param minimize: minimize the CSS, JS or other assets.
:type minimize: bool
:param watch: re-run renderer if templates change
:type watch: bool
:param lock: multiprocessing lock
:type lock: multiprocessing.Lock or None
"""
# If the paths aren't absolute, bail.
for path_name, path in config.items():
if path_name == "site":
if path_name not in paths:
continue
if not os.path.isabs(path):
raise Exception("Path for '{}' is not absolute".format(path_name))
@ -161,7 +172,9 @@ def build_website(minimize=False, watch=False, lock=None):
env_globals = {
"site_name": config["site"]["name"],
"site_email": config["site"]["email"],
"current_year": datetime.now().strftime("%Y")
"current_year": datetime.now().strftime("%Y"),
"menu": config["menu"],
"projects": config["projects"]
}
renderer = staticjinja.make_site(config["templates"], config["output"],
@ -170,7 +183,7 @@ def build_website(minimize=False, watch=False, lock=None):
renderer._env.assets_environment = webassets_env
renderer._env.globals.update(env_globals)
renderer.render(watch)
renderer.render()
def run_server(lock=None):
@ -191,8 +204,8 @@ def run_server(lock=None):
os.chdir("build/html")
httpd = HTTPServer(("", 8000), SimpleHTTPRequestHandler)
httpd.serve_forever()
logger.info("Serving website: http://127.0.0.1:8000")
httpd.serve_forever()
@click.group()
@ -218,25 +231,18 @@ def build(minimize):
@cli.command()
@click.option("--watch", is_flag=True, default=False,
help="watch for template changes and re run renderer")
@click.option("--minimize", is_flag=True, default=False,
help="minimize the CSS, JS and other assets.")
def serve(watch, minimize):
def serve(minimize):
"""
Build website and run a "http.server" instance in the output directory.
:param watch: re-render HTML output if templates change
:type watch: bool
:param minimize: minimize CSS/JS output
:type minimize: bool
"""
if watch:
lock = Lock()
else:
lock = None, None
lock = Lock()
build_proc = Process(target=build_website, args=(minimize, watch, lock))
build_proc = Process(target=build_website, args=(minimize, lock))
serve_proc = Process(target=run_server, args=(lock,))
build_proc.start()
serve_proc.start()

5
templates/_menu.html

@ -1,8 +1,3 @@
{% set menu = (
("Blog", "https://samwwwblack.lapwing.org"),
("Code", "https://code.lapwing.org")
) %}
<div class="uk-navbar-container">
<div class="uk-container">
<nav data-uk-navbar>

5
templates/index.html

@ -1,9 +1,4 @@
{% extends "_base.html" %}
{% set projects = (
("Vowel", "Virtual Online Workspace for Education and Learning.", "https://code.lapwing.org/vowel/vowel"),
("Sponson", "Sponson is a tool to create and setup systemd-nspawn containers in a Docker-like way, without using Docker.",
"https://code.lapwing.org/devops/sponson"),
) %}
{% block page_content %}
<div class="uk-section uk-section-primary">

Loading…
Cancel
Save