Skip to content

Commit 8977e11

Browse files
committed
Merge pull request #17 from jekyll/ready-release
Release v1.0.0
2 parents 7d1aea8 + 5d08372 commit 8977e11

File tree

6 files changed

+296
-263
lines changed

6 files changed

+296
-263
lines changed

History.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## 1.0.0 / 2014-09-26
2+
3+
### Major Enhancements
4+
* Support type-specific layouts
5+
* Pass `Date` object to Liquid in case of date-based archives
6+
* Liquid `{{ site.archives }}` support
7+
* Generate month and day archives
8+
9+
### Minor Enhancements
10+
* Add version file and move everything into `Archives` module
11+
* Use `Jekyll::Utils.slugify` for slugging
12+
* Require use to specify what types of archives are enabled
13+
14+
## 0.1.0 / 2014-08-17
15+
* First release
16+
* Generate year, category, and tag archives
17+
18+
## 0.0.0 / 2014-08-17
19+
* Birthday!

jekyll-archives.gemspec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
lib = File.expand_path('../lib', __FILE__)
2+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3+
require 'jekyll-archives/version'
4+
15
Gem::Specification.new do |s|
26
s.name = "jekyll-archives"
37
s.summary = "Post archives for Jekyll."
48
s.description = "Automatically generate post archives by dates, tags, and categories."
5-
s.version = "0.1.0"
9+
s.version = Jekyll::Archives::VERSION
610
s.authors = ["Alfred Xing"]
711

812
s.homepage = "https://github.com/jekyll/jekyll-archives"

lib/jekyll-archives.rb

Lines changed: 125 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,162 @@
11
require 'jekyll'
22

