diff --git a/README.md b/README.md index fef3326..8eed1a6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Never Say You Can’t Survive +# Never Say You Can’t Survive ![in progress](https://img.shields.io/badge/status-in--progress-orange) ![Book Cover](cover.jpg) diff --git a/generate.rb b/generate.rb index 4b3b572..ba7aca7 100644 --- a/generate.rb +++ b/generate.rb @@ -2,9 +2,15 @@ require 'nokogiri' skip_classes = ['ebook-link-wrapper'] +section_headers = [] + +section_headers[0] = "Section I - Introduction" +section_headers[4] = "Section II - What’s A Story, and How Do You Find One?" +section_headers[10] = "Section III - Your Feelings are Valid—and Powerful" +section_headers[15] = "Section IV - What We Write About When We Write About Spaceships" + for i in Dir.glob('html/*.html') html = "" - puts i complete_html = Nokogiri::HTML(open(i)) page = complete_html.css('.entry-content') title = complete_html.css('.entry-title>a').inner_html[29..] @@ -14,22 +20,24 @@ for i in Dir.glob('html/*.html') unless started if e.class != Nokogiri::XML::Text unless e.classes.include? 'frontmatter' - puts e.classes started = true end end end if started + # we don't need any empty tags trimmed = e.inner_text.gsub(/[[:space:]]/, '') - if trimmed == "" and not ['hr'].include? e.name + if trimmed == "" next end if e.name == "h3" - if e.inner_text.strip[0..7] == "Section" or e.inner_text.strip[0..12] == "Introduction" - e.name = "h1" - else + if /Introduction/.match? e.inner_text + e.name = "h2" + elsif /Section/.match? e.inner_text + next + elsif /Chapter/.match? e.inner_text e.name = "h2" end end @@ -47,8 +55,11 @@ for i in Dir.glob('html/*.html') end html = "" -File.open("urls.txt").each do |url| +File.open("urls.txt").each_with_index do |url, index| title = url.strip.split('/')[-1] + unless section_headers[index].nil? + html += "

#{section_headers[index]}

\n\n" + end html += File.read("chapters/#{title}.html") html += "\n\n" end