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

generate a book with all articles!

parent 9fbe91de
Branches
Tags
No related merge requests found
......@@ -42,6 +42,7 @@ pandoc:
binder: true
covers_dir: assets/covers
signature: 20
full_file: true
flags: '--smart'
site_flags: '--toc'
......@@ -58,6 +59,10 @@ pandoc:
* `skip` allows you to skip the other formats generation and proceed with the
regular jekyll site build.
* `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
a different book part.
* `site_flags` are flags applied to the html generation
* `flags` is a string with the flags you will normally pass to `pandoc` on cli.
......@@ -85,6 +90,9 @@ regular jekyll site build.
Specify `0` for a single fold of all the pages. You can also use this
option on the front matter.
* `full_file` generates a single file containing all articles, sectioned
by their main category (the first one defined if many).
**IMPORTANT**: As of version 0.1.0 the syntax of the config changed.
Please upgrade your `_config.yml` accordingly.
......
......
......@@ -11,7 +11,9 @@ module JekyllPandocMultipleFormats
'flags' => '--smart',
'site_flags' => '--toc',
'outputs' => {},
'covers_dir' => 'images/'
'covers_dir' => 'images/',
'title' => nil,
'full_flags' => '--top-level-division=part'
}
attr_accessor :config
......
......
......@@ -50,6 +50,23 @@ class PandocGenerator < Generator
@pandoc_files << pandoc_file
end
if @config.full_file
# For parts to make sense, we order articles by date and then by
# category, so each category is ordered by date.
#
# cat1 - art1
# cat1 - art3
# cat2 - art2
full = @site.posts.docs.reject { |p| p.data.dig('full') }.sort_by do |p|
[ p.data['date'], p.data['categories'].first.to_s ]
end
full_file = PandocFile.new(@site, output, full, @site.config['title'], { full: true })
full_file.write
@site.keep_files << full_file.relative_path
@pandoc_files << full_file
end
@site.post_attr_hash('categories').each_pair do |title, posts|
posts.sort!
pandoc_file = PandocFile.new(@site, output, posts, title)
......
......
......@@ -28,11 +28,13 @@ module Jekyll
attr_reader :format, :site, :config, :flags, :posts, :slug, :title, :url
attr_reader :papersize, :sheetsize, :signature
def initialize(site, format, posts, title = nil)
def initialize(site, format, posts, title = nil, extra = {})
@site = site
@config = JekyllPandocMultipleFormats::Config.new(@site.config['pandoc']).config
@format = format
@flags = []
@last_cat = nil
@extra = extra
if posts.is_a? Array
@single_post = false
......@@ -45,7 +47,7 @@ module Jekyll
else
@single_post = true
@posts = [posts]
@title = posts.data['title'] unless title
@title = title || posts.data['title']
@slug = posts.data['slug']
end
......@@ -150,7 +152,28 @@ module Jekyll
# make all images relative to source dir
content = content.gsub(relative_re, '(\1)')
# if the file contains all the articles, we make each category
# a different part by adding a first level title out of it
if full?
# make all titles down a level
# TODO have sixth level titles into account
content = content.gsub(/^#/, '##')
# we don't use all the categories otherwise the article
# would be repeated
cat = post.data['categories'].first
# if we already set the category part, we just skip it
if @last_cat == cat
content
# otherwise add the category title
else
@last_cat = cat
"# #{cat}\n\n#{content}"
end
else
# or we just return the content
content
end
# we add the first bibliography title we can find in the end
end.join("\n\n\n") << bib_title
end
......@@ -163,6 +186,7 @@ module Jekyll
# Move to the source dir since everything will be relative to that
Dir::chdir(@site.config['source']) do
# Do the stuff
puts command
Open3::popen3(command) do |stdin, stdout, stderr, thread|
stdin.puts yaml_metadata
stdin.puts content
......@@ -225,6 +249,10 @@ module Jekyll
@flags << cover
end
if full?
@flags << @config['full_flags']
end
@flags.join ' '
end
......@@ -232,6 +260,10 @@ module Jekyll
'pandoc ' << flags
end
def full?
@extra[:full]
end
def pdf?
@format == 'pdf'
end
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment