From 74554dd821fc526bd119eb42b60d8a86d4636058 Mon Sep 17 00:00:00 2001
From: Matthias Jung
Fehler und Feedback in Prüfungsfragen bitte an fragenkatalog@darc.de, Fehler und Feedback zur Plattform bitte über 50ohm@darc.de melden.
Lust mitzuarbeiten? Das Projekt findest du auf GitHub, auch unsere App ist auf GitHub zu finden.
Informationen für Ausbilder und Informationen über weitere geplante Features gibt es auf der Website des AJW-Referats.", + "lernen_paten_title": "Ausbildungspaten", + "index_title": "Werde Funkamateur!", + "lernen_selbst_btn_nea": "Kurs Klasse A (mit N und E)", + "lernen_selbst_btn_ea": "Aufstockungskurs N nach A", + "lernen_selbst_btn_digi": "Auszug Digitaltechnik (E und A)", + "lernen_selbst_title": "Selbst-Studium" +} \ No newline at end of file diff --git a/src/build.py b/src/build.py index 49e9120..c431868 100644 --- a/src/build.py +++ b/src/build.py @@ -1,6 +1,7 @@ import json import random import shutil +from pathlib import Path from jinja2 import Environment, FileSystemLoader from joblib import Memory @@ -385,25 +386,49 @@ class Build: ) def __parse_snippets(self): - with (self.config.p_data / "snippets.json").open() as file: - snippets = json.load(file) + snippets_dir = self.config.p_data / "git_content/contents/snippets/" + snippets = {} + + for md_file in Path(snippets_dir).glob("*.md"): + with md_file.open() as file: + snippets[md_file.stem] = file.read() + + with FiftyOhmHtmlRenderer( + question_renderer=self.__build_question, + picture_handler=self.__picture_handler, + photo_handler=self.__photo_handler, + include_handler=self.__include_handler, + ) as renderer: + for key, value in snippets.items(): + snippets[key] = renderer.render_inner(Document(value)) + # Remove leading
and trailing
: + snippets[key] = snippets[key][3:-4] - with FiftyOhmHtmlRenderer( - question_renderer=self.__build_question, - picture_handler=self.__picture_handler, - photo_handler=self.__photo_handler, - include_handler=self.__include_handler, - ) as renderer: - for key, value in snippets.items(): - snippets[key] = renderer.render_inner(Document(value)) - # Remove leadingand trailing
: - snippets[key] = snippets[key][3:-4] return snippets def __parse_contents(self): - with (self.config.p_data / "content.json").open() as file: - contents = json.load(file) - return contents + static_dir = self.config.p_data / "git_content/contents/static/" + static = [] + + for static_file in Path(static_dir).glob("*.html"): + if "sidebar" not in static_file.stem: + with static_file.open() as file: + content = file.read() + sidebar_file = static_dir / f"{static_file.stem}_sidebar.html" + if not sidebar_file.exists(): + sidebar = "" + else: + with sidebar_file.open() as file: + sidebar = file.read() + + static.append( + { + "url_part": static_file.stem, + "content": content, + "sidebar": sidebar if sidebar != "" else None, + } + ) + return static def __build_index(self, snippets): template = self.env.get_template("html/index.html") diff --git a/src/download.py b/src/download.py index 9e9dab4..9a43a06 100644 --- a/src/download.py +++ b/src/download.py @@ -1,7 +1,4 @@ -import json - from git import Repo -from tqdm import tqdm from api.directus import DirectusAPI @@ -13,29 +10,6 @@ class Download: self.config = config self.content_api = content_api - def download_snippets(self): - snippets = {} - for snippet in tqdm(self.content_api.get("items/snippet"), desc="Downloading snippets"): - snippets[snippet["ident"]] = snippet["content"] - 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"): - contents.append( - { - "url_part": content["url_part"], - "content": content["content"], - "sidebar": content["sidebar"], - } - ) - - with (self.config.p_data / "content.json").open("w", encoding="utf-8") as file: - json.dump(contents, file, ensure_ascii=False, indent=4) - def download_git_content(self): repo_path = self.config.p_data / "git_content" if not repo_path.exists():