Skip to content

Commit

Permalink
Style fixes in EPUB
Browse files Browse the repository at this point in the history
- Fixes #4
  • Loading branch information
captn3m0 committed Sep 27, 2017
1 parent 4df2ca0 commit 46e302c
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 194 deletions.
8 changes: 4 additions & 4 deletions edgedancer-reread.rb
Expand Up @@ -8,10 +8,10 @@
BASE = 'https://www.tor.com/'.freeze

links = [
"2017/08/24/edgedancer-reread-chapter-1/",
"2017/08/31/edgedancer-reread-chapter-2/",
"2017/09/07/edgedancer-reread-chapters-3-and-4/",
"2017/09/14/edgedancer-reread-chapters-5-and-6/"
'2017/08/24/edgedancer-reread-chapter-1/',
'2017/08/31/edgedancer-reread-chapter-2/',
'2017/09/07/edgedancer-reread-chapters-3-and-4/',
'2017/09/14/edgedancer-reread-chapters-5-and-6/'
]

episode = 1
Expand Down
48 changes: 24 additions & 24 deletions methods.rb
Expand Up @@ -4,7 +4,7 @@ module XML
class Node
def class?(*classes)
present = false
if self.attribute('class')
if attribute('class')
present = true
classes.each do |klass|
present &&= self['class'].include? klass
Expand Down Expand Up @@ -32,26 +32,26 @@ def format_match(format, format_to_match)
[:all, format_to_match].include? format
end

def gen_epub(name, _format)
if format_match(_format, :epub)
begin
require "paru/pandoc"
Paru::Pandoc.new do
from "html"
to "epub"
epub_metadata "metadata/#{name}.xml"
epub_cover_image "covers/#{name}.jpg"
output "books/#{name}.epub"
end.convert File.read("books/#{name}.html")
puts '[epub] Generated EPUB file'
rescue LoadError
puts "[error] Can't generate EPUB without paru"
end
def gen_epub(name, format)
return unless format_match(format, :epub)
begin
require 'paru/pandoc'
Paru::Pandoc.new do
from 'html'
to 'epub'
epub_metadata "metadata/#{name}.xml"
epub_cover_image "covers/#{name}.jpg"
epub_stylesheet "style.css"
output "books/#{name}.epub"
end.convert File.read("books/#{name}.html")
puts '[epub] Generated EPUB file'
rescue LoadError
puts "[error] Can't generate EPUB without paru"
end
end

def gen_mobi(name, _format)
if command?('ebook-convert') && format_match(_format, :mobi)
def gen_mobi(name, format)
if command?('ebook-convert') && format_match(format, :mobi)
# Convert epub to a mobi
`ebook-convert books/#{name}.epub books/#{name}.mobi`

This comment has been minimized.

Copy link
@kakaroto

kakaroto Sep 27, 2017

Contributor

Does this mean mobi depends on epub? so enabling ":mobi" format only would either fail, or continually convert an older/outdated epub file ?

This comment has been minimized.

Copy link
@captn3m0

captn3m0 Sep 27, 2017

Author Owner

Yeah, just mobi would be broken right now. Will switch format_match so that mobi -> epub+mobi

This comment has been minimized.

Copy link
@kakaroto

kakaroto Sep 27, 2017

Contributor

Ok! I think it should be "epub -> epub/mobi" rather than "mobi -> epub+mobi" so if someone only activates mobi, it will also activate epub, instead of doing nothing.

This comment has been minimized.

Copy link
@captn3m0

captn3m0 Sep 27, 2017

Author Owner

Yeah, you're right.

puts '[mobi] Generated MOBI file'
Expand All @@ -60,8 +60,8 @@ def gen_mobi(name, _format)
end
end

def gen_pdf(name, _format)
if commands?(%w[pandoc convert wkhtmltopdf pdftk]) && format_match(_format, :pdf)
def gen_pdf(name, format)
if commands?(%w[pandoc convert wkhtmltopdf pdftk]) && format_match(format, :pdf)
# Generate PDF as well
# First, lets make a better css version of the html
`pandoc books/#{name}.html -s -c ../style.css -o books/#{name}_pdf.html`
Expand All @@ -79,8 +79,8 @@ def gen_pdf(name, _format)
end
end

def generate(name, _format = :all)
gen_epub(name, _format)
gen_mobi(name, _format)
gen_pdf(name, _format)
def generate(name, format = :all)
gen_epub(name, format)
gen_mobi(name, format)
gen_pdf(name, format)
end
16 changes: 8 additions & 8 deletions oathbringer.rb
Expand Up @@ -12,7 +12,7 @@
'09/05/oathbringer-by-brandon-sanderson-chapters-4-6/'
]

manually_add_links = false;
manually_add_links = false

if manually_add_links
# Only downloads links already added to array <links>
Expand All @@ -25,17 +25,17 @@
# Automatically adds all recent chapters
puts 'Downloading all found links'
chapter = Integer(links.last.split('-').last.gsub(/[^0-9]/, '')) + 1
next_date = Date.new(1970,01,01)
next_date = Date.new(1970, 1, 1)
loop do
links.last.split('/')
month = links.last.split('/').first
day = links.last.split('/')[1]
next_date = Date.new(2017, month.to_i, day.to_i) + 7
links << "#{next_date.strftime("%m")}/#{next_date.strftime("%d")}/oathbringer-by-brandon-sanderson-chapters-#{chapter}-#{chapter + 2}/"
chapter += 3;
links << "#{next_date.strftime('%m')}/#{next_date.strftime('%d')}/oathbringer-by-brandon-sanderson-chapters-#{chapter}-#{chapter + 2}/"
chapter += 3
break if next_date + 7 > Date.today
end
next_date += 7;
end
next_date += 7
end

episode = 1
Expand Down Expand Up @@ -65,12 +65,12 @@
e.remove if !start || ending
end
html += page.inner_html
url = links[i - 1]
url = BASE + links[i - 1]

html += "<p>Visit <a href='#{url}'>tor.com</a> for discussion.</p>"
end

html += "<p>~fin\~<br>Next 3 chapters out on #{next_date}</p>"
html += "<p>Next 3 chapters out on #{next_date}</p>"

File.open('books/Oathbringer.html', 'w') { |file| file.write(html) }
puts '[html] Generated HTML file'
Expand Down

0 comments on commit 46e302c

Please sign in to comment.