diff --git a/build.py b/build.py index d27f990..26f86b8 100644 --- a/build.py +++ b/build.py @@ -10,11 +10,7 @@ dl = download.Download(content_api, conf) # Download the content files: dl.download_git_content() -# Download additional files: -dl.download_snippets() -dl.download_content() - -## Build Everything: +# Build Everything: bd = build.Build(conf) bd.build_website() bd.build_edition("N") diff --git a/config/config.json.example b/config/config.json.example index d93bed8..3ae6cdc 100644 --- a/config/config.json.example +++ b/config/config.json.example @@ -1,5 +1,3 @@ { - "directus_content_base_url" : "https://redaktion.50ohm.de/", - "directus_content_api_key" : "", "git_url" : "git@github.com:DARC-e-V/50ohm-contents-dl.git", } diff --git a/snippets_tmp.json b/snippets_tmp.json new file mode 100644 index 0000000..4456333 --- /dev/null +++ b/snippets_tmp.json @@ -0,0 +1,22 @@ +{ + "index_btn_start": "Jetzt starten", + "lernen_vor_ort_teaser": "Einige unserer Ortsverbände bieten Präsenzkurse mit erfahrenen Ausbildern an. Finde heraus, ob es einen für dich passenden Kurs bei dir in der Nähe gibt!", + "lernen_selbst_btn_n": "Kurs Klasse N", + "index_btn_was_ist_afu": "Was ist Amateurfunk?", + "lernen_selbst_btn_ne": "Kurs Klasse E (mit N)", + "lernen_vor_ort_btn": "Zur Lehrgangskarte", + "lernen_paten_btn": "Zur Patenkarte", + "index_teaser": "Wir bereiten dich auf die Prüfung zum Funkamateur vor. Unsere erfahrenen Ausbilder unterstützen dich auf dem gesamten Weg!", + "lernen_vor_ort_title": "Kurse vor Ort und Online", + "lernen_paten_teaser": "Unsere Ausbildungspaten sind erfahrene Funkamateure, die dich gerne unterstützen. Sie können mit dir auch praktischen Funkbetrieb üben.", + "lernen_selbst_teaser": "Bringe dir das nötige Wissen für die Amateurfunkprüfung einfach selber bei. Unser Lernmaterial hilft dir auf deinem Weg!", + "lernen_selbst_btn_a": "Aufstockungskurs E nach A", + "lernen_selbst_btn_e": "Aufstockungskurs N nach E", + "index_content": "50ohm.de hat die die BETA-Phase verlassen! Viel Spaß beim Lernen für die Klassen N, E und A wünscht das gesamte 50ohm.de-Team.
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():