Skip to content
Snippets Groups Projects
Unverified Commit 8e3dd169 authored by fauno's avatar fauno
Browse files

allow to skip some of the generation process

parent 1c063103
No related branches found
No related tags found
No related merge requests found
...@@ -34,7 +34,10 @@ Add to `_config.yml`: ...@@ -34,7 +34,10 @@ Add to `_config.yml`:
markdown: pandoc markdown: pandoc
pandoc: pandoc:
skip: false skip:
full: false
posts: false
categories: false
bundle_permalink: ':output_ext/:slug.:output_ext' bundle_permalink: ':output_ext/:slug.:output_ext'
papersize: 'a5paper' papersize: 'a5paper'
sheetsize: 'a4paper' sheetsize: 'a4paper'
...@@ -59,8 +62,10 @@ pandoc: ...@@ -59,8 +62,10 @@ pandoc:
* `markdown: pandoc` will instruct jekyll to use the pandoc html * `markdown: pandoc` will instruct jekyll to use the pandoc html
converter. converter.
* `skip` allows you to skip the other formats generation and proceed with the * `skip` allows you to skip the other formats generation and proceed
regular jekyll site build. with the regular jekyll site build. You can skip some of the
generation process or all of it. Older versions of this plugin
required `true` or `false` to skip the process altogether.
* `full_flags` if `full_file` is defined, these flags are used on it. * `full_flags` if `full_file` is defined, these flags are used on it.
By default are set to `--top-level-division=part` so each category is By default are set to `--top-level-division=part` so each category is
......
module JekyllPandocMultipleFormats module JekyllPandocMultipleFormats
class Config class Config
DEFAULTS = { DEFAULTS = {
'skip' => false, 'skip' => {
'posts' => false,
'categories' => false,
'full' => false
},
'bundle_permalink' => ':output_ext/:slug.:output_ext', 'bundle_permalink' => ':output_ext/:slug.:output_ext',
'papersize' => 'a5paper', 'papersize' => 'a5paper',
'sheetsize' => 'a4paper', 'sheetsize' => 'a4paper',
...@@ -23,7 +27,7 @@ module JekyllPandocMultipleFormats ...@@ -23,7 +27,7 @@ module JekyllPandocMultipleFormats
end end
def skip? def skip?
@config['skip'] @config['skip'].values.all?
end end
def imposition? def imposition?
...@@ -34,13 +38,21 @@ module JekyllPandocMultipleFormats ...@@ -34,13 +38,21 @@ module JekyllPandocMultipleFormats
@config['binder'] @config['binder']
end end
def full_file?
@config['full_file']
end
# TODO magic # TODO magic
def outputs def outputs
@config['outputs'] @config['outputs']
end end
def generate_posts?
!@config.dig('skip', 'posts')
end
def generate_categories?
!@config.dig('skip', 'categories')
end
def generate_full_file?
!@config.dig('skip', 'full')
end
end end
end end
...@@ -28,23 +28,12 @@ class PandocGenerator < Generator ...@@ -28,23 +28,12 @@ class PandocGenerator < Generator
attr_accessor :site, :config attr_accessor :site, :config
def generate(site) def generate_post_for_output(post, output)
@site ||= site
@config ||= JekyllPandocMultipleFormats::Config.new(@site.config['pandoc'])
return if @config.skip?
# we create a single array of files
@pandoc_files = []
@config.outputs.each_pair do |output, _|
Jekyll.logger.info 'Pandoc:', "Generating #{output}"
@site.posts.docs.each do |post|
Jekyll.logger.debug 'Pandoc:', post.data['title'] Jekyll.logger.debug 'Pandoc:', post.data['title']
Jekyll::Hooks.trigger :posts, :pre_render, post, { format: output } Jekyll::Hooks.trigger :posts, :pre_render, post, { format: output }
pandoc_file = PandocFile.new(@site, output, post) pandoc_file = PandocFile.new(@site, output, post)
next unless pandoc_file.write return unless pandoc_file.write
Jekyll::Hooks.trigger :posts, :post_render, post, { format: output } Jekyll::Hooks.trigger :posts, :post_render, post, { format: output }
...@@ -52,24 +41,24 @@ class PandocGenerator < Generator ...@@ -52,24 +41,24 @@ class PandocGenerator < Generator
@pandoc_files << pandoc_file @pandoc_files << pandoc_file
end end
@site.post_attr_hash('categories').each_pair do |title, posts| def generate_category_for_output(category, posts, output)
Jekyll.logger.info 'Pandoc:', "Generating category #{title}" Jekyll.logger.info 'Pandoc:', "Generating category #{category}"
posts.sort! posts.sort!
pandoc_file = PandocFile.new(@site, output, posts, title) pandoc_file = PandocFile.new(@site, output, posts, category)
if @site.keep_files.include? pandoc_file.relative_path if @site.keep_files.include? pandoc_file.relative_path
puts "#{pandoc_file.relative_path} is a category file AND a post file" Jekyll.logger.warn 'Pandoc:',
puts 'change the category name to fix this' "#{pandoc_file.relative_path} is a category file AND a post file. Change the category name to fix this"
next return
end end
next unless pandoc_file.write return unless pandoc_file.write
@site.keep_files << pandoc_file.relative_path @site.keep_files << pandoc_file.relative_path
@pandoc_files << pandoc_file @pandoc_files << pandoc_file
end end
if @config.full_file? def general_full_for_output(output)
title = @site.config.dig('title') title = @site.config.dig('title')
Jekyll.logger.info 'Pandoc:', "Generating full file #{title}" Jekyll.logger.info 'Pandoc:', "Generating full file #{title}"
# For parts to make sense, we order articles by date and then by # For parts to make sense, we order articles by date and then by
...@@ -87,6 +76,31 @@ class PandocGenerator < Generator ...@@ -87,6 +76,31 @@ class PandocGenerator < Generator
@site.keep_files << full_file.relative_path @site.keep_files << full_file.relative_path
@pandoc_files << full_file @pandoc_files << full_file
end end
def generate(site)
@site ||= site
@config ||= JekyllPandocMultipleFormats::Config.new(@site.config['pandoc'])
return if @config.skip?
# we create a single array of files
@pandoc_files = []
@config.outputs.each_pair do |output, _|
Jekyll.logger.info 'Pandoc:', "Generating #{output}"
if @config.generate_posts?
@site.posts.docs.each do |post|
generate_post_for_output post, output
end
end
if @config.generate_categories?
@site.post_attr_hash('categories').each_pair do |title, posts|
generate_category_for_output title, posts, output
end
end
general_full_for_output(output) if @config.generate_full_file?
end end
@pandoc_files.each do |pandoc_file| @pandoc_files.each do |pandoc_file|
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment