Make audax happy, add anchors to glossary terms (#343)

* Add .DS_Store to ignore for Mac users

* Permalinks to glossary terms
This commit is contained in:
Anthony Atkinson
2024-03-20 04:37:18 -04:00
committed by GitHub
parent a3e94d26d6
commit 4665d88241
3 changed files with 26 additions and 0 deletions

View File

@@ -5,6 +5,8 @@ GEM
method_source (1.0.0)
nokogiri (1.15.3-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.3-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.15.3-x86_64-linux)
racc (~> 1.4)
pry (0.14.2)
@@ -14,6 +16,7 @@ GEM
PLATFORMS
arm64-darwin-22
x86_64-darwin-22
x86_64-linux
DEPENDENCIES

View File

@@ -65,6 +65,7 @@ class ModifyBuild
text = fix_list_of_tables_figures_duplicates(text)
text = add_anchors_to_headers(text)
text = fix_https_links(text)
text = add_anchors_to_glossary_items(text) if is_glossary_page?(filename)
text = fix_menus_list_figures_tables(text) if is_list_figures_tables?(filename)
text = fix_list_of_figures_tables_display(text) if is_list_figures_tables?(filename)
File.open(filename, "w:UTF-8") {|file| file.puts text }
@@ -76,6 +77,10 @@ class ModifyBuild
end
end
def is_glossary_page?(filename)
filename.include?("Glossary.html")
end
def is_list_figures_tables?(filename)
["listfigurename.html", "listtablename.html", "listoflocname.html", "bibname.html"].any? do |name|
filename.include?(name)
@@ -499,6 +504,23 @@ class ModifyBuild
doc.to_html
end
def add_anchors_to_glossary_items(text)
doc = build_doc(text)
content = doc.css("dt.description")
content.each do |el|
term = el.css("span")[0]
item_name = term&.text
# No anchor for whatever reason
next unless item_name
anchor = item_name.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
copy_link = %Q{<a href="#term-#{anchor}" class="permalink">🔗</a>}
el.set_attribute("id", "term-#{anchor}")
term.inner_html = "#{term.inner_html}#{copy_link}"
end
doc.to_html
end
def build_cover_page_content
%Q{
<h2 class="chapterHead home-title">