diff --git a/History.markdown b/History.markdown index d908151..5a1adfc 100644 --- a/History.markdown +++ b/History.markdown @@ -1,5 +1,9 @@ ## HEAD +### Major Enhancements + + * Adds support for archiving by language + ### Minor Enhancements * Make Archive subclass of Page (#67) diff --git a/lib/jekyll-archives.rb b/lib/jekyll-archives.rb index 18cde72..5636c62 100644 --- a/lib/jekyll-archives.rb +++ b/lib/jekyll-archives.rb @@ -17,8 +17,9 @@ class Archives < Jekyll::Generator "month" => "/:year/:month/", "day" => "/:year/:month/:day/", "tag" => "/tag/:name/", - "category" => "/category/:name/" - } + "category" => "/category/:name/", + "language" => "/language/:name/", + }, }.freeze def initialize(config = nil) @@ -47,6 +48,7 @@ def read read_tags read_categories read_dates + read_languages end def read_tags @@ -77,11 +79,21 @@ def read_dates end end + def read_languages + if enabled? "language" + languages.each do |language, posts| + @archives << Archive.new(@site, language, "language", posts) + end + end + end + # Checks if archive type is enabled in config def enabled?(archive) - @config["enabled"] == true || @config["enabled"] == "all" || if @config["enabled"].is_a? Array - @config["enabled"].include? archive + if @config["enabled"].is_a? Array + return @config["enabled"].include? archive end + + @config["enabled"] == true || @config["enabled"] == "all" end def tags @@ -119,6 +131,11 @@ def days(month_posts) hash.values.each { |posts| posts.sort!.reverse! } hash end + + # 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. + def languages + @site.post_attr_hash("language") + end end end end