-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhead_adder.py
More file actions
57 lines (48 loc) · 1.7 KB
/
Copy pathhead_adder.py
File metadata and controls
57 lines (48 loc) · 1.7 KB
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
#!/usr/local/bin/python
import argparse
import os
import os.path
import shutil
from sys import argv, exit, stderr
def add_headers(path, case):
for f in os.listdir(path):
print "updating header in file %s" % f
infile = open(os.path.join(path, f)).read()
if case == "jekyll":
infile = "---\n" + \
"layout: default\n" + \
"title:\n" + \
"---\n" + \
"\n" + \
infile
elif case == "hyde":
infile = "---\n" + \
"title: \n" + \
"subtitle: \n" + \
"description: \n" + \
"---\n" + \
"\n" + \
"{% extends \"topbar.j2\" %}\n" + \
"\n" + \
"{% block container %}" + \
infile + \
"\n{% endblock container %}" + \
"\n"
outfile = open(os.path.join(path, f), "w")
outfile.write(infile)
outfile.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="addes jekyll or hyde headers to all the pages")
parser.add_argument("path", help="folder containing html (raw) files")
parser.add_argument("case", help="hyde or jekyll")
args = parser.parse_args()
if not os.path.exists(args.path):
stderr.write("folder %s not found." % args.path)
exit()
if args.case not in ("jekyll","hyde"):
stderr.write("type must be either \"jekyll\" or \"hyde\"")
exit()
if add_headers(args.path, args.case):
print "Error"
else:
print "Done"