diff --git a/scripts/inject-chapter-navigation-footer b/scripts/inject-chapter-navigation-footer
index 63228bc7..45c9c296 100644
--- a/scripts/inject-chapter-navigation-footer
+++ b/scripts/inject-chapter-navigation-footer
@@ -31,6 +31,10 @@ spine_titles = [se.easy_xml.EasyXmlTree(open(file_path).read()).xpath("//head/ti
# Make list of dicts containing title and relative path for each file
chapter_links = [{"title": title, "path": path} for title, path in zip(spine_titles, rel_spine_paths)]
+# Create helper function for getting filename without extension
+def get_filename_without_extension(obj):
+ return os.path.splitext(obj["path"])[0] if obj else ""
+
# Create footers
for i, chapter_link in enumerate(chapter_links):
previousObj = chapter_links[i - 1] if i > 0 else None
@@ -38,11 +42,13 @@ for i, chapter_link in enumerate(chapter_links):
fileName = 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]]
+
with open(fileName, "r") as file:
chapter = file.read()
- previousLink = f"""Previous: {html.escape(previousObj["title"])}""" if previousObj else ""
- nextLink = f"""Next: {html.escape(nextObj["title"])}""" if nextObj else ""
+ previousLink = f"""Previous: {html.escape(previousObj["title"])}""" if previousObj else ""
+ nextLink = f"""Next: {html.escape(nextObj["title"])}""" if nextObj else ""
footer = f""
chapter = chapter.replace("