-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·45 lines (40 loc) · 1.47 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
#!/usr/bin/env python
import markdown
import os
def main():
# TODO - move these to a config file
outputPath = "docs"
mdPath = "md-posts"
htmlPath = "posts"
skeletonPath = "skeletons"
# Generate html files from md files
with open(skeletonPath + "/post_preamble.html", "r") as pre:
start = pre.read()
with open(skeletonPath + "/post_postamble.html", "r") as post:
post = post.read()
# Generate an indexer for html entries
index = []
with os.scandir(path=mdPath) as it:
for entry in it:
if entry.name.endswith(".md"):
outputName = entry.name.replace(".md", ".html")
with open(entry, "r") as markfile:
out = markdown.markdown(markfile.read())
with open(
outputPath + "/" + htmlPath + "/" + outputName, "w"
) as outfile:
index.append(outputName)
outfile.write(start + out + post)
# create a basic starts page
with open(skeletonPath + "/index_preamble.html", "r") as pre:
start = pre.read()
start += "<ul>"
for i in index:
start += "<li> <a href='{}'> {} </a></li>".format(htmlPath + "/" + i, i)
start += "</ul>"
with open(skeletonPath + "/index_postamble.html", "r") as post:
start += post.read()
with open(outputPath + "/" + "index.html", "w") as indexfile:
indexfile.write(start)
if __name__ == "__main__":
main()