forked from middleman/middleman-blog
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move calendar/tag stuff to separate files, clean up a bit
- Loading branch information
Showing
5 changed files
with
146 additions
and
143 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
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
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,97 @@ | ||
module Middleman | ||
module Blog | ||
|
||
# A sitemap plugin that adds month/day/year pages to the sitemap | ||
# based on the dates of blog articles. | ||
class CalendarPages | ||
def initialize(app) | ||
@app = app | ||
end | ||
|
||
# Update the main sitemap resource list | ||
# @return [void] | ||
def manipulate_resource_list(resources) | ||
new_resources = [] | ||
# Set up date pages if the appropriate templates have been specified | ||
@app.blog.articles.group_by {|a| a.date.year }.each do |year, year_articles| | ||
if @app.respond_to? :blog_year_template | ||
@app.ignore @app.blog_year_template | ||
|
||
path = Middleman::Util.normalize_path(@app.blog_year_path(year)) | ||
|
||
p = ::Middleman::Sitemap::Resource.new( | ||
@app.sitemap, | ||
path | ||
) | ||
p.proxy_to(@app.blog_year_template) | ||
|
||
set_locals_year = Proc.new do | ||
@year = year | ||
@articles = year_articles | ||
end | ||
|
||
@app.sitemap.provides_metadata_for_path path do |path| | ||
{ :blocks => set_locals_year } | ||
end | ||
|
||
new_resources << p | ||
end | ||
|
||
year_articles.group_by {|a| a.date.month }.each do |month, month_articles| | ||
if @app.respond_to? :blog_month_template | ||
@app.ignore @app.blog_month_template | ||
|
||
path = Middleman::Util.normalize_path(@app.blog_month_path(year, month)) | ||
|
||
p = ::Middleman::Sitemap::Resource.new( | ||
@app.sitemap, | ||
path | ||
) | ||
p.proxy_to(@app.blog_month_template) | ||
|
||
set_locals_month = Proc.new do | ||
@year = year | ||
@month = month | ||
@articles = month_articles | ||
end | ||
|
||
@app.sitemap.provides_metadata_for_path path do |path| | ||
{ :blocks => [ set_locals_month ] } | ||
end | ||
|
||
new_resources << p | ||
end | ||
|
||
month_articles.group_by {|a| a.date.day }.each do |day, day_articles| | ||
if @app.respond_to? :blog_day_template | ||
@app.ignore @app.blog_day_template | ||
|
||
path = Middleman::Util.normalize_path(@app.blog_day_path(year, month, day)) | ||
p = ::Middleman::Sitemap::Resource.new( | ||
@app.sitemap, | ||
path | ||
) | ||
p.proxy_to(@app.blog_month_template) | ||
|
||
set_locals_day = Proc.new do | ||
@year = year | ||
@month = month | ||
@day = day | ||
@articles = day_articles | ||
end | ||
|
||
@app.sitemap.provides_metadata_for_path path do |path| | ||
{ :blocks => [ set_locals_day ] } | ||
end | ||
|
||
new_resources << p | ||
end | ||
end | ||
end | ||
end | ||
|
||
resources + new_resources | ||
end | ||
end | ||
end | ||
end |
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
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,39 @@ | ||
module Middleman | ||
module Blog | ||
|
||
# A sitemap plugin that adds tag pages to the sitemap | ||
# based on the tags of blog articles. | ||
class TagPages | ||
def initialize(app) | ||
@app = app | ||
end | ||
|
||
# Update the main sitemap resource list | ||
# @return [void] | ||
def manipulate_resource_list(resources) | ||
resources + @app.blog.tags.map do |tag, articles| | ||
path = @app.tag_path(tag) | ||
|
||
p = ::Middleman::Sitemap::Resource.new( | ||
@app.sitemap, | ||
path | ||
) | ||
p.proxy_to(@app.blog_tag_template) | ||
|
||
set_locals = Proc.new do | ||
@tag = tag | ||
@articles = articles | ||
end | ||
|
||
# TODO: how to keep from adding duplicates here? | ||
# How could we better set locals? | ||
@app.sitemap.provides_metadata_for_path path do |path| | ||
{ :blocks => [ set_locals ] } | ||
end | ||
|
||
p | ||
end | ||
end | ||
end | ||
end | ||
end |