From 44a1b737c9c57e651904fd3cd9426a6a9687d1ac Mon Sep 17 00:00:00 2001 From: "Prof. Dr. Matthias Jung DL9MJ" Date: Sun, 25 May 2025 23:02:27 +0200 Subject: [PATCH 1/7] feature: add course index --- src/build.py | 27 ++++++++++++++++++++++++++- templates/html/chapter.html | 2 +- templates/html/course_index.html | 9 +++++++++ templates/html/section.html | 2 +- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 templates/html/course_index.html diff --git a/src/build.py b/src/build.py index 176bc6b..4cf3850 100644 --- a/src/build.py +++ b/src/build.py @@ -113,6 +113,7 @@ class Build: with open(f'build/{edition}_chapter_{chapter["ident"]}.html', 'w') as file: result = chapter_template.render( edition=edition, + name=self.__edition_name(edition), number=number, chapter=chapter, ) @@ -139,6 +140,7 @@ class Build: result = section_template.render( edition=edition, + name=self.__edition_name(edition), section=section, chapter=chapter, ) @@ -158,12 +160,35 @@ class Build: result = BeautifulSoup(result, "html.parser").prettify() file.write(result) + def __edition_name(self, edition): + edition_names = { + "N" : "Gesamtkurs N", + "E" : "Aufbaukurs N -> E", + "A" : "Aufbaukurs E -> A", + "NE" : "Gesamtkurs N + E", + "EA" : "Aufbaukurs N -> A", + "NEA" : "Gesamtkurs A", + } + return edition_names[edition] + + def __build_index(self, edition, book): + template = self.env.get_template("course_index.html") + with open(f"build/{edition}_course_index.html", "w") as file: + result = template.render( + titel=self.__edition_name(edition), + abstract="", #TODO we can add this later + book=book, + ) + result = self.__build_page(result) + result = BeautifulSoup(result, "html.parser").prettify() + file.write(result) + def build_edition(self, edition): edition = edition.upper() with open(f'data/book_{edition}.json') as f: book = json.load(f) - + self.__build_index(edition, book) for number, chapter in enumerate(tqdm(book, desc=f"Build Edition: {edition}"),1): next_chapter = book[number] if number < len(book) else None self.__build_chapter(edition, number, chapter, next_chapter) diff --git a/templates/html/chapter.html b/templates/html/chapter.html index 4cb0218..7dafed6 100644 --- a/templates/html/chapter.html +++ b/templates/html/chapter.html @@ -10,7 +10,7 @@ diff --git a/templates/html/course_index.html b/templates/html/course_index.html new file mode 100644 index 0000000..8ab819f --- /dev/null +++ b/templates/html/course_index.html @@ -0,0 +1,9 @@ +

{{ titel }}

+

{{ abstract }}

+
+ {% for chapter in book %} + + {{loop.index}}{{ chapter["title"]}} + + {% endfor %} +
\ No newline at end of file diff --git a/templates/html/section.html b/templates/html/section.html index 63db3e0..d3f2683 100644 --- a/templates/html/section.html +++ b/templates/html/section.html @@ -10,7 +10,7 @@ -

{{ section["title"] }} (Klasse {{ section["class"] }})

+

{{ section["title"] }}

{{ section["content"] }} \ No newline at end of file From b2cb344acfb38a81dd3cb5612fcfb7a97fbfba70 Mon Sep 17 00:00:00 2001 From: "Prof. Dr. Matthias Jung DL9MJ" Date: Sun, 25 May 2025 23:31:18 +0200 Subject: [PATCH 3/7] refactor: renamed function --- src/build.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/build.py b/src/build.py index 4cf3850..1310dba 100644 --- a/src/build.py +++ b/src/build.py @@ -171,13 +171,14 @@ class Build: } return edition_names[edition] - def __build_index(self, edition, book): + def __build_book_index(self, edition, book): template = self.env.get_template("course_index.html") with open(f"build/{edition}_course_index.html", "w") as file: result = template.render( titel=self.__edition_name(edition), abstract="", #TODO we can add this later book=book, + edition=edition, ) result = self.__build_page(result) result = BeautifulSoup(result, "html.parser").prettify() @@ -188,7 +189,7 @@ class Build: with open(f'data/book_{edition}.json') as f: book = json.load(f) - self.__build_index(edition, book) + self.__build_book_index(edition, book) for number, chapter in enumerate(tqdm(book, desc=f"Build Edition: {edition}"),1): next_chapter = book[number] if number < len(book) else None self.__build_chapter(edition, number, chapter, next_chapter) From ab9918eea745258da7202f89ba406911e3e84aa6 Mon Sep 17 00:00:00 2001 From: "Prof. Dr. Matthias Jung DL9MJ" Date: Sun, 25 May 2025 23:31:37 +0200 Subject: [PATCH 4/7] fix: video url --- templates/html/chapter.html | 2 +- templates/html/section.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/html/chapter.html b/templates/html/chapter.html index 7dafed6..969f08f 100644 --- a/templates/html/chapter.html +++ b/templates/html/chapter.html @@ -1,6 +1,6 @@
- {% if chapter.video_url %} + {% if chapter["video_url"] %} {% endif %} diff --git a/templates/html/section.html b/templates/html/section.html index 99436de..82d0504 100644 --- a/templates/html/section.html +++ b/templates/html/section.html @@ -1,6 +1,6 @@
- {% if section.video_url %} + {% if section["video_url"] %} {% endif %} From d3a554ea1d7e8be4a65b3c3e4677779bdcd74039 Mon Sep 17 00:00:00 2001 From: "Prof. Dr. Matthias Jung DL9MJ" Date: Sun, 25 May 2025 23:31:55 +0200 Subject: [PATCH 5/7] fix: link for chapter --- templates/html/course_index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/html/course_index.html b/templates/html/course_index.html index 8ab819f..00974a7 100644 --- a/templates/html/course_index.html +++ b/templates/html/course_index.html @@ -2,7 +2,7 @@

{{ abstract }}

{% for chapter in book %} - + {{loop.index}}{{ chapter["title"]}} {% endfor %} From e1d7113a96cc4c6d5fbc6d204300df2c7898e5ea Mon Sep 17 00:00:00 2001 From: "Prof. Dr. Matthias Jung DL9MJ" Date: Tue, 27 May 2025 21:09:44 +0200 Subject: [PATCH 6/7] feature: load edition metadata from directus --- src/build.py | 38 +++++++++++--------------------- src/download.py | 9 +++++++- templates/html/course_index.html | 8 +++---- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/build.py b/src/build.py index 1310dba..f5aa932 100644 --- a/src/build.py +++ b/src/build.py @@ -107,13 +107,13 @@ class Build: shutil.copyfile(src, dst) # cached - def __build_chapter(self, edition, number, chapter, next_chapter=None): + def __build_chapter(self, edition, edition_name, number, chapter, next_chapter=None): chapter_template = self.env.get_template("chapter.html") next_chapter_template = self.env.get_template("next_chapter.html") with open(f'build/{edition}_chapter_{chapter["ident"]}.html', 'w') as file: result = chapter_template.render( edition=edition, - name=self.__edition_name(edition), + name=edition_name, number=number, chapter=chapter, ) @@ -129,7 +129,7 @@ class Build: file.write(result) # cached - def __build_section(self, edition, section, chapter, next_section=None, next_chapter=None): + def __build_section(self, edition, edition_name, section, chapter, next_section=None, next_chapter=None): section_template = self.env.get_template("section.html") next_section_template = self.env.get_template("next_section.html") next_chapter_template = self.env.get_template("next_chapter.html") @@ -140,7 +140,7 @@ class Build: result = section_template.render( edition=edition, - name=self.__edition_name(edition), + name=edition_name, section=section, chapter=chapter, ) @@ -160,25 +160,11 @@ class Build: result = BeautifulSoup(result, "html.parser").prettify() file.write(result) - def __edition_name(self, edition): - edition_names = { - "N" : "Gesamtkurs N", - "E" : "Aufbaukurs N -> E", - "A" : "Aufbaukurs E -> A", - "NE" : "Gesamtkurs N + E", - "EA" : "Aufbaukurs N -> A", - "NEA" : "Gesamtkurs A", - } - return edition_names[edition] - - def __build_book_index(self, edition, book): + def __build_book_index(self, book): template = self.env.get_template("course_index.html") - with open(f"build/{edition}_course_index.html", "w") as file: + with open(f"build/{book['edition']}_course_index.html", "w") as file: result = template.render( - titel=self.__edition_name(edition), - abstract="", #TODO we can add this later book=book, - edition=edition, ) result = self.__build_page(result) result = BeautifulSoup(result, "html.parser").prettify() @@ -189,14 +175,16 @@ class Build: with open(f'data/book_{edition}.json') as f: book = json.load(f) - self.__build_book_index(edition, book) - for number, chapter in enumerate(tqdm(book, desc=f"Build Edition: {edition}"),1): - next_chapter = book[number] if number < len(book) else None - self.__build_chapter(edition, number, chapter, next_chapter) + chapters = book["chapters"] + edition_name = book["title"] + self.__build_book_index(book) + for number, chapter in enumerate(tqdm(chapters, desc=f"Build Edition: {edition}"),1): + next_chapter = chapters[number] if number < len(chapters) else None + self.__build_chapter(edition, edition_name, number, chapter, next_chapter) for i, section in enumerate(chapter["sections"],1) : next_section = chapter["sections"][i] if i < len(chapter["sections"]) else None - self.__build_section(edition, section, chapter, next_section, next_chapter) + self.__build_section(edition, edition_name, section, chapter, next_section, next_chapter) def build_assets(self): shutil.copytree("assets", "build/assets", dirs_exist_ok=True) \ No newline at end of file diff --git a/src/download.py b/src/download.py index 39aaa11..bfba13c 100644 --- a/src/download.py +++ b/src/download.py @@ -52,8 +52,15 @@ class Download: } ) + out_edition = { + "title": in_edition["title"], + "abstract": in_edition["abstract"], + "chapters": out_chapters, + "edition": edition, + } + with open("data/book_" + edition + ".json", "w", encoding="utf-8") as file: - json.dump(out_chapters, file, ensure_ascii=False, indent=4) + json.dump(out_edition, file, ensure_ascii=False, indent=4) def download_question_metadata(self): questions = self.api.get( diff --git a/templates/html/course_index.html b/templates/html/course_index.html index 00974a7..ed72850 100644 --- a/templates/html/course_index.html +++ b/templates/html/course_index.html @@ -1,8 +1,8 @@ -

{{ titel }}

-

{{ abstract }}

+

{{ book["title"] }}

+

{{ book["abstract"] }}

- {% for chapter in book %} - + {% for chapter in book["chapters"] %} + {{loop.index}}{{ chapter["title"]}} {% endfor %} From 4c70bba219893a602889e689f1d8e4e655c8bd57 Mon Sep 17 00:00:00 2001 From: "Prof. Dr. Matthias Jung DL9MJ" Date: Tue, 27 May 2025 21:15:35 +0200 Subject: [PATCH 7/7] fix: corrected key name for video URL --- src/download.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/download.py b/src/download.py index bfba13c..72f37b4 100644 --- a/src/download.py +++ b/src/download.py @@ -47,7 +47,7 @@ class Download: "class": in_section["class"], "content": in_section["content"], "slide": in_section["slide"], - "video": in_section["video_url"], + "video_url": in_section["video_url"], "questions": [], } )