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("./*") 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) md_data = open(file).read() all_md += "\n"+md_data elif file.endswith((".jpg",".png")): print("image found yay",file) output_file=file.replace(folder,"./00-booklet") copy_command=f"cp {file} {output_file}" os.system(copy_command) print("copied to booklet!",copy_command) #create booklet.md output = open("00-booklet/booklet.md", "w") output.write(all_md) output.close() print("booklet md files saved!") # use pandoc to convert booklet.md to html pandoc_command = "pandoc --toc -f markdown -t html 00-booklet/booklet.md" #html_data = subprocess.run(pandoc_command, capture_output=True, text=True).stdout html_data = subprocess.check_output(pandoc_command, shell=True, text=True,encoding="utf-8") print("html has been generated!") #print("html data!", html_data) #html to template environment env = jinja2.Environment(loader=jinja2.FileSystemLoader("00-booklet")) template = env.get_template("booklet.template.html") booklet_html = template.render(content=html_data) print("this is the html: ", booklet_html) output = open("00-booklet/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