Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

move mobi generation to kindlegen

  • Loading branch information...
commit bf70699536b075431741cbe8fafe4f5b3f9ab080 1 parent 4881bfe
@schacon schacon authored
View
4 TODO.txt
@@ -1,11 +1,13 @@
To-Do List
=============
-* generate hashes for generated assets and do not regenerate them unneccesarily
+* git-init after git scribe init
+
* custom site layouts
* custom/alternate themes (stylesheets)
* cover page for site (author, about, etc)
* book cover (w/template)
+* generate hashes for generated assets and do not regenerate them unneccesarily
* book search
* math formula
View
3  git-scribe.gemspec
@@ -1,4 +1,5 @@
$LOAD_PATH.unshift 'lib'
+require 'git-scribe/version'
files = `git ls-files`.
split("\n").
@@ -9,7 +10,7 @@ puts files
# piece file back together and write...
Gem::Specification.new do |s|
s.name = "git-scribe"
- s.version = "0.0.8"
+ s.version = GitScribe::VERSION
s.date = Time.now.strftime('%Y-%m-%d')
s.summary = "git-scribe is an authors toolkit for writing and publishing books"
s.homepage = "http://github.com/schacon/git-scribe"
View
2  lib/git-scribe.rb
@@ -1,6 +1,7 @@
require 'rubygems'
require 'nokogiri'
require 'liquid'
+require 'yaml'
require 'git-scribe/generate'
require 'git-scribe/check'
@@ -26,6 +27,7 @@ def initialize
@subcommand = nil
@args = []
@options = {}
+ @config = YAML::parse(File.open(local('.gitscribe'))).transform rescue {}
end
## COMMANDS ##
View
28 lib/git-scribe/check.rb
@@ -7,28 +7,28 @@ def check(args = [])
# check for asciidoc
if !check_can_run('asciidoc')
info "asciidoc is not present, please install it for anything to work"
- status[:asciidoc] = true
+ status[:asciidoc] = false
else
info "asciidoc - ok"
- status[:asciidoc] = false
+ status[:asciidoc] = true
end
# check for xsltproc
if !check_can_run('xsltproc --version')
info "xsltproc is not present, please install it for html generation"
- status[:xsltproc] = true
+ status[:xsltproc] = false
else
info "xsltproc - ok"
- status[:xsltproc] = false
+ status[:xsltproc] = true
end
# check for a2x - should be installed with asciidoc, but you never know
if !check_can_run('a2x')
info "a2x is not present, please install it for epub generation"
- status[:a2x] = true
+ status[:a2x] = false
else
info "a2x - ok"
- status[:a2x] = false
+ status[:a2x] = true
end
# check for source-highlight
@@ -44,19 +44,19 @@ def check(args = [])
# check for fop
if !check_can_run('fop -version')
info "fop is not present, please install for PDF generation"
- status[:fop] = true
+ status[:fop] = false
else
info "fop - ok"
- status[:fop] = false
+ status[:fop] = true
end
- # check for calibre
- if !check_can_run('ebook-convert --version')
- info "calibre is not present, please install for mobi generation"
- status[:calibre] = true
+ # check for kindlegen
+ if !check_can_run('kindlegen')
+ info "kindlegen is not present, please install for mobi generation"
+ status[:mobi] = false
else
- info "calibre - ok"
- status[:calibre] = false
+ info "kindlegen - ok"
+ status[:mobi] = true
end
View
112 lib/git-scribe/generate.rb
@@ -84,11 +84,9 @@ def do_epub
def do_mobi
do_html
info "GENERATING MOBI"
- # --cover 'cover.png'
- # --authors 'Author Name'
- # --comments "licensed under CC"
- # --language 'en'
- cmd = "ebook-convert book.html book.mobi --level1-toc '//h:h1' --level2-toc '//h:h2' --level3-toc '//h:h3'"
+ generate_toc_files
+ # generate book.opf
+ cmd = "kindlegen -verbose book.opf -o book.mobi"
if ex(cmd)
'book.mobi'
end
@@ -163,9 +161,8 @@ def do_site
files = Dir.glob(template_dir + '/*')
FileUtils.cp_r files, '.'
- Liquid::Template.file_system = Liquid::LocalFileSystem.new(template_dir)
- index_template = Liquid::Template.parse(File.read(File.join(template_dir, 'index.html')))
- page_template = Liquid::Template.parse(File.read(File.join(template_dir, 'page.html')))
+ index_template = liquid_template('index.html')
+ page_template = liquid_template('page.html')
# write the index page
main_data = {
@@ -231,6 +228,105 @@ def do_site
sections
end
+ def generate_toc_files
+ # read book table of contents
+ toc = []
+ source = File.read("book.html")
+
+ # get the book title
+ book_title = 'Title'
+ if t = /\<title>(.*?)<\/title\>/.match(source)
+ book_title = t[0]
+ end
+
+ source.scan(/\<h([2|3]) id=\"(.*?)\"\>(.*?)\<\/h[2|3]\>/).each do |header|
+ sec = {'id' => header[1], 'name' => header[2]}
+ if header[0] == '2'
+ toc << {'section' => sec, 'subsections' => []}
+ else
+ toc[toc.size - 1]['subsections'] << sec
+ end
+ end
+
+ # write ncx table of contents
+ ncx = File.open('book.ncx', 'w+')
+ ncx.puts('<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
+ "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
+
+<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="en-US">
+<head>
+<meta name="dtb:depth" content="2"/>
+<meta name="dtb:totalPageCount" content="0"/>
+<meta name="dtb:maxPageNumber" content="0"/>
+</head>
+<docTitle><text>Title</text></docTitle>
+<docAuthor><text>Author</text></docAuthor>
+<navMap>
+<navPoint class="toc" id="toc" playOrder="1">
+<navLabel>
+<text>Table of Contents</text>
+</navLabel>
+<content src="toc.html"/>
+</navPoint>')
+
+ chapters = 0
+ toc.each do |section|
+ chapters += 1
+ ch = section['section']
+ ncx.puts('<navPoint class="chapter" id="chapter_' + chapters.to_s + '" playOrder="' + (chapters + 1).to_s + '">')
+ ncx.puts('<navLabel><text>' + ch['name'].to_s + '</text></navLabel>')
+ ncx.puts('<content src="book.html#' + ch['id'].to_s + '"/>')
+ ncx.puts('</navPoint>')
+ end
+ ncx.puts('</navMap></ncx>')
+ ncx.close
+
+ # build html toc
+ # write ncx table of contents
+ html = File.open('toc.html', 'w+')
+ html.puts('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head><title>Table of Contents</title></head><body>
+<div><h1><b>TABLE OF CONTENTS</b></h1><br/>')
+
+ chapters = 0
+ toc.each do |section|
+ chapters += 1
+ ch = section['section']
+
+ html.puts('<h3><b>Chapter ' + chapters.to_s + '<br/>')
+ html.puts('<a href="book.html#' + ch['id'] + '">' + ch['name'] + '</a></b></h3><br/>')
+
+ section['subsections'].each do |sub|
+ html.puts('<a href="book.html#' + sub['id'] + '"><b>' + sub['name'] + '</b></a><br/>')
+ end
+ end
+ html.puts('<h1 class="centered">* * *</h1></div></body></html>')
+ html.close
+
+ # build book.opf file
+ opf_template = liquid_template('book.opf')
+ File.open('book.opf', 'w+') do |f|
+ lang = @config['language'] || 'en'
+ author = @config['author'] || 'Author'
+ cover = @config['cover'] || 'image/cover.jpg'
+ data = {'title' => book_title,
+ 'language' => lang,
+ 'author' => author,
+ 'pubdate' => Time.now.strftime("%Y-%m-%d"),
+ 'cover_image' => cover}
+ f.puts opf_template.render( data )
+ end
+ end
+
+
+ def liquid_template(file)
+ template_dir = File.join(SCRIBE_ROOT, 'site', 'default')
+ Liquid::Template.parse(File.read(File.join(template_dir, file)))
+ end
+
+
# create a new file by concatenating all the ones we find
def gather_and_process
files = Dir.glob("book/*")
View
2  lib/git-scribe/version.rb
@@ -1,3 +1,3 @@
class GitScribe
- VERSION = '0.0.5'
+ VERSION = '0.0.9'
end
View
30 site/default/book.opf
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<package xmlns="http://www.idpf.org/2007/opf" version="2.0">
+
+<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
+ <dc:title>{{title}}</dc:title>
+ <dc:language>en</dc:language>
+ <dc:creator>{{author}}</dc:creator>
+ <dc:date>{{pubdate}}</dc:date>
+ <dc:publisher>GitHub.com</dc:publisher>
+ <meta name="cover" content="cover"/>
+</metadata>
+
+<manifest>
+ <item id="book" media-type="application/xhtml+xml" href="book.html"></item>
+ <item id="toc_file" media-type="application/xhtml+xml" href="toc.html"></item>
+ <item id="toc" media-type="application/x-dtbncx+xml" href="book.ncx"/>
+ <item id="cover" media-type="image/jpeg" href="{{cover_image}}"/>
+</manifest>
+
+<spine toc="toc">
+ <itemref idref="book"/>
+</spine>
+
+<guide>
+ <reference type="toc" title="Table of Contents" href="toc.html"></reference>
+ <reference type="text" title="Contents" href="book.html"></reference>
+</guide>
+
+</package>
+
View
4 stylesheets/handbookish.css
@@ -32,9 +32,7 @@ p, ul, ol, dl {
margin:10px 0
}
-dl {
- margin-left:40px
-}
+dl { }
dt {
font-weight:normal;
View
2  template/.gitscribe
@@ -3,3 +3,5 @@ publish: true
edition: 0.1
language: en
version: 1.0
+author: Your Name
+cover: image/cover.jpg
View
BIN  template/book/image/cover.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bf70699

Please sign in to comment.
Something went wrong with that request. Please try again.