From d1aa4e68c128e8c86662bca1758df50537c99ceb Mon Sep 17 00:00:00 2001 From: Keith Fahlgren Date: Fri, 6 Feb 2009 04:57:22 +0000 Subject: [PATCH] Improve both SEO and semantic structure of chunked ePub output by ensuring that we always send out one and only one h1 in each XHTML chunk. DocBook::Epub - should include one and only one

in each HTML file in rendered ePub files for s - should include one and only one

in each HTML file in rendered ePub files for s even if they do not have section markup --- xsl/epub/bin/spec/epub_spec.rb | 48 +++++++++++ xsl/epub/docbook.xsl | 144 +++++++++++++++++++++++++++++++++ 2 files changed, 192 insertions(+) diff --git a/xsl/epub/bin/spec/epub_spec.rb b/xsl/epub/bin/spec/epub_spec.rb index 08c8bedac..8174feda0 100755 --- a/xsl/epub/bin/spec/epub_spec.rb +++ b/xsl/epub/bin/spec/epub_spec.rb @@ -230,6 +230,54 @@ describe DocBook::Epub do end end + it "should include one and only one

in each HTML file in rendered ePub files for s" do + begin + tmpdir = File.join(Dir::tmpdir(), "epubtoctest"); Dir.mkdir(tmpdir) rescue Errno::EEXIST + + epub = DocBook::Epub.new(File.join(@testdocsdir, "book.002.xml"), @tmpdir) + epubfile = File.join(tmpdir, "h1count.epub") + epub.render_to_file(epubfile, $DEBUG) + FileUtils.copy(epubfile, ".h1c.epub") if $DEBUG + + success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{epubfile}") + raise "Could not unzip #{epubfile}" unless success + glob = Dir.glob(File.join(tmpdir, "**", "*.html")) + glob.each {|html_file| + h1s = File.open(html_file).readlines.to_s.scan(/

e + raise e + ensure + FileUtils.rm_r(tmpdir, :force => true) + end + end + + it "should include one and only one

in each HTML file in rendered ePub files for s even if they do not have section markup" do + begin + tmpdir = File.join(Dir::tmpdir(), "epubtoctest"); Dir.mkdir(tmpdir) rescue Errno::EEXIST + + epub = DocBook::Epub.new(File.join(@testdocsdir, "book.002.xml"), @tmpdir) + epubfile = File.join(tmpdir, "h1count2.epub") + epub.render_to_file(epubfile, $DEBUG) + FileUtils.copy(epubfile, ".h1c2.epub") if $DEBUG + + success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{epubfile}") + raise "Could not unzip #{epubfile}" unless success + glob = Dir.glob(File.join(tmpdir, "**", "*.html")) + glob.each {|html_file| + h1s = File.open(html_file).readlines.to_s.scan(/

e + raise e + ensure + FileUtils.rm_r(tmpdir, :force => true) + end + end + it "should include a TOC link in rendered epub files for s" do begin tmpdir = File.join(Dir::tmpdir(), "epubtoctest"); Dir.mkdir(tmpdir) rescue Errno::EEXIST diff --git a/xsl/epub/docbook.xsl b/xsl/epub/docbook.xsl index 0739dadea..e20786c0d 100644 --- a/xsl/epub/docbook.xsl +++ b/xsl/epub/docbook.xsl @@ -1412,4 +1412,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 6 + + + + + + + + + + clear: both + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + 1 + + + + + + + 1 + 2 + 3 + 4 + 5 + + + + + + + + + + + + + + + + + + + + + + + + 6 + 5 + 4 + 3 + 2 + 1 + + + + + title + + + + + + + + + + + + -- 2.40.0