Giter Site home page Giter Site logo

Comments (5)

kjvarga avatar kjvarga commented on July 16, 2024

Hi @tulios. I'm glad you asked this question and it's nice to see someone using Sitemap Groups and Namers in the wild! I think I have a more elegant solution which uses the existing features of the code to accomplish this.

First I want to give an example where all we are doing is generating the sitemap index. We add links to the index like would add them to a regular sitemap file. The use of group in this example simply prevents any sitemap files being created:

SitemapGenerator::Sitemap.sitemaps_namer = SitemapGenerator::SitemapNamer.new("my-sitemap")
SitemapGenerator::Sitemap.default_host = "http://www.example.com"
SitemapGenerator::Sitemap.create do
  group do
    3.times do
      @linkset.sitemap_index.add(@linkset.sitemaps_namer.to_s, :host => @linkset.default_host)
      @linkset.sitemaps_namer.next
    end
  end
end

[karl@karl-vargas-macbook-pro sitemap_generator-test (standalone*)]$ ruby sitemap.rb 
In /Users/karl/projects/sitemap_generator-test/public/
+ sitemap_index.xml.gz                                  3 sitemaps /  243 Bytes
Sitemap stats: 0 links / 3 sitemaps / 0m00s

<sitemap>
  <loc>http://www.example.com/my-sitemap1.xml.gz</loc>
  <lastmod>2012-02-06T10:06:45-08:00</lastmod>
</sitemap>
<sitemap>
  <loc>http://www.example.com/my-sitemap2.xml.gz</loc>
  <lastmod>2012-02-06T10:06:45-08:00</lastmod>
</sitemap>
<sitemap>
  <loc>http://www.example.com/my-sitemap3.xml.gz</loc>
  <lastmod>2012-02-06T10:06:45-08:00</lastmod>
</sitemap>

Now in your case you do want to generate some extra sitemap files so you can just do something like:

SitemapGenerator::Sitemap.sitemaps_namer = SitemapGenerator::SitemapNamer.new("my-sitemap")
SitemapGenerator::Sitemap.default_host = "http://www.example.com"
SitemapGenerator::Sitemap.create do
  3.times do
    @linkset.sitemap_index.add(@linkset.sitemaps_namer.to_s, :host => @linkset.default_host)
    @linkset.sitemaps_namer.next
  end
  add '/home'
  add '/whatever'
end

[karl@karl-vargas-macbook-pro sitemap_generator-test (standalone*)]$ ruby sitemap.rb 
In /Users/karl/projects/sitemap_generator-test/public/
+ my-sitemap4.xml.gz                                       4 links /  347 Bytes
+ sitemap_index.xml.gz                                  4 sitemaps /  245 Bytes
Sitemap stats: 4 links / 4 sitemaps / 0m00s

from sitemap_generator.

tulios avatar tulios commented on July 16, 2024

Awesome! I avoided to use the instance variable @linkset because it is for intern usage and you could break the api in the next release. Could we wrap this call (@linkset.sitemap_index) in a official api method? Something like add_to_index...

from sitemap_generator.

kjvarga avatar kjvarga commented on July 16, 2024

Hey man, yeah thats not a bad idea. I will at least add a method called 'sitemap' to replace using the instance variable. But an add_to_index method makes sense too.

from sitemap_generator.

kjvarga avatar kjvarga commented on July 16, 2024

Ok this is fixed in v3.1.0

from sitemap_generator.

tulios avatar tulios commented on July 16, 2024

Awesome!

from sitemap_generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.