Skip to content
This repository has been archived by the owner on Dec 8, 2017. It is now read-only.

added changes from mnot/jekyll-archives #1

Merged
merged 1 commit into from
Oct 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/jekyll-archives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -92,6 +84,14 @@ def enabled?(archive)
end
end

# Write archives to their destination
def write
@archives.each do |archive|
archive.write(@site.dest) if archive.regenerate?
archive.add_dependencies
end
end

def tags
@site.post_attr_hash('tags')
end
Expand All @@ -105,7 +105,7 @@ def years
hash = Hash.new { |h, key| h[key] = [] }

# In Jekyll 3, Collection#each should be called on the #docs array directly.
if Jekyll::VERSION >= '3.0.0'
if Jekyll::VERSION >= '3.0.0'
@posts.docs.each { |p| hash[p.date.strftime("%Y")] << p }
else
@posts.each { |p| hash[p.date.strftime("%Y")] << p }
Expand Down
28 changes: 26 additions & 2 deletions lib/jekyll-archives/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Archive < Jekyll::Page
name
path
url
permalink
).freeze

# Initialize a new Archive page
Expand All @@ -30,8 +31,8 @@ def initialize(site, title, type, posts)
@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)
if title.is_a? String
@slug = Utils.slugify(title)
end

# Use ".html" for file extension and url for path
Expand Down Expand Up @@ -86,6 +87,10 @@ def url
raise ArgumentError.new "Template \"#{template}\" provided is invalid."
end

def permalink
data && data.is_a?(Hash) && data['permalink']
end

# Produce a title object suitable for Liquid based on type of archive.
#
# Returns a String (for tag and category archives) and nil for
Expand All @@ -106,6 +111,25 @@ def date
end
end

# Add dependencies for incremental mode
def add_dependencies
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

def regenerate?
if defined? site.regenerator
site.regenerator.regenerate?(self)
else
true
end
end

# Obtain the write path relative to the destination directory
#
# Returns the destination relative path String.
Expand Down