Skip to content

Commit bea31f9

Browse files
committed
Use title instead of name and use method
1 parent 59fbad3 commit bea31f9

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

lib/jekyll-archives.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ def generate(site)
4646

4747
# Read archive data from posts
4848
def read
49-
tags.each do |name, posts|
50-
@archives << Archive.new(@site, name, "tag", posts)
49+
tags.each do |title, posts|
50+
@archives << Archive.new(@site, title, "tag", posts)
5151
end
52-
categories.each do |name, posts|
53-
@archives << Archive.new(@site, name, "category", posts)
52+
categories.each do |title, posts|
53+
@archives << Archive.new(@site, title, "category", posts)
5454
end
5555
years.each do |year, posts|
5656
@archives << Archive.new(@site, { :year => year }, "year", posts)

lib/jekyll-archives/archive.rb

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,33 @@ class Archive
1010
# Attributes for Liquid templates
1111
ATTRIBUTES_FOR_LIQUID = %w[
1212
posts
13+
title
1314
type
1415
]
1516

1617
# Initialize a new Archive page
1718
#
1819
# site - The Site object.
19-
# name - The name of the tag/category or a Hash of the year/month/day in case of date.
20+
# title - The name of the tag/category or a Hash of the year/month/day in case of date.
2021
# e.g. { :year => 2014, :month => 08 } or "my-category" or "my-tag".
2122
# type - The type of archive. Can be one of "year", "month", "day", "category", or "tag"
2223
# posts - The array of posts that belong in this archive.
23-
def initialize(site, name, type, posts)
24+
def initialize(site, title, type, posts)
2425
@site = site
2526
@posts = posts
2627
@type = type
27-
@name = name
28+
@title = title
2829

2930
# Generate slug if tag or category (taken from jekyll/jekyll/features/support/env.rb)
30-
if name.is_a? String
31-
@slug = name.split(" ").map { |w|
31+
if title.is_a? String
32+
@slug = title.split(" ").map { |w|
3233
w.downcase.gsub(/[^\w]/, '')
3334
}.join("-")
3435
end
3536

3637
# Use ".html" for file extension and url for path
3738
@ext = ".html"
38-
@path = url
39+
@name = @path = url
3940

4041
@data = {
4142
"layout" => site.config['jekyll-archives']['layout']
@@ -53,8 +54,8 @@ def template
5354
# Returns a hash of URL placeholder names (as symbols) mapping to the
5455
# desired placeholder replacements. For details see "url.rb".
5556
def url_placeholders
56-
if @name.is_a? Hash
57-
@name.merge({ :type => @type })
57+
if @title.is_a? Hash
58+
@title.merge({ :type => @type })
5859
else
5960
{ :name => @slug, :type => @type }
6061
end
@@ -95,14 +96,20 @@ def to_liquid(attrs = nil)
9596
[attribute, send(attribute)]
9697
}]
9798

98-
further_data["name"] = if @name.is_a? Hash
99-
args = @name.values.map { |s| s.to_i }
99+
Utils.deep_merge_hashes(data, further_data)
100+
end
101+
102+
# Produce a title object suitable for Liquid based on type of archive.
103+
#
104+
# Returns the title as a Date (for date-based archives) or a
105+
# String (for tag and category archives)
106+
def title
107+
if @title.is_a? Hash
108+
args = @title.values.map { |s| s.to_i }
100109
Date.new(*args)
101110
else
102-
@name
111+
@title
103112
end
104-
105-
Utils.deep_merge_hashes(data, further_data)
106113
end
107114

108115
# Obtain destination path.
@@ -127,7 +134,7 @@ def relative_path
127134

128135
# Returns the object as a debug String.
129136
def inspect
130-
"#<Jekyll:Archive @type=#{@type.to_s} @name=#{@name}>"
137+
"#<Jekyll:Archive @type=#{@type.to_s} @title=#{@title}>"
131138
end
132139

133140
# Returns the Boolean of whether this Page is HTML or not.

0 commit comments

Comments
 (0)