2023-09-16 13:12:45 +03:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
import mistune
|
|
|
|
|
|
|
|
render = mistune.create_markdown(
|
|
|
|
plugins=['math', 'strikethrough', 'footnotes', 'table', 'url', 'task_lists', 'abbr', 'mark', 'subscript', 'spoiler']
|
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
|
|
|
shutil.rmtree("build")
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
os.mkdir("build")
|
|
|
|
|
|
|
|
|
|
|
|
for filename in os.listdir("static"):
|
|
|
|
if len(filename.split(".")) == 1:
|
|
|
|
shutil.copytree(f"{os.getcwd()}/static/{filename}", f"{os.getcwd()}/build/{filename}")
|
|
|
|
else:
|
|
|
|
shutil.copy(f"{os.getcwd()}/static/{filename}", f"{os.getcwd()}/build/{filename}")
|
|
|
|
|
|
|
|
|
|
|
|
template_file = open('template.html', "r")
|
|
|
|
template_text = template_file.read()
|
|
|
|
template_file.close()
|
|
|
|
|
|
|
|
|
|
|
|
def gen_file(directory):
|
|
|
|
file = open(directory, "r")
|
|
|
|
md_text = file.read()
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
return template_text.replace("{{%CONTENT%}}", render(md_text))
|
|
|
|
|
2023-12-26 10:01:18 +03:00
|
|
|
def go_through(directory):
|
|
|
|
for filename in os.listdir(directory):
|
|
|
|
if len(filename.split(".")) == 1:
|
|
|
|
content = gen_file(f"{os.getcwd()}/{directory}/{filename}/index.md")
|
|
|
|
|
2023-12-26 10:29:18 +03:00
|
|
|
_, _, fier = directory.partition('/')
|
2023-12-26 10:04:23 +03:00
|
|
|
if len(fier) != 0: fier += "/"
|
2023-12-26 10:01:18 +03:00
|
|
|
|
|
|
|
loc = f"{fier}{filename}/index.html"
|
|
|
|
os.makedirs(f'build/{fier}{filename}')
|
|
|
|
|
|
|
|
go_through(directory + "/" + filename)
|
|
|
|
else:
|
|
|
|
# TODO: add support to ./././...
|
|
|
|
content = gen_file(f"{os.getcwd()}/content/{filename}")
|
|
|
|
loc = filename.split(".")[0] + '.html'
|
|
|
|
|
|
|
|
file = open(f"{os.getcwd()}/build/{loc}", "a")
|
|
|
|
file.write(content)
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
go_through("content")
|