Skip to content

Commit

Permalink
adds some basic support for archiving by language
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom committed Jun 21, 2017
1 parent 815e72b commit e681379
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 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
2 changes: 1 addition & 1 deletion lib/jekyll-archives/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def initialize(site, title, type, posts)
@name = File.basename(relative_path, @ext)

@data = {
"layout" => layout
"layout" => layout,
}
@content = ""
end
Expand Down

0 comments on commit e681379

Please sign in to comment.