Fix section headers
This commit is contained in:
parent
69ec2870f6
commit
e27c471172
|
@ -1,4 +1,4 @@
|
|||
# Never Say You Can’t Survive
|
||||
# Never Say You Can’t Survive 
|
||||
|
||||

|
||||
|
||||
|
|
25
generate.rb
25
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 += "<h1>#{section_headers[index]}</h1>\n\n"
|
||||
end
|
||||
html += File.read("chapters/#{title}.html")
|
||||
html += "\n\n"
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue