mirror of
https://github.com/hendricius/the-sourdough-framework
synced 2025-11-28 22:03:58 -06:00
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:
@@ -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
|
||||
|
||||
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user