jekyll-build-ebook 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/jekyll-e-book.gemspec +1 -1
- data/lib/jekyll-build-ebook.rb +4 -0
- data/lib/jekyll-build-ebook/config.rb +28 -53
- data/lib/jekyll-build-ebook/filters.rb +24 -0
- data/lib/jekyll-build-ebook/generator.rb +11 -22
- data/lib/jekyll-build-ebook/hooks.rb +19 -0
- data/lib/jekyll-build-ebook/version.rb +1 -1
- data/lib/jekyll/commands/build_ebook.rb +23 -7
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24ba968d95403fed60c26ea91cbaca4f6dc8165e6813d635a7cf4b9787b3496e
|
4
|
+
data.tar.gz: 55e128d636b39639579e9e9557df04dd9303193a0d52420725e90f5e5d6e7adc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 761ac329ef84fe8c5a74ab7bb292480942c1269ddb8c9276704b1f95d008e1cacdecb0420dc2014c34fac0b5400827ca77f01ca65a375e1477e620da5132de0a
|
7
|
+
data.tar.gz: 3094624f1c9f5b1c49eecd6864136d1db8e3f0ef9af9abd129889c4703956a3f2361b6858dd9f4613adbca037f3a1b4bae619e3e481d1956a30f00e2a6ba6e31
|
data/Gemfile.lock
CHANGED
data/jekyll-e-book.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency 'jekyll', '~> 3.5'
|
24
24
|
|
25
25
|
spec.add_dependency 'gepub', '~> 0.7'
|
26
|
-
spec.add_dependency 'nokogiri', '~> 1.
|
26
|
+
spec.add_dependency 'nokogiri', '~> 1.8'
|
27
27
|
|
28
28
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
29
29
|
spec.add_development_dependency 'meowcop'
|
data/lib/jekyll-build-ebook.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'jekyll'
|
2
2
|
|
3
|
+
require 'securerandom'
|
4
|
+
|
3
5
|
require 'gepub'
|
4
6
|
require 'nokogiri'
|
5
7
|
|
6
8
|
require_relative 'jekyll/commands/build_ebook'
|
7
9
|
require_relative 'jekyll-build-ebook/config'
|
10
|
+
require_relative 'jekyll-build-ebook/filters'
|
8
11
|
require_relative 'jekyll-build-ebook/generator'
|
12
|
+
require_relative 'jekyll-build-ebook/hooks'
|
9
13
|
require_relative 'jekyll-build-ebook/version'
|
@@ -4,67 +4,42 @@ module JekyllBuildEbook
|
|
4
4
|
class Config
|
5
5
|
DEFAULTS = {
|
6
6
|
'ebook' => {
|
7
|
-
'destination' => '_ebook',
|
7
|
+
'destination' => File.join(Dir.pwd, '_ebook'),
|
8
|
+
'layout' => 'ebook',
|
8
9
|
},
|
9
10
|
}.freeze
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def language
|
36
|
-
ebook['language'] || site['language'] || site['lang'] or raise InvalidConfigError, 'Language is required'
|
37
|
-
end
|
38
|
-
|
39
|
-
def date
|
40
|
-
ebook['date']
|
41
|
-
end
|
42
|
-
|
43
|
-
def creator
|
44
|
-
case
|
45
|
-
when !ebook['creator'].nil?
|
46
|
-
ebook['creator']
|
47
|
-
when site['author'].is_a?(String)
|
48
|
-
site['author']
|
49
|
-
when site['author'].is_a?(Hash) && !site['author']['name'].nil?
|
50
|
-
site['author']['name']
|
51
|
-
else
|
52
|
-
nil
|
12
|
+
REQUIRED_FIELDS = %w[identifier title language].freeze
|
13
|
+
|
14
|
+
attr_reader :data
|
15
|
+
|
16
|
+
def initialize(site_config)
|
17
|
+
@data = {
|
18
|
+
'file_name' => site_config['title'],
|
19
|
+
'identifier' => site_config['url'].nil? ? SecureRandom.uuid : "#{site_config['url']}#{site_config['base_url']}",
|
20
|
+
'title' => site_config['title'],
|
21
|
+
'language' => site_config['language'] || site_config['lang'],
|
22
|
+
'creator' => case site_config['author']
|
23
|
+
when String
|
24
|
+
site_config['author']
|
25
|
+
when Hash
|
26
|
+
site_config['author']['name']
|
27
|
+
else
|
28
|
+
nil
|
29
|
+
end,
|
30
|
+
}.merge(site_config['ebook'])
|
31
|
+
|
32
|
+
REQUIRED_FIELDS.each do |field|
|
33
|
+
raise InvalidConfigError, "#{field} is required" if data[field].nil?
|
53
34
|
end
|
54
35
|
end
|
55
36
|
|
56
|
-
def
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
def site
|
63
|
-
@config
|
37
|
+
def [](key)
|
38
|
+
data[key]
|
64
39
|
end
|
65
40
|
|
66
|
-
def
|
67
|
-
|
41
|
+
def file_path
|
42
|
+
"#{File.join(data['destination'], data['file_name'])}.epub"
|
68
43
|
end
|
69
44
|
end
|
70
45
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module JekyllBuildEbook
|
2
|
+
module Filters
|
3
|
+
def self.register
|
4
|
+
Liquid::Template.register_filter(URLFilters)
|
5
|
+
end
|
6
|
+
|
7
|
+
module URLFilters
|
8
|
+
include Jekyll::Filters::URLFilters
|
9
|
+
|
10
|
+
def relative_url(input)
|
11
|
+
return if input.nil?
|
12
|
+
input = input.url if input.respond_to?(:url)
|
13
|
+
return input if Addressable::URI.parse(input.to_s).absolute?
|
14
|
+
|
15
|
+
page = @context.registers[:page]
|
16
|
+
page_dir = Pathname.new(page.url).dirname
|
17
|
+
|
18
|
+
Pathname.new(ensure_leading_slash(input)).relative_path_from(page_dir).to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
alias_method :absolute_url, :relative_url
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -3,13 +3,12 @@ module JekyllBuildEbook
|
|
3
3
|
def generate(site, book: GEPUB::Book.new)
|
4
4
|
config = Config.new(site.config)
|
5
5
|
|
6
|
-
book.date = site.time
|
7
|
-
book.identifier = config
|
8
|
-
book.title = config
|
9
|
-
book.language = config
|
10
|
-
book.creator = config
|
11
|
-
book.
|
12
|
-
book.page_progression_direction = config.page_progression_direction
|
6
|
+
book.date = config['date'] || site.time
|
7
|
+
book.identifier = config['identifier']
|
8
|
+
book.title = config['title']
|
9
|
+
book.language = config['language']
|
10
|
+
book.creator = config['creator']
|
11
|
+
book.page_progression_direction = config['page_progression_direction']
|
13
12
|
|
14
13
|
site.static_files.each do |static_file|
|
15
14
|
File.open(static_file.path) do |io|
|
@@ -19,27 +18,17 @@ module JekyllBuildEbook
|
|
19
18
|
|
20
19
|
book.ordered do
|
21
20
|
site.posts.docs.each do |post|
|
22
|
-
output =
|
21
|
+
post.output = Jekyll::Renderer.new(site, post).run
|
23
22
|
|
24
23
|
book
|
25
|
-
.add_item(
|
26
|
-
.add_content(StringIO.new(output))
|
24
|
+
.add_item(post.url)
|
25
|
+
.add_content(StringIO.new(Nokogiri::HTML(post.output).to_xhtml))
|
27
26
|
.toc_text(post['title'])
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
31
|
-
FileUtils.mkdir_p(config
|
32
|
-
book.generate_epub(File.join(config
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def render(site, post, layout:)
|
38
|
-
original_layout = post['layout']
|
39
|
-
post.merge_data!('layout' => layout)
|
40
|
-
output = Jekyll::Renderer.new(site, post).run
|
41
|
-
post.merge_data!('layout' => original_layout)
|
42
|
-
Nokogiri::HTML(output).to_xhtml
|
30
|
+
FileUtils.mkdir_p(config['destination'])
|
31
|
+
book.generate_epub("#{File.join(config['destination'], config['file_name'])}.epub")
|
43
32
|
end
|
44
33
|
end
|
45
34
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module JekyllBuildEbook
|
2
|
+
module Hooks
|
3
|
+
def self.register
|
4
|
+
overwrite_post_data
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.overwrite_post_data
|
8
|
+
Jekyll::Hooks.register :posts, :pre_render do |post, _payload|
|
9
|
+
layout = post.site.config['ebook']['layout']
|
10
|
+
permalink = "#{post.cleaned_relative_path}.xhtml"
|
11
|
+
|
12
|
+
post.merge_data!(
|
13
|
+
'layout' => post.site.layouts.key?(layout) ? layout : 'none',
|
14
|
+
'permalink' => permalink,
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -4,28 +4,44 @@ module Jekyll
|
|
4
4
|
# Create the Mercenary command for the Jekyll CLI for this Command
|
5
5
|
def self.init_with_program(prog)
|
6
6
|
prog.command(:'build-ebook') do |c|
|
7
|
-
c.syntax 'build-ebook'
|
7
|
+
c.syntax 'build-ebook [options]'
|
8
8
|
c.description 'Build your ebook'
|
9
9
|
c.alias :be
|
10
10
|
|
11
|
+
c.option 'config', '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'
|
12
|
+
c.option 'destination', '-d', '--destination DESTINATION', 'The current folder will be generated into DESTINATION'
|
13
|
+
c.option 'source', '-s', '--source SOURCE', 'Custom source directory'
|
14
|
+
c.option 'future', '--future', 'Publishes posts with a future date'
|
15
|
+
c.option 'limit_posts', '--limit_posts MAX_POSTS', Integer, 'Limits the number of posts to parse and publish'
|
16
|
+
c.option 'show_drafts', '-D', '--drafts', 'Render posts in the _drafts folder'
|
17
|
+
c.option 'unpublished', '--unpublished', 'Render posts that were marked as unpublished'
|
18
|
+
c.option 'quiet', '-q', '--quiet', 'Silence output.'
|
19
|
+
c.option 'verbose', '-V', '--verbose', 'Print verbose output.'
|
20
|
+
|
11
21
|
c.action do |_args, options|
|
12
22
|
process(options)
|
13
23
|
end
|
14
24
|
end
|
15
25
|
end
|
16
26
|
|
17
|
-
|
18
|
-
def self.process(options, generator: JekyllBuildEbook::Generator.new)
|
27
|
+
def self.process(options)
|
19
28
|
# Adjust verbosity quickly
|
20
29
|
Jekyll.logger.adjust_verbosity(options)
|
21
30
|
|
31
|
+
JekyllBuildEbook::Hooks.register
|
32
|
+
JekyllBuildEbook::Filters.register
|
33
|
+
|
22
34
|
options = Jekyll::Utils.deep_merge_hashes(JekyllBuildEbook::Config::DEFAULTS, options)
|
23
|
-
|
24
|
-
site = Jekyll::Site.new(
|
35
|
+
config = configuration_from_options(options)
|
36
|
+
site = Jekyll::Site.new(config)
|
37
|
+
|
38
|
+
build(site, config)
|
39
|
+
end
|
25
40
|
|
41
|
+
def self.build(site, config, generator: JekyllBuildEbook::Generator.new)
|
26
42
|
t = Time.now
|
27
|
-
source =
|
28
|
-
destination =
|
43
|
+
source = config['source']
|
44
|
+
destination = config['ebook']['destination']
|
29
45
|
|
30
46
|
Jekyll.logger.info 'Source:', source
|
31
47
|
Jekyll.logger.info 'Destination:', destination
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-build-ebook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fuji Nakahara
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
47
|
+
version: '1.8'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
54
|
+
version: '1.8'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,7 +130,9 @@ files:
|
|
130
130
|
- jekyll-e-book.gemspec
|
131
131
|
- lib/jekyll-build-ebook.rb
|
132
132
|
- lib/jekyll-build-ebook/config.rb
|
133
|
+
- lib/jekyll-build-ebook/filters.rb
|
133
134
|
- lib/jekyll-build-ebook/generator.rb
|
135
|
+
- lib/jekyll-build-ebook/hooks.rb
|
134
136
|
- lib/jekyll-build-ebook/version.rb
|
135
137
|
- lib/jekyll/commands/build_ebook.rb
|
136
138
|
homepage: https://github.com/fuji-nakahara/jekyll-build-ebook
|