From aa78d322d5149fd82ce2aa2d7a3c3a94ec34fac4 Mon Sep 17 00:00:00 2001 From: Hendrik Kleinwaechter Date: Thu, 13 Jul 2023 15:39:42 +0200 Subject: [PATCH] Fix titles (#146) This fixes the default auto generated LaTeX titles for the website --- book/makefile | 1 - website/modify_build.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/book/makefile b/book/makefile index 95384ab..131c049 100644 --- a/book/makefile +++ b/book/makefile @@ -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||The Sourdough Framework|g' $(WEBSITE_DIR)/index.html # Debug Stuff from now on .PHONY: show_tools_version diff --git a/website/modify_build.rb b/website/modify_build.rb index 42d7dee..4a86cbe 100644 --- a/website/modify_build.rb +++ b/website/modify_build.rb @@ -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