generated from caltechlibrary/template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path_build.py
60 lines (50 loc) · 1.91 KB
/
_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import shutil
import subprocess
import argparse
outDir = "site"
dummyDataDir = "dummy"
stylesDir = "styles"
scriptsDir = "scripts"
imagesDir = "img"
conditionsDir = "conditions"
def buildPage(page, template):
cmd = []
cmd.append("pandoc")
cmd.append("--from=markdown")
cmd.append("--to=html")
cmd.append(f"--output={outDir}/{page}.html")
cmd.append(f"--template=templates/{template}.html")
if (args.dummy): cmd.append(f"--metadata=dummy")
cmd.append(f"pages/{page}.md")
subprocess.run(cmd)
argParser = argparse.ArgumentParser()
argParser.add_argument("--dummy", action="store_true", help="set a flag to include dummy data")
args = argParser.parse_args()
# Create output site directory
if os.path.isdir(outDir): shutil.rmtree(outDir)
os.makedirs(outDir)
shutil.copytree(imagesDir, f"{outDir}/{imagesDir}")
shutil.copytree(stylesDir, f"{outDir}/{stylesDir}")
shutil.copytree(scriptsDir, f"{outDir}/{scriptsDir}")
shutil.copyfile("google9c66b3b3d14f628e.html", f"{outDir}/google9c66b3b3d14f628e.html")
shutil.copyfile("favicon.ico", f"{outDir}/favicon.ico")
# Do the same for phoenix
os.makedirs(f"{outDir}/phoenix")
os.makedirs(f"{outDir}/phoenix/about")
os.makedirs(f"{outDir}/phoenix/data")
os.makedirs(f"{outDir}/phoenix/faq")
shutil.copytree(f"templates/phoenix/{stylesDir}", f"{outDir}/phoenix/{stylesDir}")
if args.dummy: shutil.copytree("dummy", f"{outDir}/{dummyDataDir}")
buildPage("index", "index")
buildPage("aqi-data", "aqi-data")
buildPage("OZONE-data", "pollutant-data")
buildPage("PM2.5-data", "pollutant-data")
buildPage("PM10-data", "pollutant-data")
buildPage("CO-data", "pollutant-data")
buildPage("NO2-data", "pollutant-data")
buildPage("how-is-aqi-defined-here", "how-is-aqi-defined-here")
buildPage("phoenix/index", "phoenix/index")
buildPage("phoenix/about/index", "phoenix/about")
buildPage("phoenix/data/index", "phoenix/about")
buildPage("phoenix/faq/index", "phoenix/about")