Fix titles (#146)

This fixes the default auto generated LaTeX titles for the website
This commit is contained in:
Hendrik Kleinwaechter
2023-07-13 15:39:42 +02:00
committed by GitHub
parent 1ac6c7b196
commit aa78d322d5
2 changed files with 30 additions and 1 deletions

View File

@@ -227,7 +227,6 @@ website:
rm -rf $(WEBSITE_DIR)
make4ht -c website.cfg -a debug -uf html5+tidy+common_domfilters+dvisvgm_hashes -d $(WEBSITE_DIR) book.tex
cp $(WEBSITE_DIR)/book.html $(WEBSITE_DIR)/index.html
sed -r -i -e 's|<title></title>|<title>The Sourdough Framework</title>|g' $(WEBSITE_DIR)/index.html
# Debug Stuff from now on
.PHONY: show_tools_version

View File

@@ -29,6 +29,7 @@ class ModifyBuild
orig_text = File.read(filename)
text = fix_double_slashes(orig_text)
text = fix_navigation_bar(text)
text = fix_titles(text)
File.open(filename, "w") {|file| file.puts text }
end
@@ -79,6 +80,35 @@ class ModifyBuild
end
doc.to_html
end
def fix_titles(text)
doc = Nokogiri::HTML(text)
title_node = doc.css("title")[0]
raise ArgumentError.new("No title found in HTML document") if title_node.nil?
title_node.content = build_title(title_node.content)
doc.to_html
end
# "3 Making a sourdough starter"
# Should return Making a sourdough starter - The Sourdough Framework"
def build_title(title)
# No title, happens on index page in LaTeX build
return title_appendix if title.length == 0
# Starts with number
if title[0].to_i > 0
use_title = title.split(" ").drop(1).join(" ")
else
use_title = title
end
"#{use_title} - #{title_appendix}"
end
def title_appendix
"The Sourdough Framework"
end
end
ModifyBuild.build