|
|
|
from glob import glob
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import jinja2
|
|
|
|
import json
|
|
|
|
|
|
|
|
# https://devdocs.io/python~3.9/library/glob#glob.glob
|
|
|
|
# files = glob("content/**", recursive=True)
|
|
|
|
# print(files)
|
|
|
|
print("---------")
|
|
|
|
|
|
|
|
all_html = []
|
|
|
|
|
|
|
|
# old way getting all folders
|
|
|
|
# folders = glob("*")
|
|
|
|
# new way using folder list
|
|
|
|
folders = open('./00-booklet/section-order.txt').read().splitlines()
|
|
|
|
stoplist = ["00-booklet", "spin-wheel"]
|
|
|
|
# print(folders)
|
|
|
|
titles = []
|
|
|
|
|
|
|
|
for folder in folders:
|
|
|
|
if folder in stoplist:
|
|
|
|
continue
|
|
|
|
print("...............")
|
|
|
|
print("current folder!",folder)
|
|
|
|
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, encoding='utf-8').read()
|
|
|
|
|
|
|
|
#grab metadatas
|
|
|
|
metapandoc = f"pandoc {file} --template=./00-booklet/pandoc-metadata.template"
|
|
|
|
file_metadata = subprocess.check_output(metapandoc, shell=True, text=True,encoding="utf-8")
|
|
|
|
print("You did it! You fount the metadata, good job. Its:", file_metadata)
|
|
|
|
try:
|
|
|
|
file_dictionary = json.loads(file_metadata)
|
|
|
|
titles.append(file_dictionary["title"])
|
|
|
|
except KeyError as err:
|
|
|
|
print(err)
|
|
|
|
|
|
|
|
# use pandoc to turn file into html
|
|
|
|
pandoc_command = "pandoc -f markdown -t html " + file
|
|
|
|
html_data = subprocess.check_output(pandoc_command, shell=True, text=True,encoding="utf-8")
|
|
|
|
print("html has been generated!")
|
|
|
|
|
|
|
|
all_html.append(html_data)
|
|
|
|
|
|
|
|
#Images no longer copying, that time has passed.
|
|
|
|
# elif file.endswith((".jpg",".png",".jpeg",".jfif",".bmp")):
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
|
|
|
|
#html to template environment
|
|
|
|
print("Los titlos: ", titles)
|
|
|
|
env = jinja2.Environment(loader=jinja2.FileSystemLoader("00-booklet"))
|
|
|
|
template = env.get_template("booklet.template.html")
|
|
|
|
booklet_html = template.render(content=all_html,titles=titles)
|
|
|
|
#print("this is the html: ", booklet_html)
|
|
|
|
output = open("00-booklet/booklet.html", "w",encoding="utf-8")
|
|
|
|
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
|