mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 06:40:33 -04:00
Remove extension from navigation footer links
This commit is contained in:
parent
c62ab2354f
commit
c6da28f878
1 changed files with 8 additions and 2 deletions
|
@ -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"""<a href="{book_url}/{previousObj["path"]}" rel="prev"><i>Previous:</i> {html.escape(previousObj["title"])}</a>""" if previousObj else ""
|
||||
nextLink = f"""<a href="{book_url}/{nextObj["path"]}" rel="next"><i>Next:</i> {html.escape(nextObj["title"])}</a>""" if nextObj else ""
|
||||
previousLink = f"""<a href="{book_url}/{previous_link_filename}" rel="prev"><i>Previous:</i> {html.escape(previousObj["title"])}</a>""" if previousObj else ""
|
||||
nextLink = f"""<a href="{book_url}/{next_link_filename}" rel="next"><i>Next:</i> {html.escape(nextObj["title"])}</a>""" if nextObj else ""
|
||||
|
||||
footer = f"<footer><ul><li>{previousLink}</li><li>{nextLink}</li></ul></footer>"
|
||||
chapter = chapter.replace("</body>", f"{footer}</body>")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue