and trailing
: @@ -211,35 +278,32 @@ class Build: return snippets def __parse_contents(self): - with open("data/content.json") as f: - contents = json.load(f) + with (self.config.p_data / "content.json").open() as file: + contents = json.load(file) return contents def __build_index(self, snippets): - template = self.env.get_template("index.html") + template = self.env.get_template("html/index.html") result = template.render({"snippets": snippets}) - with open("build/index.html", "w") as file: + with (self.config.p_build / "index.html").open("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}) + template = self.env.get_template(f"html/{template}.html") + result = template.render({"snippets": snippets}) - with open(f"build/{page}.html", "w") as file: + with (self.config.p_build / f"{page}.html").open("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"] - ) + with (self.config.p_build / f"{page}.html").open("w") as file: + result = self.__build_page(content=content["content"], sidebar=content["sidebar"]) file.write(result) def build_website(self): @@ -250,4 +314,4 @@ class Build: 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") \ No newline at end of file + self.__build_html_page(contents, "infos") diff --git a/src/config.py b/src/config.py index ef1f6c2..fe381b9 100644 --- a/src/config.py +++ b/src/config.py @@ -1,12 +1,10 @@ import json import os +from pathlib import Path class Config: - env_prefix = "OHM" - access_token: str - base_url: str - no_latex: bool + __env_prefix = "OHM" def __init__(self): if os.path.isfile("config/config.json"): @@ -19,14 +17,28 @@ class Config: self.content_base_url = self.get_config_value("directus_content_base_url", "https://redaktion.50ohm.de/") self.no_latex = self.get_config_value("no_latex", False) + self.p_fragenkatalog = Path(self.get_config_value("path_fragenkatalog", "./data/fragenkatalog3b.json")) + + self.p_data = Path("./data") + self.p_data_photos = self.p_data / "photos" + self.p_data_pictures = self.p_data / "pictures" + + self.p_build = Path("./build") + self.p_build_photos = self.p_build / "photos" + self.p_build_pictures = self.p_build / "pictures" + self.p_build_assets = self.p_build / "assets" + + self.p_assets = Path("./assets") + def get_config_value(self, key: str, default=None): if key in self.config: return self.config[key] - elif f"{self.env_prefix}_{key.upper()}" in os.environ.keys(): - return os.environ[f"{self.env_prefix}_{key.upper()}"] + elif f"{self.__env_prefix}_{key.upper()}" in os.environ.keys(): + return os.environ[f"{self.__env_prefix}_{key.upper()}"] elif default is not None: return default else: raise Exception( - f"ERROR: Required value for '{key}' not found. Add to config.json or env as '${self.env_prefix}_{key.upper()}'" + f"ERROR: Required value for '{key}' not found." + f"Add to config.json or env as '${self.__env_prefix}_{key.upper()}'" ) diff --git a/src/download.py b/src/download.py index 9295825..9459417 100644 --- a/src/download.py +++ b/src/download.py @@ -6,9 +6,13 @@ import shutil from joblib import Memory, Parallel, delayed from tqdm import tqdm +from api.directus import DirectusAPI + +from .config import Config + class Download: - def __init__(self, api, content_api, config): + def __init__(self, api: DirectusAPI, content_api: DirectusAPI, config: Config): self.api = api self.config = config self.content_api = content_api @@ -60,7 +64,7 @@ class Download: "edition": edition, } - with open("data/book_" + edition + ".json", "w", encoding="utf-8") as file: + with (self.config.p_data / f"book_{edition}.json").open("w", encoding="utf-8") as file: json.dump(out_edition, file, ensure_ascii=False, indent=4) def download_question_metadata(self): @@ -82,26 +86,26 @@ class Download: } # Serializing json: - with open("data/metadata.json", "w") as f: + with (self.config.p_data / "metadata.json").open("w", encoding="utf-8") as f: json.dump(result, f, indent=4) f.close() def download_photos(self): + self.config.p_data_photos.mkdir(parents=True, exist_ok=True) + photos = self.api.get("items/Fotos", params={"limit": -1}) for photo in tqdm(photos, desc="Downloading photos"): data = self.api.get_file("assets/" + photo["photo"]) - with open(f"./data/photos/{photo['id']}.jpg", "wb") as file: + with (self.config.p_data_photos / f"{photo['id']}.jpg").open("wb") as file: file.write(data) - def __symlink_pictures(self): - os.chdir("./data/pictures") - if not os.path.islink("foto"): - os.system("ln -s ../photos foto") - os.chdir("../..") - def download_pictures(self): - self.__symlink_pictures() + self.config.p_data_pictures.mkdir(parents=True, exist_ok=True) + # Symlink photos, so LaTeX can access these assets to render into graphics. + foto_link = self.config.p_data_pictures / "foto" + if not foto_link.is_symlink(): + foto_link.symlink_to(self.config.p_data_photos) memory = Memory("./cache", verbose=0) @@ -115,17 +119,22 @@ class Download: return if self.config.no_latex: - shutil.copyfile("./assets/images/50ohm_gray.svg", f"./data/pictures/{pid}.svg") + shutil.copyfile("./assets/images/50ohm_gray.svg", self.config.p_data_pictures / f"{pid}.svg") else: - with open(f"./data/pictures/img/{pid}include.tex", "w") as file: + with (self.config.p_data_pictures / f"img/{pid}include.tex").open("w") as file: file.write(picture["latex"]) - with open(f"./data/pictures/{pid}.tex", "w", encoding="utf-8") as file: + + aux_file = self.config.p_data_photos / f"{pid}.tex" + with aux_file.open("w", encoding="utf-8") as file: # Write the auxilary LaTeX file: file.write(f"\\documentclass{{BNetzA-Fragenkatalog}}\\DARCimageOnly{{9cm}}{{{pid}include}}") # Build the picture: - os.system(f"latexmk -lualatex -f -interaction=nonstopmode ./data/pictures/{pid}.tex > /dev/null 2>&1") + os.system(f"latexmk -lualatex -f -interaction=nonstopmode {aux_file} > /dev/null 2>&1") # Convert the PDF to SVG: - os.system(f"pdftocairo -svg data/pictures/{pid}.pdf - > data/pictures/{pid}.svg") + os.system( + "pdftocairo -svg" + f"{self.config.p_data_pictures / f'{pid}.pdf'} - > {self.config.p_data_pictures / f'{pid}.svg'}" + ) pictures = self.api.get("items/pictures", params={"limit": -1}) @@ -139,20 +148,22 @@ class Download: result = {} for include in tqdm(includes, desc="Downloading includes"): result[include["ident"]] = include["content"] - - with open("data/includes.json", "w") as f: - json.dump(result, f, indent=4) + + with (self.config.p_data / "includes.json").open("w", encoding="utf-8") as file: + json.dump(result, file, indent=4) def download_snippets(self): snippets = {} for snippet in tqdm(self.content_api.get("items/snippet"), desc="Downloading snippets"): snippets[snippet["ident"]] = snippet["content"] - with open("data/snippets.json", "w", encoding="utf-8") as file: + with (self.config.p_data / "snippets.json").open("w", encoding="utf-8") as file: json.dump(snippets, file, ensure_ascii=False, indent=4) def download_content(self): contents = [] - for content in self.content_api.get("items/content"): #tqdm(self.content_api.get("items/content"), desc="Downloading content"): + for content in self.content_api.get( + "items/content" + ): # tqdm(self.content_api.get("items/content"), desc="Downloading content"): contents.append( { "url_part": content["url_part"], @@ -160,6 +171,6 @@ class Download: "sidebar": content["sidebar"], } ) - - with open("data/content.json", "w", encoding="utf-8") as file: + + with (self.config.p_data / "content.json").open("w", encoding="utf-8") as file: json.dump(contents, file, ensure_ascii=False, indent=4) diff --git a/templates/slide/help.html b/templates/slide/help.html new file mode 100644 index 0000000..036c33a --- /dev/null +++ b/templates/slide/help.html @@ -0,0 +1,112 @@ +Diese Navigationshilfe zeigt die ersten Schritte zur Verwendung der Präsention. Sie kann mit ⟶ (Pfeiltaste + rechts) übersprungen werden.
+Zwischen den Folien und Abschnitten kann man mittels der Pfeiltasten hin- und herspringen, dazu kann man auch + die Pfeiltasten am Computer nutzen.
+
+ Mit ein paar Tastenkürzeln können weitere Funktionen aufgerufen werden. Die wichtigsten sind:
+Die Präsentation ist zweidimensional aufgebaut. Dadurch sind in Spalten die einzelnen Abschnitte eines + Kapitels und in den Reihen die Folien zu den Abschnitten.
+Tippt man ein „o“ ein, bekommt man eine Übersicht über alle Folien des jeweiligen Kapitels. Das hilft + sich zunächst einen Überblick zu verschaffen oder sich zu orientieren, wenn man das Gefühlt hat sich + „verlaufen“ zu haben. Die Navigation erfolgt über die Pfeiltasten.
+
+ Durch Anklicken einer Folie wird diese präsentiert.
+
+ Tippt man ein „s“ ein, bekommt man ein neues Fenster, die Referentenansicht.
+Indem man „Layout“ auswählt, kann man zwischen verschieden Anordnungen der Elemente auswählen.
+Die Referentenansicht bietet folgende Elemente:
+Tippt man ein „f“ ein, wird die aktuelle Folie im Vollbild angezeigt. Mit „Esc“ kann man diesen wieder + verlassen.
+Das ist insbesondere für den Bildschirm mit der Präsentation für das Publikum praktisch. +
Tippt man ein „b“ ein, wird die Präsentation ausgeblendet.
+Sie kann wie folgte wieder eingeblendet werden:
+
+Bei gedrückter Alt-Taste und einem Mausklick in der Präsentation wird in diesen Teil hineingezoomt. Das ist + praktisch, um Details von Schaltungen hervorzuheben. Durh einen nochmaligen Mausklick zusammen mit Alt wird + wieder herausgezoomt.
+Das Zoomen funktioniert nur im ausgewählten Fenster. Die Referentenansicht ist hier nicht mit dem + Präsenationsansicht gesynct.
+{{ answer_label[loop.index - 1] }}: {{ answer.content }}
+ {% endfor -%} + {% endif -%} + {% if answer_pictures[0] -%} + {% for answer in answer_pictures|shuffle_answers -%} +{{ book["abstract"] }}
+Foo
", 1, 0) + "\n", "Foo
", 1, 0) + "\n", - "Foo
", 1, 0) + "\n", + "Foo
", 1, 0) + + "\n", "Foo
\n", "Foo
\nFoo
\nFoo
\na
\na
\nb
\na
\na
\na
\n