Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* adding sitemap for Google/Bing/Yahoo and ping task
- Loading branch information
Showing
6 changed files
with
98 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
class SitemapController < ApplicationController | ||
#layout nil | ||
|
||
def index | ||
base_url = request.protocol + request.host_with_port | ||
latest_article = Article.published.first | ||
@pages = [] | ||
|
||
@pages << Page.new( | ||
:location => base_url, | ||
:last_modified_at => latest_article.published_at, | ||
:change_frequency => 'daily' | ||
) | ||
@pages << Page.new( | ||
:location => base_url + archive_path, | ||
:last_modified_at => latest_article.published_at, | ||
:change_frequency => 'daily' | ||
) | ||
|
||
Article.published.each do |article| | ||
@pages << Page.new( | ||
:location => base_url + article_path(article), | ||
:last_modified_at => article.last_updated_at, | ||
:change_frequency => 'weekly' | ||
) | ||
end | ||
Series.active.each do |series| | ||
articles = series.articles | ||
last_modified_at = if articles && articles.last.published_at > series.updated_at | ||
articles.last.published_at | ||
else | ||
series.updated_at | ||
end | ||
@pages << Page.new( | ||
:location => base_url + series_path(series), | ||
:last_modified_at => last_modified_at, | ||
:change_frequency => 'daily' | ||
) | ||
end | ||
|
||
if stale?(:etag => latest_article, :last_modified => latest_article.updated_at.utc) | ||
respond_to do |format| | ||
format.xml { render :layout => nil } | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
class Page | ||
attr_accessor :location, :last_modified_at, :change_frequency | ||
|
||
def initialize(params) | ||
self.location = params[:location] | ||
self.last_modified_at = params[:updated_at] | ||
self.change_frequency = params[:change_frequency] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module SitemapHelper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
xml.instruct! :xml, :version=>'1.0' | ||
xml.tag! 'urlset', 'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9' do | ||
@pages.each do |page| | ||
xml.tag! 'url' do | ||
xml.tag! 'loc', page.location | ||
xml.tag! 'lastmod', page.last_modified_at | ||
xml.tag! 'changefreq', page.change_frequency | ||
#xml.tag! 'priority', '0.5' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
title: Askja | ||
|
||
# Used for `rake top` to get top articles from Analytics | ||
analytics_id: | ||
|
||
# Used for `rake ping`, no trailing slash | ||
url: |
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