-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_pdf.py
38 lines (26 loc) · 1012 Bytes
/
generate_pdf.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
import os
PDF_DIR = "_pdf/"
def main():
walk_directories()
def walk_directories():
markdown_files = {}
# Walk through all available files
for root, dirs, files in os.walk(".", topdown = False):
for name in files:
# We grab the markdown filepaths
if name != "README.md" and name.endswith(".md"):
markdown_files[name] = os.path.join(root, name)
# We update the markdowns with the appropriate metadata
convert_md_to_pdf(markdown_files)
def convert_md_to_pdf(md_files):
cwd = os.getcwd()
pdf_dir = os.path.join(cwd, PDF_DIR)
for name, path in md_files.items():
os.chdir(os.path.join(cwd, os.path.dirname(path)))
html = name.split(".")[0] + ".html"
pdf = pdf_dir + name.split(".")[0] + ".pdf"
os.system("grip {} --export {}".format(name, html))
os.chdir(cwd)
os.system("./html_to_pdf.sh {} {}".format(pdf, path[:-2] + "html"))
if __name__ == "__main__":
main()