feature: build index.html

This commit is contained in:
Prof. Dr. Matthias Jung DL9MJ
2025-06-24 22:04:13 +02:00
committed by Tim Grelka
parent ae5a2e1a66
commit 952006fa3a
6 changed files with 227 additions and 12 deletions
+26 -3
View File
@@ -124,7 +124,8 @@ class Build:
title=next_chapter["title"],
)
result = self.__build_page(result)
result = self.__build_page('<div class="course">'+result+'</div>')
result = BeautifulSoup(result, "html.parser").prettify()
file.write(result)
@@ -156,7 +157,7 @@ class Build:
title=next_chapter["title"],
)
result = self.__build_page(result)
result = self.__build_page('<div class="course">'+result+'</div>')
result = BeautifulSoup(result, "html.parser").prettify()
file.write(result)
@@ -187,4 +188,26 @@ class Build:
self.__build_section(edition, edition_name, section, 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 __build_index(self):
template = self.env.get_template("index.html")
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]
result = template.render({"snippets": snippets})
with open("build/index.html", "w") as file:
result = self.__build_page(result)
result = BeautifulSoup(result, "html.parser").prettify()
file.write(result)
def build_website(self):
self.__build_index()
+9 -1
View File
@@ -8,9 +8,10 @@ from tqdm import tqdm
class Download:
def __init__(self, api, config):
def __init__(self, api, content_api, config):
self.api = api
self.config = config
self.content_api = content_api
def download_edition(self, edition):
in_edition = self.api.get_one("items/edition", {"filter": {"ident": {"_eq": edition}}})
@@ -131,3 +132,10 @@ class Download:
Parallel(n_jobs=multiprocessing.cpu_count())(
delayed(build_picture)(picture) for picture in tqdm(pictures, desc="Build All Pictures")
)
def download_snippets(self):
snippets = {}
for snippet in tqdm(self.content_api.get("items/snippet"), desc="Downloading photos"):
snippets[snippet["ident"]] = snippet["content"]
with open("data/snippets.json", "w", encoding="utf-8") as file:
json.dump(snippets, file, ensure_ascii=False, indent=4)