-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake
executable file
·33 lines (27 loc) · 995 Bytes
/
make
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
#!/usr/bin/env python3
import os
ROOT = "root"
DOCS = "docs"
EXTRAS = "extras"
TEMPLATES = "templates"
def src_to_doc(path):
return DOCS + path[len(ROOT):]
def compile_page(in_file, out_file):
for line in in_file:
if line.strip().startswith("<!--- ") and line.endswith(" --->\n"):
template = line.strip()[6:-5]
with open(f"{TEMPLATES}/{template}", "r") as template_file:
compile_page(template_file, out_file)
else:
out_file.write(line)
def compile_dir(directory):
os.system(f"mkdir -p {src_to_doc(directory)}");
for file in os.scandir(directory):
if file.is_file() and not file.name.startswith("."):
with open(file.path, "r") as in_file, open(src_to_doc(file.path), "w") as out_file:
compile_page(in_file, out_file)
print(file.path)
elif file.is_dir():
compile_dir(file.path)
compile_dir(ROOT)
os.system(f"cp -r {EXTRAS}/* {DOCS}");