Skip to content

Commit

Permalink
only regenerate files when the sources are newer
Browse files Browse the repository at this point in the history
  • Loading branch information
fauno committed Jul 10, 2018
1 parent 55ad0e6 commit 26d869d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/jekyll-pandoc-multiple-formats/generator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2012-2015 Nicolás Reynolds <[email protected]>
# Copyright (c) 2012-2018 Nicolás Reynolds <[email protected]>
# 2012-2013 Mauricio Pasquier Juan <[email protected]>
# 2013 Brian Candler <[email protected]>
#
Expand Down
29 changes: 28 additions & 1 deletion lib/jekyll-pandoc-multiple-formats/pandoc_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PandocFile
include Convertible

attr_reader :format, :site, :config, :flags, :posts, :slug, :title, :url
attr_reader :papersize, :sheetsize, :signature
attr_reader :papersize, :sheetsize, :signature, :sources

def initialize(site, format, posts, title = nil, extra = {})
@site = site
Expand Down Expand Up @@ -184,6 +184,12 @@ def content
end

def write
unless rebuild?
Jekyll.logger.info "#{relative_path} doesn't need to be rebuilt"
Jekyll.logger.debug sources.join(' ')
return true
end

FileUtils.mkdir_p(File.dirname(path))
# Remove the file before creating it
FileUtils.rm_f(path)
Expand Down Expand Up @@ -332,6 +338,27 @@ def signature
@signature ||= find_option 'signature'
end

# Finds the source files for this pandoc file
def sources
return @sources if @sources

@sources = ['_config.yml']
@sources << flags.split(' ').map do |flag|
file = File.join(@site.config['source'], flag.split('=').last)
file if File.exist? file
end

@sources << posts.map(&:path)

@sources = @sources.flatten.compact
end

def rebuild?
!File.exist?(path) || sources.map do |f|
File.ctime(f) > File.ctime(path)
end.any?
end

private

def single_post
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-pandoc-multiple-formats/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module JekyllPandocMultipleFormats
VERSION = '0.3.0'
VERSION = '0.4.0'
end

0 comments on commit 26d869d

Please sign in to comment.