forked from ansible/docsite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
45 lines (31 loc) · 952 Bytes
/
build.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
import shutil
import sys
from pathlib import Path
from staticjinja import Site
from yaml import Loader, load
import sass
def load_page_data():
yaml = Path("./data").glob("*.yaml")
return {
file_path.stem: load(file_path.read_text(), Loader=Loader) for file_path in yaml
}
def clean_buildpath(output_dir):
shutil.rmtree(output_dir, ignore_errors=True)
def main():
try:
build_dir_str = sys.argv[1]
except IndexError:
build_dir_str = "output"
buildpath = Path(build_dir_str)
clean_buildpath(buildpath)
site = Site.make_site()
site.outpath = buildpath
site.contexts = [(".*.html", load_page_data)]
# disable automatic reloading
site.render(use_reloader=False)
# copy the static folder
shutil.copytree("static", buildpath / "static")
# compile sass to css
sass.compile(dirname=("sass", buildpath / "static/css"))
if __name__ == "__main__":
main()