Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding extra check if 'exclude' option is provided in config file at all... #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions lib/jekyll/epub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ def url #:nodoc:
File.join( @dir, @name )
end
end
class Site #:nodoc:

class Site #:nodoc:
def all
if self.config["epub"]["pages-order"]
self.create_order( pages.clone, posts.clone, self.config["epub"]["pages-order"], :url )
else
posts + pages
end
end

def get_item( item, method, posts, pages ) #:nodoc:
_out = []

Expand Down Expand Up @@ -58,63 +58,63 @@ def create_order( pages, posts, order, method ) #:nodoc:

return _result
end

# This is a Jekyll[http://jekyllrb.com] extension
#
# Same as Site::process but generate the epub.
# Same as Site::process but generate the epub.
def epub #:nodoc:
self.reset
self.read

# Change layout to use epub
self.layouts.each do |name, layout|
self.layouts[name].data['layout'] = layout.data['epub'] if layout.data['epub']
end

# Generate specifics epub files
FileUtils.rm_rf( self.dest )
self.package_epub

self.render

# Apply filters
self.apply_epub_filters( pages )
self.apply_epub_filters( posts )

self.write

# Create epub file
self.zip
end

# This is a Jekyll[http://jekyllrb.com] extension
#
# Generate the specifics epub files : content.opf, toc.ncx, mimetype,
# Generate the specifics epub files : content.opf, toc.ncx, mimetype,
# page-template.xpgt and META-INF/container.xml
def package_epub #:nodoc:
files = []
order = 0

# Check for cover image
if self.config["epub"]["cover-image"]
self.config["epub"]["cover"] = {
"image" => self.config["epub"]["cover-image"],
"mime" => MIME::Types.type_for( self.config["epub"]["cover-image"] ).to_s
}
end

(all + static_files).each do |p|
url = p.url.gsub( /^\//, "" )
next if url == self.config["epub"]["cover-image"]
mime = MIME::Types.type_for( url ).to_s
mime = "application/xhtml+xml" if mime == "text/html"
next if self.config['exclude'].include?(File.basename( url ))
mime = "application/xhtml+xml" if mime == "text/html"
next if self.config.key?("exclude") and self.config['exclude'].include?(File.basename( url ))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix is here! :)


if mime == "" then
$stderr.puts "** Ignore file #{url}, unknown mime type!"
next
end

file_data = {
'id' => url.gsub( /\/|\./, "_" ),
'url' => url,
Expand All @@ -133,10 +133,10 @@ def package_epub #:nodoc:
end
files << file_data
end

FileUtils.mkdir_p(self.dest)
FileUtils.mkdir_p(File.join( self.dest, "META-INF" ))

write_epub_file( "content.opf", files )
write_epub_file( "toc.ncx", files )
write_epub_file( "mimetype", files )
Expand All @@ -146,7 +146,7 @@ def package_epub #:nodoc:
write_epub_file( "cover.xhtml", files )
end
end

# This is a Jekyll[http://jekyllrb.com] extension
#
# Write a specific epub file using Liquid. See Jekyll::Site::package_epub
Expand All @@ -156,7 +156,7 @@ def write_epub_file( tmpl, files ) #:nodoc:
template_content = Liquid::Template.parse(File.open(template_file).read).render( 'epub' => self.config['epub'], 'files' => files )
File.open( File.join( self.dest, tmpl ), "w+" ).puts template_content
end

# This is a Jekyll[http://jekyllrb.com] extension
#
# Very simple post-filters
Expand All @@ -173,7 +173,7 @@ def apply_epub_filters( files ) #:nodoc:
file.output = file.output.gsub( /<noscript>.*<\/noscript>/, "" )
end
end

# This is a Jekyll[http://jekyllrb.com] extension
#
# Create the epub file...
Expand All @@ -187,10 +187,10 @@ def zip #:nodoc:
end
end
end

class Epub
include Jekyll::Filters

DEFAULTS = Jekyll::DEFAULTS.merge( {
'destination' => File.join('.', '_epub', 'src'),
'permalink' => '/:title.html',
Expand All @@ -200,7 +200,7 @@ class Epub
'identifier' => UUID.generate
}
} )

# Generate a Jekyll::Epub configuration Hash by merging the default options
# with anything in _epub.yml, and adding the given options on top
# +override+ is a Hash of config directives
Expand All @@ -226,22 +226,22 @@ def self.configuration(override = {})
# Merge DEFAULTS < _config.yml < override
Jekyll::Epub::DEFAULTS.deep_merge(config).deep_merge(override)
end

# Generate the epub! All in one!
def create( override )
options = Jekyll::Epub.configuration( override )

site = Jekyll::Site.new(options)
site.epub

if options['epub']['validate'] == true
self.validate( site )
end
end

# A tiny XHTML validator.
#
# If you want to validate your xhtml files, juste add
#
# If you want to validate your xhtml files, juste add
#
# epub:
# validate: true
Expand All @@ -254,10 +254,10 @@ def validate( site )
$stderr.puts "** WARNING: libxml-ruby is not installed. Can't validate!"
return
end

dtd_file = File.join( File.expand_path( File.dirname( __FILE__ ) ), "epub", "dtd", "xhtml1-strict.dtd" )
dtd = XML::Dtd.new("-//W3C//DTD XHTML 1.0 Strict//EN", dtd_file)

(site.posts + site.pages).each do |path|
file = File.join( site.dest, path.url )
$stderr.puts "** Validate #{file}."
Expand All @@ -269,6 +269,6 @@ def validate( site )
end
end
end

end
end