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:
continue
img_tag["src"] = (
f"data:image/jpg;base64,{b64encode(img_data).decode()}"
)
img_tag[
"src"
] = f"data:image/jpg;base64,{b64encode(img_data).decode()}"
data[part["id"]] = tree.prettify()
@@ -46,13 +46,14 @@ id="copyright-license-image">
<section id="contents" class="toc">
<h1>Table of Contents</h1>
<ul>
{% for part_id in part_ids %}
{% for part_id in parts %}
<li><a href="#{{part_id}}"></a></li>
{% endfor %}
</ul>
</section>
{% for part_html in part_htmls %}
{{part_html | safe}}
{% for part_id in parts %}
{{parts[part_id] | safe}}
{% endfor %}
</div>
+2 -1
View File
@@ -15,7 +15,8 @@ def clean_tree(title: str, id: int, body: str) -> BeautifulSoup:
f"""
<h1 class="chapter-name" id={id}>{title}</h1>
<section class="chapter-body"></section>
"""
""",
parser="html.parser", # head/body tags aren't generated
)
insert_at = cast(Tag, new_soup.find("section"))