Skip to content

Commit e681379

Browse files
author
Tom
committed
adds some basic support for archiving by language
1 parent 815e72b commit e681379

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

History.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## HEAD
22

3+
### Major Enhancements
4+
5+
* Adds support for archiving by language
6+
37
### Minor Enhancements
48

59
* Make Archive subclass of Page (#67)

lib/jekyll-archives.rb

+21-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ class Archives < Jekyll::Generator
1717
"month" => "/:year/:month/",
1818
"day" => "/:year/:month/:day/",
1919
"tag" => "/tag/:name/",
20-
"category" => "/category/:name/"
21-
}
20+
"category" => "/category/:name/",
21+
"language" => "/language/:name/",
22+
},
2223
}.freeze
2324

2425
def initialize(config = nil)
@@ -47,6 +48,7 @@ def read
4748
read_tags
4849
read_categories
4950
read_dates
51+
read_languages
5052
end
5153

5254
def read_tags
@@ -77,11 +79,21 @@ def read_dates
7779
end
7880
end
7981

82+
def read_languages
83+
if enabled? "language"
84+
languages.each do |language, posts|
85+
@archives << Archive.new(@site, language, "language", posts)
86+
end
87+
end
88+
end
89+
8090
# Checks if archive type is enabled in config
8191
def enabled?(archive)
82-
@config["enabled"] == true || @config["enabled"] == "all" || if @config["enabled"].is_a? Array
83-
@config["enabled"].include? archive
92+
if @config["enabled"].is_a? Array
93+
return @config["enabled"].include? archive
8494
end
95+
96+
@config["enabled"] == true || @config["enabled"] == "all"
8597
end
8698

8799
def tags
@@ -119,6 +131,11 @@ def days(month_posts)
119131
hash.values.each { |posts| posts.sort!.reverse! }
120132
hash
121133
end
134+
135+
# TODO: would prefer to enable arbitrary front-matter archiving, but this'll do for now. Also would prefer that language isnt an array, but just doing like categories frontmatter for now.
136+
def languages
137+
@site.post_attr_hash("language")
138+
end
122139
end
123140
end
124141
end

lib/jekyll-archives/archive.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def initialize(site, title, type, posts)
3939
@name = File.basename(relative_path, @ext)
4040

4141
@data = {
42-
"layout" => layout
42+
"layout" => layout,
4343
}
4444
@content = ""
4545
end

0 commit comments

Comments
 (0)