From e681379e055329522a8c480c1314405a0a060f74 Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 21 Jun 2017 12:54:06 -0700 Subject: [PATCH] adds some basic support for archiving by language --- History.markdown | 4 ++++ lib/jekyll-archives.rb | 25 +++++++++++++++++++++---- lib/jekyll-archives/archive.rb | 2 +- 3 files changed, 26 insertions(+), 5 deletions(-) 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 diff --git a/lib/jekyll-archives/archive.rb b/lib/jekyll-archives/archive.rb index 66585bf..8b031fb 100644 --- a/lib/jekyll-archives/archive.rb +++ b/lib/jekyll-archives/archive.rb @@ -39,7 +39,7 @@ def initialize(site, title, type, posts) @name = File.basename(relative_path, @ext) @data = { - "layout" => layout + "layout" => layout, } @content = "" end