Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sitemap for multiple domain #24

Closed
chamnap opened this issue Dec 15, 2010 · 7 comments
Closed

Sitemap for multiple domain #24

chamnap opened this issue Dec 15, 2010 · 7 comments

Comments

@chamnap
Copy link

chamnap commented Dec 15, 2010

I have a rails 2.3.2 application which handles around 5 domains. I just can't figure out how to use well. I need to create a new rake task to generate sitemap for a domain, put it in a separate folder. I need a rake task to generate sitemap for all domains, put them in a separate folder (for each domain).

Any idea?

@kjvarga
Copy link
Owner

kjvarga commented Dec 15, 2010

Hi chamnap,

You are in luck! If you had asked a little while ago, it would have been very difficult, but recent changes I've made make it very easy.

I'm still working on the API, so this consider this experimental stuff. Put this in your config/sitemap.rb and refresh your sitemaps. You'll get an exception at the end, but the sitemaps should be created ok.

Alternatively you can add require 'sitemap_generator' to the script and run it with ./script/runner config/sitemap.rb and you won't get an exception, but you also won't see the stats output.

SitemapGenerator::Sitemap.yahoo_app_id = false

SitemapGenerator::Sitemap.sitemaps_path = "en/"
SitemapGenerator::Sitemap.default_host = "http://www.en.example.com"
SitemapGenerator::Sitemap.create do
  add '/english-site'
end

SitemapGenerator::Sitemap.sitemaps_path = "fr/"
SitemapGenerator::Sitemap.default_host = "http://www.fr.example.com"
SitemapGenerator::Sitemap.create do 
  add '/french-site'
end

SitemapGenerator::Sitemap.sitemaps_path = "ru/"
SitemapGenerator::Sitemap.default_host = "http://www.ru.example.com"
SitemapGenerator::Sitemap.create do 
  add '/russian-site'
end

@chamnap
Copy link
Author

chamnap commented Dec 15, 2010

Alright, thanks for reply. I figured out by go through the code base, but a slicely different approach.

@kjvarga
Copy link
Owner

kjvarga commented Dec 16, 2010

Closing

@chamnap
Copy link
Author

chamnap commented Dec 20, 2010

It seems it doesn't work in a loop. The first domain is generated correctly in sitemap file, but the rest doesn't (only example.com).

@kjvarga
Copy link
Owner

kjvarga commented Dec 20, 2010

What do you mean "it doesn't work in a loop"? You'll have to paste your code for me to understand what you mean. The example I gave works fine, as does this:

SitemapGenerator::Sitemap.yahoo_app_id = false

%w[en fr ru].each do |domain|
  SitemapGenerator::Sitemap.sitemaps_path = "#{domain}/"
  SitemapGenerator::Sitemap.default_host = "http://www.#{domain}.example.com"
  SitemapGenerator::Sitemap.create do
    add '/whatever'
  end
end

@chamnap
Copy link
Author

chamnap commented Dec 22, 2010

Well, the above code works fine, except in the sitemap file of the second and third domain name, the generated domain name is http://example.com/.

@kjvarga
Copy link
Owner

kjvarga commented Dec 22, 2010

Hmm, yeah the host in the sitemap file e.g. sitemap1.xml is correct, but the host in the index file is not.

I'll take a look when I get a chance.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants