mirror of
https://github.com/standardebooks/web.git
synced 2025-07-05 14:20:29 -04:00
Update variable names in navigation footer script
This commit is contained in:
parent
c6da28f878
commit
40b3ed1340
1 changed files with 11 additions and 11 deletions
|
@ -32,26 +32,26 @@ spine_titles = [se.easy_xml.EasyXmlTree(open(file_path).read()).xpath("//head/ti
|
||||||
chapter_links = [{"title": title, "path": path} for title, path in zip(spine_titles, rel_spine_paths)]
|
chapter_links = [{"title": title, "path": path} for title, path in zip(spine_titles, rel_spine_paths)]
|
||||||
|
|
||||||
# Create helper function for getting filename without extension
|
# Create helper function for getting filename without extension
|
||||||
def get_filename_without_extension(obj):
|
def get_filename_without_extension(dict_with_path):
|
||||||
return os.path.splitext(obj["path"])[0] if obj else ""
|
return os.path.splitext(dict_with_path["path"])[0] if dict_with_path else ""
|
||||||
|
|
||||||
# Create footers
|
# Create footers
|
||||||
for i, chapter_link in enumerate(chapter_links):
|
for i, chapter_link in enumerate(chapter_links):
|
||||||
previousObj = chapter_links[i - 1] if i > 0 else None
|
previous_dict = chapter_links[i - 1] if i > 0 else None
|
||||||
nextObj = chapter_links[i + 1] if i < len(chapter_links) - 1 else None
|
next_dict = chapter_links[i + 1] if i < len(chapter_links) - 1 else None
|
||||||
|
|
||||||
fileName = os.path.join(ebook_dir, "src/epub", chapter_link["path"])
|
file_path = os.path.join(ebook_dir, "src/epub", chapter_link["path"])
|
||||||
|
|
||||||
previous_link_filename, next_link_filename = [get_filename_without_extension(obj) for obj in [previousObj, nextObj]]
|
previous_link_filename, next_link_filename = [get_filename_without_extension(chapter_dict) for chapter_dict in [previous_dict, next_dict]]
|
||||||
|
|
||||||
with open(fileName, "r") as file:
|
with open(file_path, "r") as file:
|
||||||
chapter = file.read()
|
chapter = file.read()
|
||||||
|
|
||||||
previousLink = f"""<a href="{book_url}/{previous_link_filename}" rel="prev"><i>Previous:</i> {html.escape(previousObj["title"])}</a>""" if previousObj else ""
|
previous_link = f"""<a href="{book_url}/{previous_link_filename}" rel="prev"><i>Previous:</i> {html.escape(previous_dict["title"])}</a>""" if previous_dict else ""
|
||||||
nextLink = f"""<a href="{book_url}/{next_link_filename}" rel="next"><i>Next:</i> {html.escape(nextObj["title"])}</a>""" if nextObj else ""
|
next_link = f"""<a href="{book_url}/{next_link_filename}" rel="next"><i>Next:</i> {html.escape(next_dict["title"])}</a>""" if next_dict else ""
|
||||||
|
|
||||||
footer = f"<footer><ul><li>{previousLink}</li><li>{nextLink}</li></ul></footer>"
|
footer = f"<footer><ul><li>{previous_link}</li><li>{next_link}</li></ul></footer>"
|
||||||
chapter = chapter.replace("</body>", f"{footer}</body>")
|
chapter = chapter.replace("</body>", f"{footer}</body>")
|
||||||
|
|
||||||
with open(fileName, "w") as file:
|
with open(file_path, "w") as file:
|
||||||
file.write(chapter)
|
file.write(chapter)
|
Loading…
Add table
Add a link
Reference in a new issue