-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae171e7
commit 0173783
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# {% year_utilities %} | ||
# Returns a list of links to all years that have posts in them | ||
# | ||
# To install, copy this file into your Jekyll/Octopress plugins folder | ||
# To use: {% year_utilities PARAMETER %} | ||
# | ||
# PARAMETER can be: | ||
# year_links (returns a list of links to all years that have posts in them) | ||
|
||
module Jekyll | ||
class YearUtilities < Liquid::Tag | ||
def initialize(tag, text, tokens) | ||
super | ||
@tag = tag | ||
@text = text.strip | ||
@tokens = tokens | ||
end | ||
|
||
def render(context) | ||
the_result = nil | ||
|
||
all_posts = context.registers[:site].posts.docs | ||
years = all_posts.map { |post| post.date.year }.uniq | ||
|
||
if @text.start_with? "year_links" | ||
years.map { |year| "<a href='/#{year}/' class='year-link'>#{year}</a>" }.join(', ') | ||
end | ||
|
||
return the_result | ||
end | ||
end | ||
end | ||
|
||
Liquid::Template.register_tag('year_utilities', Jekyll::YearUtilities) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
layout: page | ||
title: Archives | ||
--- | ||
|
||
<h2>Yearly archives</h2> | ||
{% year_utilities year_links %} |