Fix list tables figures (#305)

* Add links

* Fix list of tables/flowcharts

Fixes the order and adds missing link
This commit is contained in:
Hendrik Kleinwaechter
2023-12-12 11:48:12 +01:00
committed by GitHub
parent 0b550a4666
commit 89f5ab6be3
2 changed files with 32 additions and 3 deletions

View File

@@ -76,7 +76,7 @@ class ModifyBuild
end
def is_list_figures_tables?(filename)
["listfigurename.html", "listtablename.html", "listoflocname.html"].any? do |name|
["listfigurename.html", "listtablename.html", "listoflocname.html", "bibname.html"].any? do |name|
filename.include?(name)
end
end
@@ -245,7 +245,9 @@ class ModifyBuild
# Users are lost and can't easily access the root page of the book. This
# adds a home menu item.
def add_home_link_to_menu(text)
doc = build_doc(text)
# Remove duplicate menu entries first before building clean menu
doc = build_doc(remove_duplicate_entries_menu(text))
menu = doc.css(".menu-items")[0]
return text if menu.nil?
@@ -260,6 +262,21 @@ class ModifyBuild
<span class="link_text">List of Flowcharts</span>
</a>
</span>
<span class="chapterToc">
<a href="listtablename.html">
<span class="link_text">List of Tables</span>
</a>
</span>
<span class="chapterToc">
<a href="listfigurename.html">
<span class="link_text">List of Figures</span>
</a>
</span>
<span class="chapterToc">
<a href="bibname.html">
<span class="link_text">Bibliography</span>
</a>
</span>
<span class="chapterToc">
<a href="https://breadco.de/kofi">
<span class="chapter_number">⭐️</span>
@@ -277,6 +294,18 @@ class ModifyBuild
doc.to_html
end
# Some of the menu links are added in the wrong order. Remove them since we
# later on add them in the structure that we want.
def remove_duplicate_entries_menu(text)
doc = build_doc(text)
remove = ["List of Tables", "List of Figures"]
selected_elements = doc.css(".menu-items .chapterToc > a").select do |el|
remove.include?(el.text)
end
selected_elements.each(&:remove)
doc.to_html
end
# Some of the links in the menu have an anchor. This makes clicking through
# the menu frustrating as the browser jumps a lot on each request. Only do
# this for the top level menu entries though.