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 ![in progress](https://img.shields.io/badge/status-in--progress-orange)
|
||||||
|
|
||||||
![Book Cover](cover.jpg)
|
![Book Cover](cover.jpg)
|
||||||
|
|
||||||
|
|
25
generate.rb
25
generate.rb
|
@ -2,9 +2,15 @@ require 'nokogiri'
|
||||||
|
|
||||||
skip_classes = ['ebook-link-wrapper']
|
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')
|
for i in Dir.glob('html/*.html')
|
||||||
html = ""
|
html = ""
|
||||||
puts i
|
|
||||||
complete_html = Nokogiri::HTML(open(i))
|
complete_html = Nokogiri::HTML(open(i))
|
||||||
page = complete_html.css('.entry-content')
|
page = complete_html.css('.entry-content')
|
||||||
title = complete_html.css('.entry-title>a').inner_html[29..]
|
title = complete_html.css('.entry-title>a').inner_html[29..]
|
||||||
|
@ -14,22 +20,24 @@ for i in Dir.glob('html/*.html')
|
||||||
unless started
|
unless started
|
||||||
if e.class != Nokogiri::XML::Text
|
if e.class != Nokogiri::XML::Text
|
||||||
unless e.classes.include? 'frontmatter'
|
unless e.classes.include? 'frontmatter'
|
||||||
puts e.classes
|
|
||||||
started = true
|
started = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if started
|
if started
|
||||||
|
# we don't need any empty tags
|
||||||
trimmed = e.inner_text.gsub(/[[:space:]]/, '')
|
trimmed = e.inner_text.gsub(/[[:space:]]/, '')
|
||||||
if trimmed == "" and not ['hr'].include? e.name
|
if trimmed == ""
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
if e.name == "h3"
|
if e.name == "h3"
|
||||||
if e.inner_text.strip[0..7] == "Section" or e.inner_text.strip[0..12] == "Introduction"
|
if /Introduction/.match? e.inner_text
|
||||||
e.name = "h1"
|
e.name = "h2"
|
||||||
else
|
elsif /Section/.match? e.inner_text
|
||||||
|
next
|
||||||
|
elsif /Chapter/.match? e.inner_text
|
||||||
e.name = "h2"
|
e.name = "h2"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -47,8 +55,11 @@ for i in Dir.glob('html/*.html')
|
||||||
end
|
end
|
||||||
|
|
||||||
html = ""
|
html = ""
|
||||||
File.open("urls.txt").each do |url|
|
File.open("urls.txt").each_with_index do |url, index|
|
||||||
title = url.strip.split('/')[-1]
|
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 += File.read("chapters/#{title}.html")
|
||||||
html += "\n\n"
|
html += "\n\n"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue