Last active
December 17, 2015 07:39
-
-
Save harish86/5574792 to your computer and use it in GitHub Desktop.
Building xml sitemaps in rails.
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
# Below is a snippet to generate sitemap.xml file | |
# Reference: http://www.sitemaps.org, http://en.wikipedia.org/wiki/Site_map, http://support.google.com/webmasters/bin/answer.py?hl=en&answer=183668&topic=8476&ctx=topic | |
xml.instruct! | |
xml.urlset(:xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9") { | |
@items.each do |item| | |
xml.url { | |
xml.loc(item_url(item)) | |
xml.changefreq("daily") | |
xml.priority("0.5") | |
} | |
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
# Below is a snippet to generate sitemap.xml file | |
# Reference: http://www.sitemaps.org, http://en.wikipedia.org/wiki/Site_map, http://support.google.com/webmasters/bin/answer.py?hl=en&answer=183668&topic=8476&ctx=topic | |
xml.instruct! | |
xml.urlset(:xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9") { | |
@resources.each do |resource| | |
xml.url { | |
xml.loc(resource_url(resource)) | |
xml.changefreq("weekly") | |
xml.priority("0.5") | |
} | |
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
get "/sitemapindex.xml" => "welcome#sitemapindex", :as => :sitemapindex | |
resoureces :resources do | |
collection do | |
get :sitemap | |
end | |
end | |
resoureces :items do | |
collection do | |
get :sitemap | |
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
# Below is a snippet to generate sitemapindex.xml file. Sitemapindex file is required to list multiple sitemap files. Useful when the site has multiple sitemap files | |
# Reference: http://www.sitemaps.org, http://en.wikipedia.org/wiki/Sitemap_index, http://support.google.com/webmasters/bin/answer.py?hl=en&answer=71453 | |
xml.instruct! | |
xml.sitemapindex(:xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9") { | |
xml.sitemap { | |
xml.loc(sitemap_resources_url(:format => :xml)) | |
xml.lastmod(Time.zone.now.strftime("%Y-%m-%d")) | |
} | |
xml.sitemap { | |
xml.loc(sitemap_items_url(:format => :xml)) | |
xml.lastmod(Time.zone.now.strftime("%Y-%m-%d")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment