refactor: adopts rendering process to new data source
This commit is contained in:
@@ -16,11 +16,11 @@ dl.download_content()
|
|||||||
|
|
||||||
## Build Everything:
|
## Build Everything:
|
||||||
bd = build.Build(conf)
|
bd = build.Build(conf)
|
||||||
# bd.build_website()
|
bd.build_website()
|
||||||
# bd.build_edition("N")
|
bd.build_edition("N")
|
||||||
# bd.build_edition("E")
|
bd.build_edition("E")
|
||||||
# bd.build_edition("A")
|
bd.build_edition("A")
|
||||||
# bd.build_edition("NE")
|
bd.build_edition("NE")
|
||||||
# bd.build_edition("EA")
|
bd.build_edition("EA")
|
||||||
# bd.build_edition("NEA")
|
bd.build_edition("NEA")
|
||||||
# bd.build_assets()
|
bd.build_assets()
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
|
|||||||
def render_photo_helper(id, ref, text, number, alt_text):
|
def render_photo_helper(id, ref, text, number, alt_text):
|
||||||
return f"""
|
return f"""
|
||||||
<figure class="photo" id="ref_{ref}" name="{ref}">
|
<figure class="photo" id="ref_{ref}" name="{ref}">
|
||||||
<img src="photos/{id}.jpg" alt="{alt_text}">
|
<img src="photos/{id}.png" alt="{alt_text}">
|
||||||
<figcaption>Abbildung {number}: {text}</figcaption>
|
<figcaption>Abbildung {number}: {text}</figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ class Question(BlockToken):
|
|||||||
def start(line):
|
def start(line):
|
||||||
# Search for:
|
# Search for:
|
||||||
# [question:123]
|
# [question:123]
|
||||||
return re.match(r"^\s*\[question:\d+\]", line)
|
return re.match(r"^\s*\[question:[\w\d]+\]", line)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def read(cls, lines):
|
def read(cls, lines):
|
||||||
first_line = next(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
|
return question_number
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
+29
-15
@@ -48,26 +48,28 @@ class Build:
|
|||||||
return questions
|
return questions
|
||||||
|
|
||||||
# cached
|
# 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"""
|
"""Combines the original question dataset from BNetzA with our internal metadata"""
|
||||||
|
|
||||||
question_template = self.env.get_template(template_file)
|
question_template = self.env.get_template(template_file)
|
||||||
|
|
||||||
with (self.config.p_data / "metadata3b.json").open() as file:
|
with (self.config.p_data / "git_content/contents/questions/metadata3b.json").open() as file:
|
||||||
metadata = json.load(file)
|
metadata_json = json.load(file)
|
||||||
|
|
||||||
question = None
|
question = None
|
||||||
number = None
|
metadata = None
|
||||||
if f"{input}" in metadata:
|
|
||||||
metadata = metadata[f"{input}"]
|
|
||||||
number = metadata["number"] # Fragennummer z.B. AB123
|
|
||||||
if number in self.questions:
|
if number in self.questions:
|
||||||
question = self.questions[number]
|
question = self.questions[number]
|
||||||
|
|
||||||
if question is None:
|
if number in metadata_json:
|
||||||
|
metadata = metadata_json[number]
|
||||||
|
|
||||||
|
if question is None or metadata is None:
|
||||||
tqdm.write(
|
tqdm.write(
|
||||||
f"\033[31mQuestion #{input} is missing"
|
f"\033[31mQuestion #{number} is missing"
|
||||||
+ (f" (but found number: {number})" if number is not None else "")
|
+ (" (Question not in question pool)" if question is None else "")
|
||||||
|
+ (" (Question not in metadata)" if metadata is None else "")
|
||||||
+ "\033[0m"
|
+ "\033[0m"
|
||||||
)
|
)
|
||||||
metadata = {"layout": "not-found", "picture_a": ""}
|
metadata = {"layout": "not-found", "picture_a": ""}
|
||||||
@@ -143,7 +145,7 @@ class Build:
|
|||||||
|
|
||||||
def __photo_handler(self, id):
|
def __photo_handler(self, id):
|
||||||
self.config.p_build_photos.mkdir(parents=True, exist_ok=True)
|
self.config.p_build_photos.mkdir(parents=True, exist_ok=True)
|
||||||
file = f"{id}.jpg"
|
file = f"{id}.png"
|
||||||
try:
|
try:
|
||||||
shutil.copyfile(self.config.p_data_photos / file, self.config.p_build_photos / file)
|
shutil.copyfile(self.config.p_data_photos / file, self.config.p_build_photos / file)
|
||||||
if (self.config.p_data_photos / f"{id}.txt").exists():
|
if (self.config.p_data_photos / f"{id}.txt").exists():
|
||||||
@@ -175,9 +177,8 @@ class Build:
|
|||||||
file.write(result)
|
file.write(result)
|
||||||
|
|
||||||
def __include_handler(self, include):
|
def __include_handler(self, include):
|
||||||
with (self.config.p_data / "includes.json").open() as file:
|
with (self.config.p_data / f"git_content/contents/html/{include}.html").open() as file:
|
||||||
includes = json.load(file)
|
return file.read()
|
||||||
return includes.get(include)
|
|
||||||
|
|
||||||
# cached
|
# cached
|
||||||
def __build_section(
|
def __build_section(
|
||||||
@@ -337,9 +338,22 @@ class Build:
|
|||||||
|
|
||||||
edition = edition.upper()
|
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)
|
book = json.load(file)
|
||||||
chapters = book["chapters"]
|
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"]
|
edition_name = book["title"]
|
||||||
self.__build_book_index(book)
|
self.__build_book_index(book)
|
||||||
self.__build_slide_index(book)
|
self.__build_slide_index(book)
|
||||||
|
|||||||
+2
-2
@@ -22,8 +22,8 @@ class Config:
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.p_data = Path("./data")
|
self.p_data = Path("./data")
|
||||||
self.p_data_photos = self.p_data / "git_content" / "photos"
|
self.p_data_photos = self.p_data / "git_content" / "contents" / "photos"
|
||||||
self.p_data_pictures = self.p_data / "git_content" / "pictures"
|
self.p_data_pictures = self.p_data / "git_content" / "contents" / "drawings"
|
||||||
|
|
||||||
self.p_build = Path("./build")
|
self.p_build = Path("./build")
|
||||||
self.p_build_photos = self.p_build / "photos"
|
self.p_build_photos = self.p_build / "photos"
|
||||||
|
|||||||
Reference in New Issue
Block a user