Skip to content

Commit

Permalink
adds basic language archiving support
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommy committed Apr 23, 2018
1 parent 815e72b commit 6de925a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions History.markdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## HEAD

### Major Enhancements

* Adds support for archiving by language

### Minor Enhancements

* Make Archive subclass of Page (#67)
Expand Down
25 changes: 21 additions & 4 deletions lib/jekyll-archives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -47,6 +48,7 @@ def read
read_tags
read_categories
read_dates
read_languages
end

def read_tags
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 6de925a

Please sign in to comment.