|
|
@ -2,6 +2,7 @@ from glob import glob
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import subprocess
|
|
|
|
import jinja2
|
|
|
|
import jinja2
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
# https://devdocs.io/python~3.9/library/glob#glob.glob
|
|
|
|
# https://devdocs.io/python~3.9/library/glob#glob.glob
|
|
|
|
# files = glob("content/**", recursive=True)
|
|
|
|
# files = glob("content/**", recursive=True)
|
|
|
@ -16,6 +17,7 @@ all_html = []
|
|
|
|
folders = open('./00-booklet/section-order.txt').read().splitlines()
|
|
|
|
folders = open('./00-booklet/section-order.txt').read().splitlines()
|
|
|
|
stoplist = ["00-booklet", "spin-wheel"]
|
|
|
|
stoplist = ["00-booklet", "spin-wheel"]
|
|
|
|
# print(folders)
|
|
|
|
# print(folders)
|
|
|
|
|
|
|
|
titles = []
|
|
|
|
|
|
|
|
|
|
|
|
for folder in folders:
|
|
|
|
for folder in folders:
|
|
|
|
if folder in stoplist:
|
|
|
|
if folder in stoplist:
|
|
|
@ -32,8 +34,17 @@ for folder in folders:
|
|
|
|
print("===========")
|
|
|
|
print("===========")
|
|
|
|
file = file.replace(" ", "\ ")
|
|
|
|
file = file.replace(" ", "\ ")
|
|
|
|
print(file)
|
|
|
|
print(file)
|
|
|
|
md_data = open(file).read()
|
|
|
|
md_data = open(file, encoding='utf-8').read()
|
|
|
|
#all_md += "\n"+md_data
|
|
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
# use pandoc to turn file into html
|
|
|
|
pandoc_command = "pandoc -f markdown -t html " + file
|
|
|
|
pandoc_command = "pandoc -f markdown -t html " + file
|
|
|
@ -41,7 +52,7 @@ for folder in folders:
|
|
|
|
print("html has been generated!")
|
|
|
|
print("html has been generated!")
|
|
|
|
|
|
|
|
|
|
|
|
all_html.append(html_data)
|
|
|
|
all_html.append(html_data)
|
|
|
|
elif file.endswith((".jpg",".png")):
|
|
|
|
elif file.endswith((".jpg",".png",".jpeg",".jfif",".bmp")):
|
|
|
|
print("image found yay",file)
|
|
|
|
print("image found yay",file)
|
|
|
|
output_file=file.replace(folder,"./00-booklet")
|
|
|
|
output_file=file.replace(folder,"./00-booklet")
|
|
|
|
copy_command=f"cp {file} {output_file}"
|
|
|
|
copy_command=f"cp {file} {output_file}"
|
|
|
@ -50,12 +61,12 @@ for folder in folders:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#html to template environment
|
|
|
|
#html to template environment
|
|
|
|
|
|
|
|
print("Los titlos: ", titles)
|
|
|
|
env = jinja2.Environment(loader=jinja2.FileSystemLoader("00-booklet"))
|
|
|
|
env = jinja2.Environment(loader=jinja2.FileSystemLoader("00-booklet"))
|
|
|
|
template = env.get_template("booklet.template.html")
|
|
|
|
template = env.get_template("booklet.template.html")
|
|
|
|
booklet_html = template.render(content=all_html)
|
|
|
|
booklet_html = template.render(content=all_html,titles=titles)
|
|
|
|
#print("this is the html: ", booklet_html)
|
|
|
|
#print("this is the html: ", booklet_html)
|
|
|
|
output = open("00-booklet/booklet.html", "w")
|
|
|
|
output = open("00-booklet/booklet.html", "w",encoding="utf-8")
|
|
|
|
output.write(booklet_html)
|
|
|
|
output.write(booklet_html)
|
|
|
|
output.close()
|
|
|
|
output.close()
|
|
|
|
print("booklet html files saved!")
|
|
|
|
print("booklet html files saved!")
|
|
|
|