-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Streamlined workflow. Now editing chapters in-place, with a script to…
… load them (+deps) into OPF spine/manifest. Misc. other changes.
- Loading branch information
vi
committed
Nov 1, 2013
1 parent
cf99066
commit e8a8d4f
Showing
12 changed files
with
108 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
dl: | ||
dl: clean | ||
wget -c -rnH -k -np http://www.feynmanlectures.caltech.edu/ | ||
|
||
macros: | ||
./bin/macros | ||
preprocess: | ||
./bin/macros < I_01.html > template/macros.tex | ||
./bin/chapters | xargs ./bin/preprocess | ||
|
||
concat: | ||
find * -maxdepth 0 -type f | grep -P 'I_\d+\.html' | xargs bin/concat > flp.html | ||
|
||
replace: macros concat | ||
./bin/replace flp.html | ||
|
||
preprocess: concat | ||
./bin/mxml flp.html | ||
|
||
epub: replace preprocess | ||
epub: preprocess | ||
cp -r ./template/epub/* . | ||
grep -oP '(?<=img src=")[^"]*(?=")' flp.html | xargs zip flp.epub mimetype META-INF/* content.opf flp.html | ||
./bin/opf content.opf | ||
(./bin/chapters; ./bin/images) | zip -@ flp.epub mimetype META-INF/* content.opf | ||
|
||
mobi: epub | ||
ebook-convert flp.epub flp.mobi | ||
|
||
convert: epub mobi | ||
|
||
clean: | ||
git clean -Xf | ||
git clean -Xfd | ||
|
||
all: dl convert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
find * -maxdepth 0 -type f | grep -P 'I_\d+\.html' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
./bin/chapters | xargs grep -hoP '(?<=img src=")[^"]*(?=")' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'nokogiri' | ||
require 'mime/types' | ||
|
||
class OPF | ||
attr_reader :xml | ||
def initialize path | ||
@xml = Nokogiri::XML File.read(path) | ||
end | ||
def add_chapter filename | ||
id, type, href = generics filename | ||
add_manifest id, type, href | ||
add_spine id | ||
end | ||
def add_image filename | ||
id, type, href = generics filename | ||
add_manifest id, type, href | ||
end | ||
private | ||
def generics filename | ||
id = filename.delete ?. | ||
type = MIME::Types.type_for(filename)[0].content_type | ||
href = filename | ||
return [id, type, href] | ||
end | ||
def add_manifest id, type, href | ||
item = @xml.create_element 'item', id: id, href: href, 'media-type' => type | ||
item.parent = @xml.at_css 'manifest' | ||
end | ||
def add_spine id | ||
itemref = @xml.create_element 'itemref', idref: id | ||
itemref.parent = @xml.at_css 'spine' | ||
end | ||
end | ||
|
||
opf = OPF.new(ARGV.first) | ||
IO.popen('./bin/chapters').map(&:chomp).each { |filename| opf.add_chapter filename } | ||
IO.popen('./bin/images').map(&:chomp).each { |filename| opf.add_image filename } | ||
File.write ARGV.first, opf.xml.to_xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'nokogiri' | ||
|
||
class Equation < String | ||
def to_image | ||
str = self.inspect[1..-2] | ||
bin = File.dirname(__FILE__) | ||
cmd = [bin, 'eq2img'].join('/') | ||
IO.popen([cmd, str]).read.chomp | ||
end | ||
def for_html | ||
['<img src="', self.to_image, '">'].join | ||
end | ||
end | ||
|
||
class String | ||
def slim | ||
html = self.to_html.css('.document').children | ||
html.css('footer').remove | ||
return html.to_html | ||
end | ||
def prettify | ||
html = self.to_html | ||
html.css('span.tag').each do |tag| | ||
tag.content = tag.content << ?\s | ||
end | ||
return html.to_html | ||
end | ||
def tex2png | ||
delimiters = [ | ||
/\\begin{equation\*?}.*?\\end{equation\*?}/m, | ||
/\\begin{align\*?}.*?\\end{align\*?}/m, | ||
/\$+.*?\$+/m | ||
] | ||
delimiters.each do |pattern| | ||
gsub!(pattern) do |equation| | ||
Equation.new(equation).for_html | ||
end | ||
end | ||
return self | ||
end | ||
def to_html | ||
Nokogiri::HTML self | ||
end | ||
end | ||
|
||
ARGV.each do |html| | ||
output = File.read(html).slim.prettify.tex2png | ||
File.write html, output | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
application/epub+zip |