Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds some basic support for archiving by language #108

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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