Skip to content

Commit

Permalink
Make Archive subclass of Page
Browse files Browse the repository at this point in the history
Make Archive a subclass of Jekyll::Page, and render it using the regular
Page pipleline. This should fix long-standing issue #28.
  • Loading branch information
alfredxing committed Aug 24, 2016
1 parent 40823a4 commit 411c7d8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 69 deletions.
22 changes: 1 addition & 21 deletions lib/jekyll-archives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,8 @@ def generate(site)
@site.config['jekyll-archives'] = @config

read
render
write
@site.pages.concat(@archives)

@site.keep_files ||= []
@archives.each do |archive|
@site.keep_files << archive.relative_path
end
@site.config["archives"] = @archives
end

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

# Renders the archives into the layouts
def render
payload = @site.site_payload
@archives.each do |archive|
archive.render(@site.layouts, payload)
end
end

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

def tags
@site.post_attr_hash('tags')
end
Expand Down
51 changes: 3 additions & 48 deletions lib/jekyll-archives/archive.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
module Jekyll
module Archives
class Archive
include Convertible
class Archive < Jekyll::Page

attr_accessor :posts, :type, :name, :slug
attr_accessor :data, :content, :output
attr_accessor :path, :ext
attr_accessor :site
attr_accessor :posts, :type, :slug

# Attributes for Liquid templates
ATTRIBUTES_FOR_LIQUID = %w[
Expand All @@ -17,7 +13,7 @@ class Archive
name
path
url
]
].freeze

# Initialize a new Archive page
#
Expand Down Expand Up @@ -90,31 +86,6 @@ def url
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
Expand All @@ -135,17 +106,6 @@ def date
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.
Expand All @@ -159,11 +119,6 @@ def relative_path
def inspect
"#<Jekyll:Archive @type=#{@type.to_s} @title=#{@title} @data=#{@data.inspect}>"
end

# Returns the Boolean of whether this Page is HTML or not.
def html?
true
end
end
end
end

0 comments on commit 411c7d8

Please sign in to comment.