33
module Jekyll
4-
# Internal requires
5-
autoload :Archive, 'jekyll-archives/archive'
6-
7-
class Archives < Jekyll::Generator
8-
safe true
9-
10-
DEFAULTS = {
11-
'layout' => 'archive',
12-
'enabled' => [],
13-
'permalinks' => {
14-
'year' => '/:year/',
15-
'month' => '/:year/:month/',
16-
'day' => '/:year/:month/:day/',
17-
'tag' => '/tag/:name/',
18-
'category' => '/category/:name/'
4+
module Archives
5+
# Internal requires
6+
autoload :Archive, 'jekyll-archives/archive'
7+
autoload :VERSION, 'jekyll-archives/version'
8+
9+
class Archives < Jekyll::Generator
10+
safe true
11+
12+
DEFAULTS = {
13+
'layout' => 'archive',
14+
'enabled' => [],
15+
'permalinks' => {
16+
'year' => '/:year/',
17+
'month' => '/:year/:month/',
18+
'day' => '/:year/:month/:day/',
19+
'tag' => '/tag/:name/',
20+
'category' => '/category/:name/'
21+
}
1922
}
20-
}
2123

22-
def initialize(config = nil)
23-
if config['jekyll-archives'].nil?
24-
@config = DEFAULTS
25-
else
26-
@config = Utils.deep_merge_hashes(DEFAULTS, config['jekyll-archives'])
24+
def initialize(config = nil)
25+
if config['jekyll-archives'].nil?
26+
@config = DEFAULTS
27+
else
28+
@config = Utils.deep_merge_hashes(DEFAULTS, config['jekyll-archives'])
29+
end
2730
end
28-
end
2931

30-
def generate(site)
31-
@site = site
32-
@posts = site.posts
33-
@archives = []
32+
def generate(site)
33+
@site = site
34+
@posts = site.posts
35+
@archives = []
3436

35-
@site.config['jekyll-archives'] = @config
37+
@site.config['jekyll-archives'] = @config
3638

37-
read
38-
render
39-
write
39+
read
40+
render
41+
write
4042

41-
@site.keep_files ||= []
42-
@archives.each do |archive|
43-
@site.keep_files << archive.relative_path
43+
@site.keep_files ||= []
44+
@archives.each do |archive|
45+
@site.keep_files << archive.relative_path
46+
end
47+
@site.config["archives"] = @archives
4448
end
45-
@site.config["archives"] = @archives
46-
end
4749

48-
# Read archive data from posts
49-
def read
50-
read_tags
51-
read_categories
52-
read_dates
53-
end
50+
# Read archive data from posts
51+
def read
52+
read_tags
53+
read_categories
54+
read_dates
55+
end
5456

55-
def read_tags
56-
if enabled? "tags"
57-
tags.each do |title, posts|
58-
@archives << Archive.new(@site, title, "tag", posts)
57+
def read_tags
58+
if enabled? "tags"
59+
tags.each do |title, posts|
60+
@archives << Archive.new(@site, title, "tag", posts)
61+
end
5962
end
6063
end
61-
end
6264

63-
def read_categories
64-
if enabled? "categories"
65-
categories.each do |title, posts|
66-
@archives << Archive.new(@site, title, "category", posts)
65+
def read_categories
66+
if enabled? "categories"
67+
categories.each do |title, posts|
68+
@archives << Archive.new(@site, title, "category", posts)
69+
end
6770
end
6871
end
69-
end
7072

71-
def read_dates
72-
years.each do |year, posts|
73-
@archives << Archive.new(@site, { :year => year }, "year", posts) if enabled? "year"
74-
months(posts).each do |month, posts|
75-
@archives << Archive.new(@site, { :year => year, :month => month }, "month", posts) if enabled? "month"
76-
days(posts).each do |day, posts|
77-
@archives << Archive.new(@site, { :year => year, :month => month, :day => day }, "day", posts) if enabled? "day"
73+
def read_dates
74+
years.each do |year, posts|
75+
@archives << Archive.new(@site, { :year => year }, "year", posts) if enabled? "year"
76+
months(posts).each do |month, posts|
77+
@archives << Archive.new(@site, { :year => year, :month => month }, "month", posts) if enabled? "month"
78+
days(posts).each do |day, posts|
79+
@archives << Archive.new(@site, { :year => year, :month => month, :day => day }, "day", posts) if enabled? "day"
80+
end
7881
end
7982
end
8083
end
81-
end
8284

83-
# Checks if archive type is enabled in config
84-
def enabled?(archive)
85-
@config["enabled"] == true || @config["enabled"] == "all" || if @config["enabled"].is_a? Array
86-
@config["enabled"].include? archive
85+
# Checks if archive type is enabled in config
86+
def enabled?(archive)
87+
@config["enabled"] == true || @config["enabled"] == "all" || if @config["enabled"].is_a? Array
88+
@config["enabled"].include? archive
89+
end
8790
end
88-
end
8991

90-
# Renders the archives into the layouts
91-
def render
92-
payload = @site.site_payload
93-
@archives.each do |archive|
94-
archive.render(@site.layouts, payload)
92+
# Renders the archives into the layouts
93+
def render
94+
payload = @site.site_payload
95+
@archives.each do |archive|
96+
archive.render(@site.layouts, payload)
97+
end
9598
end
96-
end
9799

98-
# Write archives to their destination
99-
def write
100-
@archives.each do |archive|
101-
archive.write(@site.dest)
100+
# Write archives to their destination
101+
def write
102+
@archives.each do |archive|
103+
archive.write(@site.dest)
104+
end
102105
end
103-
end
104106

105-
# Construct a Hash of Posts indexed by the specified Post attribute.
106-
#
107-
# post_attr - The String name of the Post attribute.
108-
#
109-
# Examples
110-
#
111-
# post_attr_hash('categories')
112-
# # => { 'tech' => [<Post A>, <Post B>],
113-
# # 'ruby' => [<Post B>] }
114-
#
115-
# Returns the Hash: { attr => posts } where
116-
# attr - One of the values for the requested attribute.
117-
# posts - The Array of Posts with the given attr value.
118-
#
119-
# Taken from jekyll/jekyll (Copyright (c) 2014 Tom Preston-Werner under the MIT).
120-
def post_attr_hash(post_attr)
121-
# Build a hash map based on the specified post attribute ( post attr =>
122-
# array of posts ) then sort each array in reverse order.
123-
hash = Hash.new { |h, key| h[key] = [] }
124-
@posts.each { |p| p.send(post_attr.to_sym).each { |t| hash[t] << p } }
125-
hash.values.each { |posts| posts.sort!.reverse! }
126-
hash
127-
end
107+
# Construct a Hash of Posts indexed by the specified Post attribute.
108+
#
109+
# post_attr - The String name of the Post attribute.
110+
#
111+
# Examples
112+
#
113+
# post_attr_hash('categories')
114+
# # => { 'tech' => [<Post A>, <Post B>],
115+
# # 'ruby' => [<Post B>] }
116+
#
117+
# Returns the Hash: { attr => posts } where
118+
# attr - One of the values for the requested attribute.
119+
# posts - The Array of Posts with the given attr value.
120+
#
121+
# Taken from jekyll/jekyll (Copyright (c) 2014 Tom Preston-Werner under the MIT).
122+
def post_attr_hash(post_attr)
123+
# Build a hash map based on the specified post attribute ( post attr =>
124+
# array of posts ) then sort each array in reverse order.
125+
hash = Hash.new { |h, key| h[key] = [] }
126+
@posts.each { |p| p.send(post_attr.to_sym).each { |t| hash[t] << p } }
127+
hash.values.each { |posts| posts.sort!.reverse! }
128+
hash
129+
end
128130

129-
def tags
130-
post_attr_hash('tags')
131-
end
131+
def tags
132+
post_attr_hash('tags')
133+
end
132134

133-
def categories
134-
post_attr_hash('categories')
135-
end
135+
def categories
136+
post_attr_hash('categories')
137+
end
136138

137-
# Custom `post_attr_hash` method for years
138-
def years
139-
hash = Hash.new { |h, key| h[key] = [] }
140-
@posts.each { |p| hash[p.date.strftime("%Y")] << p }
141-
hash.values.each { |posts| posts.sort!.reverse! }
142-
hash
143-
end
139+
# Custom `post_attr_hash` method for years
140+
def years
141+
hash = Hash.new { |h, key| h[key] = [] }
142+
@posts.each { |p| hash[p.date.strftime("%Y")] << p }
143+
hash.values.each { |posts| posts.sort!.reverse! }
144+
hash
145+
end
144146

145-
def months(year_posts)
146-
hash = Hash.new { |h, key| h[key] = [] }
147-
year_posts.each { |p| hash[p.date.strftime("%m")] << p }
148-
hash.values.each { |posts| posts.sort!.reverse! }
149-
hash
150-
end
147+
def months(year_posts)
148+
hash = Hash.new { |h, key| h[key] = [] }
149+
year_posts.each { |p| hash[p.date.strftime("%m")] << p }
150+
hash.values.each { |posts| posts.sort!.reverse! }
151+
hash
152+
end
151153

152-
def days(month_posts)
153-
hash = Hash.new { |h, key| h[key] = [] }
154-
month_posts.each { |p| hash[p.date.strftime("%d")] << p }
155-
hash.values.each { |posts| posts.sort!.reverse! }
156-
hash
154+
def days(month_posts)
155+
hash = Hash.new { |h, key| h[key] = [] }
156+
month_posts.each { |p| hash[p.date.strftime("%d")] << p }
157+
hash.values.each { |posts| posts.sort!.reverse! }
158+
hash
159+
end
157160
end
158161
end
159162
end

0 commit comments

Comments
 (0)