Skip to content

Commit

Permalink
fix(epub-serializer): return serialized epub path
Browse files Browse the repository at this point in the history
  • Loading branch information
10zinten committed Oct 8, 2020
1 parent 25fba24 commit 7d3e8a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions openpecha/serializers/epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ def serialize(self, output_path="./output/epub_output"):
pecha_id (string): Pecha id that needs to be exported in other format
"""
output_path = Path(output_path)
pecha_id = self.opf_path.name.split(".")[0]
out_fn = f"{pecha_id}.html"
out_html_fn = f"{pecha_id}.html"
try:
pecha_title = self.meta["ebook_metadata"]["title"]
except KeyError:
Expand All @@ -143,7 +144,7 @@ def serialize(self, output_path="./output/epub_output"):
f"<html>\n<head>\n\t<title>{pecha_title}</title>\n</head>\n<body>\n"
)
results += f"{result}</body>\n</html>"
Path(out_fn).write_text(results)
Path(out_html_fn).write_text(results)
# Downloading css template file from ebook template repo and saving it
template = requests.get(
"https://raw.githubusercontent.com/OpenPecha/ebook-template/master/tsadra_template.css"
Expand All @@ -157,9 +158,12 @@ def serialize(self, output_path="./output/epub_output"):
font_size = 15
chapter_mark = "pagebreak"
cover_path = self.opf_path / f"asset/image/{cover_image}"
out_epub_fn = output_path / f"{pecha_id}.epub"
os.system(
f'ebook-convert {out_fn} {output_path}/{pecha_id}.epub --extra-css=./template.css --chapter={chapter_Xpath} --chapter-mark="{chapter_mark}" --base-font-size={font_size} --embed-font-family="{font_family}" --cover={cover_path}'
f'ebook-convert {out_html_fn} {out_epub_fn} --extra-css=./template.css --chapter={chapter_Xpath} --chapter-mark="{chapter_mark}" --base-font-size={font_size} --embed-font-family="{font_family}" --cover={cover_path}'
)
# Removing html file and template file
os.system(f"rm {out_fn}")
os.system(f"rm {out_html_fn}")
os.system("rm template.css")

return out_epub_fn
3 changes: 2 additions & 1 deletion tests/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ def test_hfml_serializer():
def test_hfml_2_tsadra_serializer(opf_path):
serializer = EpubSerializer(opf_path)
serializer.apply_layers()
serializer.serialize()
out_fn = serializer.serialize()
assert str(out_fn) == "output/epub_output/P000100.epub"

0 comments on commit 7d3e8a9

Please sign in to comment.