fix(api): Iterate over parts dict in PDF Template

This commit is contained in:
TheOnlyWayUp
2025-06-09 23:47:30 +00:00
parent 86ae5eac21
commit ddfd0dc0a9
4 changed files with 11 additions and 8 deletions
+2 -1
View File
@@ -8,4 +8,5 @@ class StoryNotFoundError(WattpadError):
... ...
class PartNotFoundError(StoryNotFoundError): ... class PartNotFoundError(StoryNotFoundError):
...
+3 -3
View File
@@ -111,9 +111,9 @@ class PDFGenerator(AbstractGenerator):
if not img_data: if not img_data:
continue continue
img_tag["src"] = ( img_tag[
f"data:image/jpg;base64,{b64encode(img_data).decode()}" "src"
) ] = f"data:image/jpg;base64,{b64encode(img_data).decode()}"
data[part["id"]] = tree.prettify() data[part["id"]] = tree.prettify()
@@ -46,13 +46,14 @@ id="copyright-license-image">
<section id="contents" class="toc"> <section id="contents" class="toc">
<h1>Table of Contents</h1> <h1>Table of Contents</h1>
<ul> <ul>
{% for part_id in part_ids %} {% for part_id in parts %}
<li><a href="#{{part_id}}"></a></li> <li><a href="#{{part_id}}"></a></li>
{% endfor %} {% endfor %}
</ul> </ul>
</section> </section>
{% for part_html in part_htmls %} {% for part_id in parts %}
{{part_html | safe}}
{{parts[part_id] | safe}}
{% endfor %} {% endfor %}
</div> </div>
+2 -1
View File
@@ -15,7 +15,8 @@ def clean_tree(title: str, id: int, body: str) -> BeautifulSoup:
f""" f"""
<h1 class="chapter-name" id={id}>{title}</h1> <h1 class="chapter-name" id={id}>{title}</h1>
<section class="chapter-body"></section> <section class="chapter-body"></section>
""" """,
parser="html.parser", # head/body tags aren't generated
) )
insert_at = cast(Tag, new_soup.find("section")) insert_at = cast(Tag, new_soup.find("section"))