-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.py
59 lines (48 loc) · 1.38 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import argparse
import os
from pathlib import Path
from staticjinja import Site
def get_context() -> dict[str, str]:
context = {}
prefix = "SJP_"
for key in os.environ.keys():
if key.startswith(prefix):
context[key.removeprefix(prefix).lower()] = os.environ[key]
return context
def main() -> None:
parser = argparse.ArgumentParser(
description="Render HTML pages from Jinja templates",
)
parser.add_argument(
"-w",
"--watch",
help="Render the site, and re-render on changes to <srcpath>",
action="store_true",
)
parser.add_argument(
"--srcpath",
help="The directory to look in for templates (defaults to './templates)'",
default=Path(".") / "templates",
type=Path,
)
parser.add_argument(
"--outpath",
help="The directory to place rendered files in (defaults to './build')",
default=Path(".") / "build",
type=Path,
)
args = parser.parse_args()
src_path = args.srcpath
output_path = args.outpath
static_path = Path(src_path) / "assets"
site = Site.make_site(
searchpath=src_path,
outpath=output_path,
staticpaths=[
str(static_path),
],
contexts=[(".*.html", get_context)],
)
site.render(use_reloader=args.watch)
if __name__ == '__main__':
main()