diff --git a/build.py b/build.py index cbd48f1..d27f990 100644 --- a/build.py +++ b/build.py @@ -16,11 +16,11 @@ dl.download_content() ## Build Everything: bd = build.Build(conf) -# bd.build_website() -# bd.build_edition("N") -# bd.build_edition("E") -# bd.build_edition("A") -# bd.build_edition("NE") -# bd.build_edition("EA") -# bd.build_edition("NEA") -# bd.build_assets() +bd.build_website() +bd.build_edition("N") +bd.build_edition("E") +bd.build_edition("A") +bd.build_edition("NE") +bd.build_edition("EA") +bd.build_edition("NEA") +bd.build_assets() diff --git a/renderer/fifty_ohm_html_renderer.py b/renderer/fifty_ohm_html_renderer.py index 2a54114..c73a511 100644 --- a/renderer/fifty_ohm_html_renderer.py +++ b/renderer/fifty_ohm_html_renderer.py @@ -277,7 +277,7 @@ class FiftyOhmHtmlRenderer(HtmlRenderer): def render_photo_helper(id, ref, text, number, alt_text): return f"""
- {alt_text} + {alt_text}
Abbildung {number}: {text}
""" diff --git a/renderer/question.py b/renderer/question.py index 9fe4c97..47d7eb7 100644 --- a/renderer/question.py +++ b/renderer/question.py @@ -8,12 +8,12 @@ class Question(BlockToken): def start(line): # Search for: # [question:123] - return re.match(r"^\s*\[question:\d+\]", line) + return re.match(r"^\s*\[question:[\w\d]+\]", line) @classmethod def read(cls, lines): first_line = next(lines) - question_number = re.match(r"^\s*\[question:(\d+)\]", first_line).group(1) + question_number = re.match(r"^\s*\[question:([\w\d]+)\]", first_line).group(1) return question_number @classmethod diff --git a/src/build.py b/src/build.py index 4b2dc6e..49e9120 100644 --- a/src/build.py +++ b/src/build.py @@ -48,26 +48,28 @@ class Build: return questions # cached - def __build_question(self, input, template_file="html/question.html"): + def __build_question(self, number, template_file="html/question.html"): """Combines the original question dataset from BNetzA with our internal metadata""" question_template = self.env.get_template(template_file) - with (self.config.p_data / "metadata3b.json").open() as file: - metadata = json.load(file) + with (self.config.p_data / "git_content/contents/questions/metadata3b.json").open() as file: + metadata_json = json.load(file) question = None - number = None - if f"{input}" in metadata: - metadata = metadata[f"{input}"] - number = metadata["number"] # Fragennummer z.B. AB123 - if number in self.questions: - question = self.questions[number] + metadata = None - if question is None: + if number in self.questions: + question = self.questions[number] + + if number in metadata_json: + metadata = metadata_json[number] + + if question is None or metadata is None: tqdm.write( - f"\033[31mQuestion #{input} is missing" - + (f" (but found number: {number})" if number is not None else "") + f"\033[31mQuestion #{number} is missing" + + (" (Question not in question pool)" if question is None else "") + + (" (Question not in metadata)" if metadata is None else "") + "\033[0m" ) metadata = {"layout": "not-found", "picture_a": ""} @@ -143,7 +145,7 @@ class Build: def __photo_handler(self, id): self.config.p_build_photos.mkdir(parents=True, exist_ok=True) - file = f"{id}.jpg" + file = f"{id}.png" try: shutil.copyfile(self.config.p_data_photos / file, self.config.p_build_photos / file) if (self.config.p_data_photos / f"{id}.txt").exists(): @@ -175,9 +177,8 @@ class Build: file.write(result) def __include_handler(self, include): - with (self.config.p_data / "includes.json").open() as file: - includes = json.load(file) - return includes.get(include) + with (self.config.p_data / f"git_content/contents/html/{include}.html").open() as file: + return file.read() # cached def __build_section( @@ -337,9 +338,22 @@ class Build: edition = edition.upper() - with (self.config.p_data / f"book_{edition}.json").open() as file: + with (self.config.p_data / f"git_content/toc/{edition}.json").open() as file: book = json.load(file) chapters = book["chapters"] + + for chapter in chapters: + for section in chapter["sections"]: + ident = section["ident"] + section["content"] = None + section["slide"] = None + with (self.config.p_data / f"git_content/contents/sections/{ident}.md").open() as sfile: + section_content = sfile.read() + section["content"] = section_content + with (self.config.p_data / f"git_content/contents/slides/{ident}.md").open() as sfile: + section_content = sfile.read() + section["slide"] = section_content + edition_name = book["title"] self.__build_book_index(book) self.__build_slide_index(book) diff --git a/src/config.py b/src/config.py index 7ce9eb8..0f71765 100644 --- a/src/config.py +++ b/src/config.py @@ -22,8 +22,8 @@ class Config: ) self.p_data = Path("./data") - self.p_data_photos = self.p_data / "git_content" / "photos" - self.p_data_pictures = self.p_data / "git_content" / "pictures" + self.p_data_photos = self.p_data / "git_content" / "contents" / "photos" + self.p_data_pictures = self.p_data / "git_content" / "contents" / "drawings" self.p_build = Path("./build") self.p_build_photos = self.p_build / "photos"