From 8e44397ac0b2ff6e2f3d009a1c023b1b4f330cb3 Mon Sep 17 00:00:00 2001 From: Mark Nottingham Date: Mon, 15 Feb 2016 15:04:30 +1100 Subject: [PATCH 1/7] Don't disable incremental --- lib/jekyll-archives.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/jekyll-archives.rb b/lib/jekyll-archives.rb index 61fe33c..05e1a2b 100644 --- a/lib/jekyll-archives.rb +++ b/lib/jekyll-archives.rb @@ -6,14 +6,6 @@ module Archives autoload :Archive, 'jekyll-archives/archive' autoload :VERSION, 'jekyll-archives/version' - if (Jekyll.const_defined? :Hooks) - Jekyll::Hooks.register :site, :after_reset do |site| - # We need to disable incremental regen for Archives to generate with the - # correct content - site.regenerator.instance_variable_set(:@disabled, true) - end - end - class Archives < Jekyll::Generator safe true From a57081932f8693f82985b397007ba7f0ff0c7be2 Mon Sep 17 00:00:00 2001 From: Mark Nottingham Date: Mon, 15 Feb 2016 15:05:29 +1100 Subject: [PATCH 2/7] Track dependencies for archives --- lib/jekyll-archives/archive.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/jekyll-archives/archive.rb b/lib/jekyll-archives/archive.rb index 3f47f8b..ae0feab 100644 --- a/lib/jekyll-archives/archive.rb +++ b/lib/jekyll-archives/archive.rb @@ -47,6 +47,11 @@ def initialize(site, title, type, posts) "layout" => layout } @content = "" + + # set up dependencies + posts.each do |post| + site.regenerator.add_dependency(self.path, post.path) + end end # The template of the permalink. From 106069308b99bba4faf390d3b5da0ef906f6a179 Mon Sep 17 00:00:00 2001 From: Mark Nottingham Date: Wed, 24 Feb 2016 18:01:47 +1100 Subject: [PATCH 3/7] Update jekyll-archives.rb --- lib/jekyll-archives.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/jekyll-archives.rb b/lib/jekyll-archives.rb index 05e1a2b..cb4cfce 100644 --- a/lib/jekyll-archives.rb +++ b/lib/jekyll-archives.rb @@ -100,7 +100,8 @@ def render # Write archives to their destination def write @archives.each do |archive| - archive.write(@site.dest) + archive.write(@site.dest) if archive.regenerate? + archive.add_dependencies end end From 3f97948d50d69e8a0a6023d3ea7cc7be1cc78f2e Mon Sep 17 00:00:00 2001 From: Mark Nottingham Date: Wed, 24 Feb 2016 18:03:11 +1100 Subject: [PATCH 4/7] Update archive.rb --- lib/jekyll-archives/archive.rb | 250 ++++++++++----------------------- 1 file changed, 76 insertions(+), 174 deletions(-) diff --git a/lib/jekyll-archives/archive.rb b/lib/jekyll-archives/archive.rb index ae0feab..6439dd1 100644 --- a/lib/jekyll-archives/archive.rb +++ b/lib/jekyll-archives/archive.rb @@ -1,174 +1,76 @@ -module Jekyll - module Archives - class Archive - include Convertible - - attr_accessor :posts, :type, :name, :slug - attr_accessor :data, :content, :output - attr_accessor :path, :ext - attr_accessor :site - - # Attributes for Liquid templates - ATTRIBUTES_FOR_LIQUID = %w[ - posts - type - title - date - name - path - url - ] - - # Initialize a new Archive page - # - # site - The Site object. - # title - The name of the tag/category or a Hash of the year/month/day in case of date. - # e.g. { :year => 2014, :month => 08 } or "my-category" or "my-tag". - # type - The type of archive. Can be one of "year", "month", "day", "category", or "tag" - # posts - The array of posts that belong in this archive. - def initialize(site, title, type, posts) - @site = site - @posts = posts - @type = type - @title = title - @config = site.config['jekyll-archives'] - - # Generate slug if tag or category (taken from jekyll/jekyll/features/support/env.rb) - if title.to_s.length - @slug = Utils.slugify(title.to_s) - end - - # Use ".html" for file extension and url for path - @ext = File.extname(relative_path) - @path = relative_path - @name = File.basename(relative_path, @ext) - - @data = { - "layout" => layout - } - @content = "" - - # set up dependencies - posts.each do |post| - site.regenerator.add_dependency(self.path, post.path) - end - end - - # The template of the permalink. - # - # Returns the template String. - def template - @config['permalinks'][type] - end - - # The layout to use for rendering - # - # Returns the layout as a String - def layout - if @config['layouts'] && @config['layouts'][type] - @config['layouts'][type] - else - @config['layout'] - end - end - - # Returns a hash of URL placeholder names (as symbols) mapping to the - # desired placeholder replacements. For details see "url.rb". - def url_placeholders - if @title.is_a? Hash - @title.merge({ :type => @type }) - else - { :name => @slug, :type => @type } - end - end - - # The generated relative url of this page. e.g. /about.html. - # - # Returns the String url. - def url - @url ||= URL.new({ - :template => template, - :placeholders => url_placeholders, - :permalink => nil - }).to_s - rescue ArgumentError - raise ArgumentError.new "Template \"#{template}\" provided is invalid." - end - - # Add any necessary layouts to this post - # - # layouts - The Hash of {"name" => "layout"}. - # site_payload - The site payload Hash. - # - # Returns nothing. - def render(layouts, site_payload) - payload = Utils.deep_merge_hashes({ - "page" => to_liquid - }, site_payload) - - do_layout(payload, layouts) - end - - # Convert this Convertible's data to a Hash suitable for use by Liquid. - # - # Returns the Hash representation of this Convertible. - def to_liquid(attrs = nil) - further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map { |attribute| - [attribute, send(attribute)] - }] - - Utils.deep_merge_hashes(data, further_data) - end - - # Produce a title object suitable for Liquid based on type of archive. - # - # Returns a String (for tag and category archives) and nil for - # date-based archives. - def title - if @title.is_a? String - @title - end - end - - # Produce a date object if a date-based archive - # - # Returns a Date. - def date - if @title.is_a? Hash - args = @title.values.map { |s| s.to_i } - Date.new(*args) - end - end - - # Obtain destination path. - # - # dest - The String path to the destination dir. - # - # Returns the destination file path String. - def destination(dest) - path = Jekyll.sanitized_path(dest, URL.unescape_path(url)) - path = File.join(path, "index.html") if url =~ /\/$/ - path - end - - # Obtain the write path relative to the destination directory - # - # Returns the destination relative path String. - def relative_path - path = URL.unescape_path(url).gsub(/^\//, '') - path = File.join(path, "index.html") if url =~ /\/$/ - path - end - - # Returns the object as a debug String. - def inspect - "#" - end - - # Returns the Boolean of whether this Page is HTML or not. - def html? - true - end - end - end -end +--- archive.rb ++++ (clipboard) +@@ -17,7 +17,6 @@ + name + path + url +- permalink + ] + + # Initialize a new Archive page +@@ -35,19 +34,24 @@ + @config = site.config['jekyll-archives'] + + # Generate slug if tag or category (taken from jekyll/jekyll/features/support/env.rb) +- if title.is_a? String +- @slug = Utils.slugify(title) ++ if title.to_s.length ++ @slug = Utils.slugify(title.to_s) + end + + # Use ".html" for file extension and url for path + @ext = File.extname(relative_path) +- @path = site.in_dest_dir(relative_path) ++ @path = relative_path + @name = File.basename(relative_path, @ext) + + @data = { + "layout" => layout + } + @content = "" ++ ++ # set up dependencies ++ posts.each do |post| ++ site.regenerator.add_dependency(self.path, post.path) ++ end + end + + # The template of the permalink. +@@ -91,10 +95,6 @@ + raise ArgumentError.new "Template \"#{template}\" provided is invalid." + end + +- def permalink +- data && data.is_a?(Hash) && data['permalink'] +- end +- + # Add any necessary layouts to this post + # + # layouts - The Hash of {"name" => "layout"}. +@@ -109,15 +109,6 @@ + do_layout(payload, layouts) + end + +- # Add dependencies for incremental mode +- def add_dependencies +- archive_path = site.in_dest_dir(relative_path) +- site.regenerator.add(archive_path) +- @posts.each do |post| +- site.regenerator.add_dependency(archive_path, post.path) +- end +- end +- + # Convert this Convertible's data to a Hash suitable for use by Liquid. + # + # Returns the Hash representation of this Convertible. +@@ -169,10 +160,6 @@ + path + end + +- def regenerate? +- site.regenerator.regenerate?(self) +- end +- + # Returns the object as a debug String. + def inspect + "#" From ac71b45722364c441e636ba31dafa3d9a2e9cd1e Mon Sep 17 00:00:00 2001 From: Mark Nottingham Date: Wed, 24 Feb 2016 18:04:17 +1100 Subject: [PATCH 5/7] Update archive.rb --- lib/jekyll-archives/archive.rb | 263 +++++++++++++++++++++++---------- 1 file changed, 187 insertions(+), 76 deletions(-) diff --git a/lib/jekyll-archives/archive.rb b/lib/jekyll-archives/archive.rb index 6439dd1..e9ff30f 100644 --- a/lib/jekyll-archives/archive.rb +++ b/lib/jekyll-archives/archive.rb @@ -1,76 +1,187 @@ ---- archive.rb -+++ (clipboard) -@@ -17,7 +17,6 @@ - name - path - url -- permalink - ] - - # Initialize a new Archive page -@@ -35,19 +34,24 @@ - @config = site.config['jekyll-archives'] - - # Generate slug if tag or category (taken from jekyll/jekyll/features/support/env.rb) -- if title.is_a? String -- @slug = Utils.slugify(title) -+ if title.to_s.length -+ @slug = Utils.slugify(title.to_s) - end - - # Use ".html" for file extension and url for path - @ext = File.extname(relative_path) -- @path = site.in_dest_dir(relative_path) -+ @path = relative_path - @name = File.basename(relative_path, @ext) - - @data = { - "layout" => layout - } - @content = "" -+ -+ # set up dependencies -+ posts.each do |post| -+ site.regenerator.add_dependency(self.path, post.path) -+ end - end - - # The template of the permalink. -@@ -91,10 +95,6 @@ - raise ArgumentError.new "Template \"#{template}\" provided is invalid." - end - -- def permalink -- data && data.is_a?(Hash) && data['permalink'] -- end -- - # Add any necessary layouts to this post - # - # layouts - The Hash of {"name" => "layout"}. -@@ -109,15 +109,6 @@ - do_layout(payload, layouts) - end - -- # Add dependencies for incremental mode -- def add_dependencies -- archive_path = site.in_dest_dir(relative_path) -- site.regenerator.add(archive_path) -- @posts.each do |post| -- site.regenerator.add_dependency(archive_path, post.path) -- end -- end -- - # Convert this Convertible's data to a Hash suitable for use by Liquid. - # - # Returns the Hash representation of this Convertible. -@@ -169,10 +160,6 @@ - path - end - -- def regenerate? -- site.regenerator.regenerate?(self) -- end -- - # Returns the object as a debug String. - def inspect - "#" +module Jekyll + module Archives + class Archive + include Convertible + + attr_accessor :posts, :type, :name, :slug + attr_accessor :data, :content, :output + attr_accessor :path, :ext + attr_accessor :site + + # Attributes for Liquid templates + ATTRIBUTES_FOR_LIQUID = %w[ + posts + type + title + date + name + path + url + permalink + ] + + # Initialize a new Archive page + # + # site - The Site object. + # title - The name of the tag/category or a Hash of the year/month/day in case of date. + # e.g. { :year => 2014, :month => 08 } or "my-category" or "my-tag". + # type - The type of archive. Can be one of "year", "month", "day", "category", or "tag" + # posts - The array of posts that belong in this archive. + def initialize(site, title, type, posts) + @site = site + @posts = posts + @type = type + @title = title + @config = site.config['jekyll-archives'] + + # Generate slug if tag or category (taken from jekyll/jekyll/features/support/env.rb) + if title.is_a? String + @slug = Utils.slugify(title) + end + + # Use ".html" for file extension and url for path + @ext = File.extname(relative_path) + @path = site.in_dest_dir(relative_path) + @name = File.basename(relative_path, @ext) + + @data = { + "layout" => layout + } + @content = "" + end + + # The template of the permalink. + # + # Returns the template String. + def template + @config['permalinks'][type] + end + + # The layout to use for rendering + # + # Returns the layout as a String + def layout + if @config['layouts'] && @config['layouts'][type] + @config['layouts'][type] + else + @config['layout'] + end + end + + # Returns a hash of URL placeholder names (as symbols) mapping to the + # desired placeholder replacements. For details see "url.rb". + def url_placeholders + if @title.is_a? Hash + @title.merge({ :type => @type }) + else + { :name => @slug, :type => @type } + end + end + + # The generated relative url of this page. e.g. /about.html. + # + # Returns the String url. + def url + @url ||= URL.new({ + :template => template, + :placeholders => url_placeholders, + :permalink => nil + }).to_s + rescue ArgumentError + raise ArgumentError.new "Template \"#{template}\" provided is invalid." + end + + def permalink + data && data.is_a?(Hash) && data['permalink'] + end + + # Add any necessary layouts to this post + # + # layouts - The Hash of {"name" => "layout"}. + # site_payload - The site payload Hash. + # + # Returns nothing. + def render(layouts, site_payload) + payload = Utils.deep_merge_hashes({ + "page" => to_liquid + }, site_payload) + + do_layout(payload, layouts) + end + + # Add dependencies for incremental mode + def add_dependencies + archive_path = site.in_dest_dir(relative_path) + site.regenerator.add(archive_path) + @posts.each do |post| + site.regenerator.add_dependency(archive_path, post.path) + end + end + + # Convert this Convertible's data to a Hash suitable for use by Liquid. + # + # Returns the Hash representation of this Convertible. + def to_liquid(attrs = nil) + further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map { |attribute| + [attribute, send(attribute)] + }] + + Utils.deep_merge_hashes(data, further_data) + end + + # Produce a title object suitable for Liquid based on type of archive. + # + # Returns a String (for tag and category archives) and nil for + # date-based archives. + def title + if @title.is_a? String + @title + end + end + + # Produce a date object if a date-based archive + # + # Returns a Date. + def date + if @title.is_a? Hash + args = @title.values.map { |s| s.to_i } + Date.new(*args) + end + end + + # Obtain destination path. + # + # dest - The String path to the destination dir. + # + # Returns the destination file path String. + def destination(dest) + path = Jekyll.sanitized_path(dest, URL.unescape_path(url)) + path = File.join(path, "index.html") if url =~ /\/$/ + path + end + + # Obtain the write path relative to the destination directory + # + # Returns the destination relative path String. + def relative_path + path = URL.unescape_path(url).gsub(/^\//, '') + path = File.join(path, "index.html") if url =~ /\/$/ + path + end + + def regenerate? + site.regenerator.regenerate?(self) + end + + # Returns the object as a debug String. + def inspect + "#" + end + + # Returns the Boolean of whether this Page is HTML or not. + def html? + true + end + end + end +end From cb37528ab2e5d0009007248319f26b8fabe3f734 Mon Sep 17 00:00:00 2001 From: Mark Nottingham Date: Tue, 17 May 2016 14:50:34 +1000 Subject: [PATCH 6/7] fix @path --- lib/jekyll-archives/archive.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll-archives/archive.rb b/lib/jekyll-archives/archive.rb index e9ff30f..c6c2f6c 100644 --- a/lib/jekyll-archives/archive.rb +++ b/lib/jekyll-archives/archive.rb @@ -41,7 +41,7 @@ def initialize(site, title, type, posts) # Use ".html" for file extension and url for path @ext = File.extname(relative_path) - @path = site.in_dest_dir(relative_path) + @path = relative_path @name = File.basename(relative_path, @ext) @data = { From 38d306a70409d0f5c482a7d3977c577227ed9312 Mon Sep 17 00:00:00 2001 From: Mark Nottingham Date: Tue, 17 May 2016 15:05:34 +1000 Subject: [PATCH 7/7] Don't try to regenerate with older jekyll. --- lib/jekyll-archives/archive.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/jekyll-archives/archive.rb b/lib/jekyll-archives/archive.rb index c6c2f6c..c5e2240 100644 --- a/lib/jekyll-archives/archive.rb +++ b/lib/jekyll-archives/archive.rb @@ -111,10 +111,12 @@ def render(layouts, site_payload) # Add dependencies for incremental mode def add_dependencies - archive_path = site.in_dest_dir(relative_path) - site.regenerator.add(archive_path) - @posts.each do |post| - site.regenerator.add_dependency(archive_path, post.path) + if defined? site.regenerator + archive_path = site.in_dest_dir(relative_path) + site.regenerator.add(archive_path) + @posts.each do |post| + site.regenerator.add_dependency(archive_path, post.path) + end end end @@ -170,7 +172,11 @@ def relative_path end def regenerate? - site.regenerator.regenerate?(self) + if defined? site.regenerator + site.regenerator.regenerate?(self) + else + true + end end # Returns the object as a debug String.