Merge branch 'main' into feature/slides
This commit is contained in:
+89
-10
@@ -3,7 +3,6 @@ import os
|
||||
import random
|
||||
import shutil
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
from joblib import Memory
|
||||
from mistletoe import Document
|
||||
@@ -98,9 +97,13 @@ class Build:
|
||||
return self.__build_question(input, template_file="slide/question.html")
|
||||
|
||||
# cached
|
||||
def __build_page(self, content) :
|
||||
def __build_page(self, content, course_wrapper=False, sidebar=None) :
|
||||
page_template = self.env.get_template("html/page.html")
|
||||
return page_template.render(content=content)
|
||||
return page_template.render(
|
||||
content=content,
|
||||
course_wrapper=course_wrapper,
|
||||
sidebar=sidebar
|
||||
)
|
||||
|
||||
def __picture_handler(self, id):
|
||||
os.makedirs("build/pictures", exist_ok=True)
|
||||
@@ -132,8 +135,7 @@ class Build:
|
||||
title=next_chapter["title"],
|
||||
)
|
||||
|
||||
result = self.__build_page(result)
|
||||
result = BeautifulSoup(result, "html.parser").prettify()
|
||||
result = self.__build_page(result, course_wrapper=True)
|
||||
file.write(result)
|
||||
|
||||
# cached
|
||||
@@ -169,8 +171,34 @@ class Build:
|
||||
title=next_chapter["title"],
|
||||
)
|
||||
|
||||
result = self.__build_page(result)
|
||||
result = BeautifulSoup(result, "html.parser").prettify()
|
||||
result = self.__build_page(result, course_wrapper=True)
|
||||
file.write(result)
|
||||
|
||||
def __build_chapter_slidedeck(self, edition, chapter, sections, next_chapter):
|
||||
with open(f'build/{edition}_slide_{chapter["ident"]}.html', 'w') as file:
|
||||
slide_template = self.env.get_template("slide/slide.html")
|
||||
help_template = self.env.get_template("slide/help.html")
|
||||
next_template = self.env.get_template("slide/next.html")
|
||||
with FiftyOhmHtmlSlideRenderer(
|
||||
question_renderer=self.__build_question_slide,
|
||||
picture_handler=self.__picture_handler,
|
||||
photo_handler=self.__photo_handler
|
||||
) as renderer:
|
||||
result = "<section>\n"
|
||||
result += f'<section data-background="#DAEEFA">\n<h1>{chapter["title"]}</h1>\n</section>\n'
|
||||
result += help_template.render()
|
||||
result += "</section>\n"
|
||||
for section in sections:
|
||||
tmp = f'<section data-background="#DAEEFA">\n<h1>{section["title"]}</h1>\n</section>\n'
|
||||
tmp += renderer.render_wrapper(section["slide"])
|
||||
result += f"<section>{tmp}</section>\n"
|
||||
result += next_template.render(
|
||||
edition=edition,
|
||||
next_chapter=next_chapter,
|
||||
chapter=chapter,
|
||||
)
|
||||
|
||||
result = slide_template.render(content=result)
|
||||
file.write(result)
|
||||
|
||||
def __build_chapter_slidedeck(self, edition, chapter, sections, next_chapter):
|
||||
@@ -219,7 +247,6 @@ class Build:
|
||||
book=book,
|
||||
)
|
||||
result = self.__build_page(result)
|
||||
result = BeautifulSoup(result, "html.parser").prettify()
|
||||
file.write(result)
|
||||
|
||||
def __build_slide_index(self, book):
|
||||
@@ -229,7 +256,6 @@ class Build:
|
||||
book=book,
|
||||
)
|
||||
result = self.__build_page(result)
|
||||
result = BeautifulSoup(result, "html.parser").prettify()
|
||||
file.write(result)
|
||||
|
||||
def build_edition(self, edition):
|
||||
@@ -251,4 +277,57 @@ class Build:
|
||||
self.__build_section(edition, edition_name, section, i, chapter, next_section, next_chapter)
|
||||
|
||||
def build_assets(self):
|
||||
shutil.copytree("assets", "build/assets", dirs_exist_ok=True)
|
||||
shutil.copytree("assets", "build/assets", dirs_exist_ok=True)
|
||||
|
||||
def __parse_snippets(self):
|
||||
with open("data/snippets.json") as f:
|
||||
snippets = json.load(f)
|
||||
|
||||
with FiftyOhmHtmlRenderer(self.__build_question, self.__picture_handler, self.__photo_handler) as renderer:
|
||||
for key, value in snippets.items():
|
||||
snippets[key] = renderer.render_inner(Document(value))
|
||||
# Remove leading <p> and trailing </p>:
|
||||
snippets[key] = snippets[key][3:-4]
|
||||
return snippets
|
||||
|
||||
def __parse_contents(self):
|
||||
with open("data/content.json") as f:
|
||||
contents = json.load(f)
|
||||
return contents
|
||||
|
||||
def __build_index(self, snippets):
|
||||
template = self.env.get_template("index.html")
|
||||
result = template.render({"snippets": snippets})
|
||||
|
||||
with open("build/index.html", "w") as file:
|
||||
result = self.__build_page(result)
|
||||
|
||||
file.write(result)
|
||||
|
||||
def __build_course_page(self, snippets, template, page):
|
||||
template = self.env.get_template(f"{template}.html")
|
||||
result=template.render({"snippets": snippets})
|
||||
|
||||
with open(f"build/{page}.html", "w") as file:
|
||||
result = self.__build_page(result)
|
||||
file.write(result)
|
||||
|
||||
def __build_html_page(self, contents, page):
|
||||
for content in contents:
|
||||
if content["url_part"] == page:
|
||||
with open(f"build/{page}.html", "w") as file:
|
||||
result = self.__build_page(
|
||||
content=content["content"],
|
||||
sidebar=content["sidebar"]
|
||||
)
|
||||
file.write(result)
|
||||
|
||||
def build_website(self):
|
||||
snippets = self.__parse_snippets()
|
||||
contents = self.__parse_contents()
|
||||
self.__build_index(snippets)
|
||||
self.__build_course_page(snippets, "kurse-karte", "kurse_vor_ort_karte")
|
||||
self.__build_course_page(snippets, "kurse-liste", "kurse_vor_ort_liste")
|
||||
self.__build_course_page(snippets, "patenkarte", "patenkarte")
|
||||
self.__build_html_page(contents, "pruefung")
|
||||
self.__build_html_page(contents, "infos")
|
||||
Reference in New Issue
Block a user