|
|
|
from glob import glob
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import jinja2
|
|
|
|
|
|
|
|
# https://devdocs.io/python~3.9/library/glob#glob.glob
|
|
|
|
# files = glob("content/**", recursive=True)
|
|
|
|
# print(files)
|
|
|
|
print("---------")
|
|
|
|
|
|
|
|
all_html = ""
|
|
|
|
all_md = ""
|
|
|
|
html=[]
|
|
|
|
|
|
|
|
folders = glob("content/*")
|
|
|
|
print(folders)
|
|
|
|
|
|
|
|
for folder in folders:
|
|
|
|
files = glob(folder + "/*")
|
|
|
|
print(files)
|
|
|
|
print("************")
|
|
|
|
|
|
|
|
for file in files:
|
|
|
|
#print(file)
|
|
|
|
if file.endswith(".md"):
|
|
|
|
print("===========")
|
|
|
|
file = file.replace(" ", "\ ")
|
|
|
|
print(file)
|
|
|
|
|
|
|
|
# html_file = file.replace(".md", ".html")
|
|
|
|
# pandoc_cmd = "pandoc -s -c style.css -f markdown -t html " + file + " -o " + html_file
|
|
|
|
# os.system(pandoc_cmd)
|
|
|
|
# print("standalone html files saved!")
|
|
|
|
|
|
|
|
pandoc2 = "pandoc -f markdown -t html " + file
|
|
|
|
html_data = subprocess.run(pandoc2, capture_output=True, text=True).stdout
|
|
|
|
print("html_data: ", html_data)
|
|
|
|
|
|
|
|
# #editing the html before creatings the main file
|
|
|
|
# # filename = os.path.basename(file)
|
|
|
|
# # print("filename", filename)
|
|
|
|
# # html_data = html_data.replace('<img src="','<img src="' + folder + '/')
|
|
|
|
|
|
|
|
# print("This is the html data: ", html_data)
|
|
|
|
|
|
|
|
# # and then collect all that content into a variable called "all_html"
|
|
|
|
# # add this content to all_html
|
|
|
|
# all_html = all_html + html_data
|
|
|
|
html.append(html_data)
|
|
|
|
|
|
|
|
md_data = open(file).read()
|
|
|
|
all_md += "\n"+md_data
|
|
|
|
|
|
|
|
#create md and use pandoc to convert to html
|
|
|
|
output = open("booklet.md", "w")
|
|
|
|
output.write(all_md)
|
|
|
|
output.close()
|
|
|
|
# pandoc_md = "pandoc -s --toc -c style.css -f markdown -t html booklet.md -o booklet.html"
|
|
|
|
# os.system(pandoc_md)
|
|
|
|
print("booklet md files saved!")
|
|
|
|
|
|
|
|
env = jinja2.Environment(loader=jinja2.FileSystemLoader("."))
|
|
|
|
template = env.get_template("booklet.template.html")
|
|
|
|
booklet_html = template.render(content=html)
|
|
|
|
print("this is the html: ", booklet_html)
|
|
|
|
output = open("booklet.html", "w")
|
|
|
|
output.write(booklet_html)
|
|
|
|
output.close()
|
|
|
|
print("booklet html files saved!")
|
|
|
|
|
|
|
|
#take all the css files and write to main css
|
|
|
|
|
|
|
|
|
|
|
|
# Now open this page in the browser, remember: paged.js needs to be accessed through a webserver.
|
|
|
|
|
|
|
|
# To run a webserver locally, you can use:
|
|
|
|
# cd SI20/booklet/
|
|
|
|
# python3 -m http.server
|
|
|
|
# localhost:8000/booklet.html
|