Comments (5)
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.
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.
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.
Ok this is fixed in v3.1.0
from sitemap_generator.
Awesome!
from sitemap_generator.
Related Issues (20)
- Ping failed for Bing: #<OpenURI::HTTPError: 410 Gone> HOT 2
- Feature Request: Remove unwanted options HOT 6
- Is it possible to override the default link options? HOT 3
- How to remove default priority, lastmod and changefreq from all urls HOT 1
- GoogleStorageAdapter - Can't create sitemap on buckets with uniform bucket-level access enabled HOT 3
- Allow disable acl for S3 bucket HOT 1
- Rails on Heroku with S3 sitemap hosting - google didn't like it HOT 2
- 【Worked】Ping failed for Bing: #<OpenURI::HTTPError: 410 Gone> HOT 4
- Is it possible to add additional metadata fields to the xml HOT 5
- Feature request : Make `default_host` optional / Allow full URL instead of path HOT 2
- Entity escaping in XML output
- google search console couldn't fetch sitemap but index is ok HOT 7
- Google search correct ping url HOT 2
- Readme install instructions fail HOT 1
- [BUG] Mobile sitemap link in Readme.md is giving 404
- TimeZone is ignored
- sitemap.xml.gz file not found on server
- Testing with frozen time does not work
- should sitemap show up automatically in google search console? HOT 2
- Should we drop default `lastmod` of `Time.now` as Google says "it needs to consistently match reality"? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sitemap_generator.