-
-
Save dmitry/4341237 to your computer and use it in GitHub Desktop.
Shows how to generate sitemap with sitemap_generator gem for multilingual site and set rewrite urls in nginx conf.
This file contains hidden or 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
rewrite ^/sitemap1.xml.gz /sitemaps/$host/sitemap1.xml.gz last; | |
rewrite ^/sitemap_index.xml.gz /sitemaps/$host/sitemap_index.xml.gz last; | |
# or | |
location /sitemap { | |
# it can be already switched on for globally | |
# gzip_static on; | |
rewrite ^/sitemap.xml /sitemaps/$host/sitemap.xml last; # that's will catch .gz files and served as normal static file, but with gzip header | |
} |
This file contains hidden or 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
require 'rubygems' | |
require 'sitemap_generator' | |
# Constants::HOSTS = {'www.site.com' => :en, 'www.site.de' => :de} | |
Constants::HOSTS.each do |host, locale| | |
SitemapGenerator::Sitemap.default_host = "http://#{host}" | |
SitemapGenerator::Sitemap.public_path = "public/sitemaps/#{host}" | |
SitemapGenerator::Sitemap.sitemaps_path = '' | |
SitemapGenerator::Sitemap.create do | |
add root_path, priority: 1 | |
Property.find_each do |property| | |
add property_path(property), | |
priority: 0.8, | |
lastmod: (property.updated_at || property.created_at), | |
alternates: Constants::HOSTS.map { |h, l| | |
if locale != l | |
{ | |
href: property_url(property, host: h), | |
lang: l | |
} | |
end | |
}.compact | |
end | |
end | |
SitemapGenerator::Sitemap.ping_search_engines | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment