SitemapGenerator is a framework-agnostic XML Sitemap generator written in Ruby with automatic Rails integration. It supports Video, News, Image, Mobile, PageMap and Alternate Links sitemap extensions and includes Rake tasks for managing your sitemaps, as well as many other great features.
MIT License
2.44k
stars
276
forks
source link
Feature request : Make `default_host` optional / Allow full URL instead of path #414
The SitemapGenerator::Sitemap.default_host is required and always added to the URL passed as #add first argument, even when the URL has a protocol and a host.
Code
SitemapGenerator::Sitemap.default_host = "https://dont-want-to-use.it"
SitemapGenerator::Sitemap.create do
each_locale do |locale|
each_page do |page|
main_url = page.url(only_path: false, host: host_for_locale(locale))
alternate = each_locale.map { |locale| page.url(only_path: false, host: host_for_locale(locale)) }
add main_url, alternate: alternate
end
end
end
Just in case, some helpers definitions :
def each_locale(&block)
return to_enum(:each_locale) unless block_given?
I18n.locales.each do |locale|
I18n.locale = locale
yield locale
end
end
def each_page(&block)
Page.with_locale(I18n.locale).find_each(&block)
end
def host_for_locale(locale)
locale == fr ? "myhost.fr" : "myhost.com"
end
Goal
I'm trying to reproduce this Google documentation example which uses multiple hosts :
Problem
The
SitemapGenerator::Sitemap.default_host
is required and always added to the URL passed as#add
first argument, even when the URL has a protocol and a host.Code
Just in case, some helpers definitions :
But the result looks like this :
Did I miss something ? Is there any other way to reproduce the sitemap above ?
Thank you !