refactor: changed question_index layout
This commit is contained in:
+14
-10
@@ -24,7 +24,7 @@ class Build:
|
||||
self.env.filters["shuffle_answers"] = self.__filter_shuffle_answers
|
||||
self.questions = self.__parse_katalog()
|
||||
|
||||
self.question_index = defaultdict(set)
|
||||
self.question_index = defaultdict(lambda: defaultdict(set))
|
||||
self.question_token_pattern = re.compile(r"^\s*\[question:([\w\d]+)\]", re.MULTILINE)
|
||||
|
||||
def __parse_katalog(self):
|
||||
@@ -394,7 +394,7 @@ class Build:
|
||||
section["slide"] = section_content
|
||||
|
||||
if section["content"] is not None:
|
||||
self.__collect_question_links(edition, ident, section["content"])
|
||||
self.__collect_question_occurrences(edition, ident, section["content"])
|
||||
|
||||
next_section = (
|
||||
chapter["sections"][section_number] if section_number < len(chapter["sections"]) else None
|
||||
@@ -523,16 +523,20 @@ class Build:
|
||||
page = self.__build_page(page, course_wrapper=False)
|
||||
file.write(page)
|
||||
|
||||
def __collect_question_links(self, edition: str, section_ident: str, section_content: str):
|
||||
section_filename = f"{edition}_{section_ident}.html"
|
||||
|
||||
def __collect_question_occurrences(self, edition: str, section_ident: str, section_content: str):
|
||||
for question_number in self.question_token_pattern.findall(section_content or ""):
|
||||
self.question_index[question_number].add(f"{section_filename}#{question_number}")
|
||||
self.question_index[question_number][section_ident].add(edition)
|
||||
|
||||
def __serialize_question_index(self) -> dict[str, list[str]]:
|
||||
serialized: dict[str, list[str]] = {}
|
||||
for question, links in sorted(self.question_index.items()):
|
||||
serialized[question] = sorted(links)
|
||||
def __serialize_question_index(self) -> dict[str, list[dict[str, list[str]]]]:
|
||||
serialized: dict[str, list[dict[str, list[str]]]] = {}
|
||||
for question, sections in sorted(self.question_index.items()):
|
||||
serialized[question] = [
|
||||
{
|
||||
"section": section,
|
||||
"editions": sorted(editions),
|
||||
}
|
||||
for section, editions in sorted(sections.items())
|
||||
]
|
||||
return serialized
|
||||
|
||||
def build_question_index(self):
|
||||
|
||||
Reference in New Issue
Block a user