sitemap_generator 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,9 +1,22 @@
1
1
  SitemapGenerator
2
2
  ================
3
3
 
4
- This plugin enables ['enterprise-class'][enterprise_class] Google Sitemaps to be easily generated for a Rails site as a rake task, using a simple 'Rails Routes'-like DSL.
4
+ A Rails 3-compatible gem/plugin to generate ['enterprise-class'][enterprise_class] Sitemaps using a familiar Rails Routes-like DSL. Sitemaps are readable by all search engines and adhere to the ['Sitemap protocol specification'][sitemap_protocol]. Automatically pings search engines to notify them of new sitemaps (including Google, Yahoo and Bing). Provides rake tasks to easily manage your sitemaps. Supports image sitemaps and handles millions of links.
5
5
 
6
- **Now supporting Rails 3 as of version 0.2.5!**
6
+ Features
7
+ -------
8
+
9
+ - v0.2.6: **Support ['image sitemaps'][sitemap_images]**!
10
+ - v0.2.5: **Support Rails 3**!
11
+
12
+ - Adheres to the ['Sitemap protocol specification'][sitemap_protocol]
13
+ - Handles millions of links
14
+ - Automatic Gzip of Sitemap files
15
+ - Automatic ping of search engines to notify them of new sitemaps: Google, Yahoo, Bing, Ask, SitemapWriter
16
+ - Won't clobber your old sitemaps if the new one fails to generate
17
+ - Set the priority of links, change frequency etc
18
+ - You control which links are included
19
+ - You set the host name, so it doesn't matter if your application is in a subdirectory
7
20
 
8
21
  Foreword
9
22
  -------
@@ -22,7 +35,7 @@ Installation
22
35
  <code>gem 'sitemap_generator'</code>
23
36
 
24
37
  2. `$ rake sitemap:install`
25
-
38
+
26
39
  **Rails 2.x: As a gem**
27
40
 
28
41
  1. Add the gem as a dependency in your <tt>config/environment.rb</tt>
@@ -49,14 +62,19 @@ Installation
49
62
 
50
63
  Installation creates a <tt>config/sitemap.rb</tt> file which will contain your logic for generating the Sitemap files. If you want to create this file manually run <code>rake sitemap:install</code>.
51
64
 
52
- You can run <code>rake sitemap:refresh</code> as needed to create Sitemap files. This will also ping all the ['major'][sitemap_engines] search engines. If you want to disable all non-essential output run the rake task with <code>rake -s sitemap:refresh</code>.
65
+ You can run <code>rake sitemap:refresh</code> as needed to create Sitemap files. This will also ping these ['major search engines'][sitemap_engines]: Google, Yahoo, Bing, Ask, SitemapWriter. If you want to disable all non-essential output run the rake task with <code>rake -s sitemap:refresh</code>.
53
66
 
54
- Sitemaps with many urls (100,000+) take quite a long time to generate, so if you need to refresh your Sitemaps regularly you can set the rake task up as a cron job. Most cron agents will only send you an email if there is output from the cron task.
67
+ To keep your Sitemaps up-to-date, setup a cron job. Pass the <tt>-s</tt> option to the rake task to silence all but the most important output. If you're using Whenever, then your schedule would look something like:
55
68
 
56
- Optionally, you can add the following to your <code>public/robots.txt</code> file, so that robots can find the sitemap file.
69
+ # config/schedule.rb
70
+ every 1.day, :at => '5:00 am' do
71
+ rake "-s sitemap:refresh"
72
+ end
73
+
74
+ Optionally, you can add the following to your <code>public/robots.txt</code> file, so that robots can find the sitemap file:
57
75
 
58
76
  Sitemap: <hostname>/sitemap_index.xml.gz
59
-
77
+
60
78
  The Sitemap URL in the robots file should be the complete URL to the Sitemap Index, such as <tt>http://www.example.org/sitemap_index.xml.gz</tt>
61
79
 
62
80
 
@@ -75,12 +93,12 @@ Example 'config/sitemap.rb'
75
93
  # Usage: sitemap.add path, options
76
94
  # (default options are used if you don't specify them)
77
95
  #
78
- # Defaults: :priority => 0.5, :changefreq => 'weekly',
96
+ # Defaults: :priority => 0.5, :changefreq => 'weekly',
79
97
  # :lastmod => Time.now, :host => default_host
80
98
 
81
-
99
+
82
100
  # Examples:
83
-
101
+
84
102
  # add '/articles'
85
103
  sitemap.add articles_path, :priority => 0.7, :changefreq => 'daily'
86
104
 
@@ -91,25 +109,30 @@ Example 'config/sitemap.rb'
91
109
 
92
110
  # add merchant path
93
111
  sitemap.add '/purchase', :priority => 0.7, :host => "https://www.example.com"
94
-
112
+
113
+ # add all individual news with images
114
+ News.all.each do |n|
115
+ sitemap.add news_path(n), :lastmod => n.updated_at, :images=>n.images.collect{ |r| :loc=>r.image.url, :title=>r.image.name }
116
+ end
117
+
95
118
  end
96
119
 
97
120
  # Including Sitemaps from Rails Engines.
98
121
  #
99
- # These Sitemaps should be almost identical to a regular Sitemap file except
122
+ # These Sitemaps should be almost identical to a regular Sitemap file except
100
123
  # they needn't define their own SitemapGenerator::Sitemap.default_host since
101
124
  # they will undoubtedly share the host name of the application they belong to.
102
125
  #
103
126
  # As an example, say we have a Rails Engine in vendor/plugins/cadability_client
104
127
  # We can include its Sitemap here as follows:
105
- #
128
+ #
106
129
  file = File.join(Rails.root, 'vendor/plugins/cadability_client/config/sitemap.rb')
107
130
  eval(open(file).read, binding, file)
108
131
 
109
132
  Raison d'être
110
133
  -------
111
134
 
112
- Most of the Sitemap plugins out there seem to try to recreate the Sitemap links by iterating the Rails routes. In some cases this is possible, but for a great deal of cases it isn't.
135
+ Most of the Sitemap plugins out there seem to try to recreate the Sitemap links by iterating the Rails routes. In some cases this is possible, but for a great deal of cases it isn't.
113
136
 
114
137
  a) There are probably quite a few routes in your routes file that don't need inclusion in the Sitemap. (AJAX routes I'm looking at you.)
115
138
 
@@ -118,7 +141,7 @@ and
118
141
  b) How would you infer the correct series of links for the following route?
119
142
 
120
143
  map.zipcode 'location/:state/:city/:zipcode', :controller => 'zipcode', :action => 'index'
121
-
144
+
122
145
  Don't tell me it's trivial, because it isn't. It just looks trivial.
123
146
 
124
147
  So my idea is to have another file similar to 'routes.rb' called 'sitemap.rb', where you can define what goes into the Sitemap.
@@ -133,22 +156,13 @@ Easy hey?
133
156
 
134
157
  Other Sitemap settings for the link, like `lastmod`, `priority`, `changefreq` and `host` are entered automatically, although you can override them if you need to.
135
158
 
136
- Other "difficult" Sitemap issues, solved by this plugin:
137
-
138
- - Support for more than 50,000 urls (using a Sitemap Index file)
139
- - Gzip of Sitemap files
140
- - Variable priority of links
141
- - Paging/sorting links (e.g. my_list?page=3)
142
- - SSL host links (e.g. https:)
143
- - Rails apps which are installed on a sub-path (e.g. example.com/blog_app/)
144
-
145
159
  Compatibility
146
160
  =======
147
161
 
148
162
  Tested and working on:
149
163
 
150
164
  - **Rails** 3.0.0, sitemap_generator version >= 0.2.5
151
- - **Rails** 1.x - 2.3.5 sitemap_generator version < 0.2.5
165
+ - **Rails** 1.x - 2.3.5
152
166
  - **Ruby** 1.8.7, 1.9.1
153
167
 
154
168
  Notes
@@ -182,21 +196,26 @@ Known Bugs
182
196
  - There's no check on the size of a URL which [isn't supposed to exceed 2,048 bytes][sitemaps_xml].
183
197
  - Currently only supports one Sitemap Index file, which can contain 50,000 Sitemap files which can each contain 50,000 urls, so it _only_ supports up to 2,500,000,000 (2.5 billion) urls. I personally have no need of support for more urls, but plugin could be improved to support this.
184
198
 
185
- Wishlist
199
+ Wishlist & Coming Soon
186
200
  ========
187
201
 
202
+ - Support for generating sitemaps for sites with multiple domains. Sitemaps are generated into subdirectories and we use a Rack middleware to rewrite requests for sitemaps to the correct subdirectory based on the request host.
203
+ - I want to refactor the code because it has grown a lot. Part of this refactoring will include implementing some more checks to make sure we adhere to standards as well as making sure that the sitemaps are being generated as efficiently as possible.
204
+
205
+ I'd like to simplify adding links to a sitemap. Right now it's all or nothing. I'd like to break it up so you can add batches.
188
206
  - Auto coverage testing. Generate a report of broken URLs by checking the status codes of each page in the sitemap.
189
207
 
190
208
  Thanks (in no particular order)
191
209
  ========
192
210
 
211
+ - [Alexadre Bini](http://github.com/alexandrebini) for image sitemaps
193
212
  - [Dan Pickett](http://github.com/dpickett)
194
213
  - [Rob Biedenharn](http://github.com/rab)
195
214
  - [Richie Vos](http://github.com/jerryvos)
196
215
  - [Adrian Mugnolo](http://github.com/xymbol)
197
216
 
198
217
 
199
- Copyright (c) 2009 Adam @ [Codebright.net][cb], released under the MIT license
218
+ Copyright (c) 2009 Karl Varga released under the MIT license
200
219
 
201
220
  [canonical_repo]:http://github.com/kjvarga/sitemap_generator
202
221
  [enterprise_class]:https://twitter.com/dhh/status/1631034662 "I use enterprise in the same sense the Phusion guys do - i.e. Enterprise Ruby. Please don't look down on my use of the word 'enterprise' to represent being a cut above. It doesn't mean you ever have to work for a company the size of IBM. Or constantly fight inertia, writing crappy software, adhering to change management practices and spending hours in meetings... Not that there's anything wrong with that - Wait, what?"
@@ -206,3 +225,5 @@ Copyright (c) 2009 Adam @ [Codebright.net][cb], released under the MIT license
206
225
  [sitemap_generator_usage]:http://wiki.github.com/adamsalter/sitemap_generator/sitemapgenerator-usage "http://wiki.github.com/adamsalter/sitemap_generator/sitemapgenerator-usage"
207
226
  [boost_juice]:http://www.boostjuice.com.au/ "Mmmm, sweet, sweet Boost Juice."
208
227
  [cb]:http://codebright.net "http://codebright.net"
228
+ [sitemap_images]:http://www.google.com/support/webmasters/bin/answer.py?answer=178636
229
+ [sitemap_protocol]:http://sitemaps.org/protocol.php
data/Rakefile CHANGED
@@ -8,8 +8,8 @@ begin
8
8
  require 'jeweler'
9
9
  Jeweler::Tasks.new do |gem|
10
10
  gem.name = "sitemap_generator"
11
- gem.summary = %Q{Easily generate enterprise class Sitemaps for your Rails site using a simple 'Rails Routes'-like DSL and a single Rake task}
12
- gem.description = %Q{A Rails 3-compatible gem to easily generate enterprise class Sitemaps readable by all search engines. Automatically ping search engines to notify them of new sitemaps, including Google, Yahoo and Bing. Provides rake tasks to easily manage your sitemaps. Won't clobber your old sitemaps if the new one fails to generate. Setup a cron schedule and never worry about your sitemaps again.}
11
+ gem.summary = %Q{Easily generate enterprise class Sitemaps for your Rails site using a familiar Rails Routes-like DSL}
12
+ gem.description = %Q{A Rails 3-compatible gem/plugin to generate enterprise-class Sitemaps using a familiar Rails Routes-like DSL. Sitemaps are readable by all search engines and adhere to the Sitemap protocol specification. Automatically pings search engines to notify them of new sitemaps (including Google, Yahoo and Bing). Provides rake tasks to easily manage your sitemaps. Supports image sitemaps and handles millions of links.}
13
13
  gem.email = "kjvarga@gmail.com"
14
14
  gem.homepage = "http://github.com/kjvarga/sitemap_generator"
15
15
  gem.authors = ["Adam Salter", "Karl Varga"]
@@ -28,19 +28,19 @@ namespace :test do
28
28
  task :gem => ['test:prepare:gem', 'multi_spec']
29
29
  task :plugin => ['test:prepare:plugin', 'multi_spec']
30
30
  task :rails3 => ['test:prepare:rails3', 'multi_spec']
31
-
31
+
32
32
  task :multi_spec do
33
33
  Rake::Task['spec'].invoke
34
34
  Rake::Task['spec'].reenable
35
35
  end
36
-
36
+
37
37
  namespace :prepare do
38
38
  task :gem do
39
39
  ENV["SITEMAP_RAILS"] = 'gem'
40
40
  prepare_path(local_path('spec/mock_app_gem/vendor/gems/sitemap_generator-1.2.3'))
41
41
  rm_rf(local_path('spec/mock_app_gem/public/sitemap*'))
42
42
  end
43
-
43
+
44
44
  task :plugin do
45
45
  ENV["SITEMAP_RAILS"] = 'plugin'
46
46
  prepare_path(local_path('spec/mock_app_plugin/vendor/plugins/sitemap_generator-1.2.3'))
@@ -51,11 +51,11 @@ namespace :test do
51
51
  ENV["SITEMAP_RAILS"] = 'rails3'
52
52
  rm_rf(local_path('spec/mock_rails3_gem/public/sitemap*'))
53
53
  end
54
-
54
+
55
55
  def local_path(path)
56
56
  File.join(File.dirname(__FILE__), path)
57
57
  end
58
-
58
+
59
59
  def prepare_path(path)
60
60
  rm_rf path
61
61
  mkdir_p path
@@ -64,8 +64,8 @@ namespace :test do
64
64
  end
65
65
  end
66
66
 
67
- desc "Run all tests both as a plugin and gem"
68
- task :test => ['test:plugin', 'test:gem']
67
+ desc "Run tests as a gem install"
68
+ task :test => ['test:gem']
69
69
 
70
70
  Spec::Rake::SpecTask.new(:spec) do |spec|
71
71
  spec.libs << 'lib' << 'spec'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
@@ -3,6 +3,9 @@ require 'sitemap_generator/link'
3
3
  require 'sitemap_generator/rails_helper'
4
4
  require 'sitemap_generator/helper'
5
5
  require 'sitemap_generator/link_set'
6
+ require 'sitemap_generator/helper'
7
+ require 'sitemap_generator/templates'
8
+ require 'sitemap_generator/utilities'
6
9
 
7
10
  require 'sitemap_generator/railtie' if SitemapGenerator::RailsHelper.rails3?
8
11
 
@@ -10,17 +13,14 @@ module SitemapGenerator
10
13
  silence_warnings do
11
14
  VERSION = File.read(File.dirname(__FILE__) + "/../VERSION").strip
12
15
  MAX_ENTRIES = 50_000
16
+ MAX_IMAGES = 1_000
13
17
  Sitemap = LinkSet.new
14
18
  end
15
-
19
+
16
20
  class << self
17
21
  attr_accessor :root, :templates
18
22
  end
19
23
 
20
24
  self.root = File.expand_path(File.join(File.dirname(__FILE__), '../'))
21
- self.templates = {
22
- :sitemap_index => File.join(self.root, 'templates/sitemap_index.builder'),
23
- :sitemap_xml => File.join(self.root, 'templates/xml_sitemap.builder'),
24
- :sitemap_sample => File.join(self.root, 'templates/sitemap.rb'),
25
- }
25
+ self.templates = SitemapGenerator::Templates.new(self.root)
26
26
  end
@@ -1,19 +1,31 @@
1
-
2
1
  module SitemapGenerator
3
2
  class Link
4
3
  class << self
5
4
  def generate(path, options = {})
6
- options.assert_valid_keys(:priority, :changefreq, :lastmod, :host)
7
- options.reverse_merge!(:priority => 0.5, :changefreq => 'weekly', :lastmod => Time.now, :host => Sitemap.default_host)
5
+ options.assert_valid_keys(:priority, :changefreq, :lastmod, :host, :images)
6
+ options.reverse_merge!(:priority => 0.5, :changefreq => 'weekly', :lastmod => Time.now, :host => Sitemap.default_host, :images => [])
8
7
  {
9
8
  :path => path,
10
9
  :priority => options[:priority],
11
10
  :changefreq => options[:changefreq],
12
11
  :lastmod => options[:lastmod],
13
12
  :host => options[:host],
14
- :loc => URI.join(options[:host], path).to_s
13
+ :loc => URI.join(options[:host], path).to_s,
14
+ :images => prepare_images(options[:images], options[:host])
15
15
  }
16
16
  end
17
+
18
+ # Maximum 1000 images. <tt>loc</tt> is required.
19
+ # ?? Does the image URL have to be on the same host?
20
+ def prepare_images(images, host)
21
+ images.delete_if { |key,value| key[:loc] == nil }
22
+ images.each do |r|
23
+ r.assert_valid_keys(:loc, :caption, :geo_location, :title, :license)
24
+ r[:loc] = URI.join(host, r[:loc]).to_s
25
+ end
26
+ images[0..(SitemapGenerator::MAX_IMAGES-1)]
27
+ end
17
28
  end
18
29
  end
19
30
  end
31
+
@@ -60,13 +60,19 @@ module SitemapGenerator
60
60
 
61
61
  # Write links to sitemap file.
62
62
  def write_sitemap(file = upcoming_file)
63
+ slice_index = 0
63
64
  buffer = ""
64
65
  xml = Builder::XmlMarkup.new(:target => buffer)
65
- eval(File.read(SitemapGenerator.templates[:sitemap_xml]), binding)
66
+ eval(SitemapGenerator.templates.sitemap_xml, binding)
66
67
  filename = File.join(Rails.root, "public", file)
67
68
  write_file(filename, buffer)
68
69
  show_progress("Sitemap", filename, buffer) if verbose
69
- links.clear
70
+ if slice_index==0
71
+ links.clear
72
+ else
73
+ links.slice! slice_index, links.size
74
+ end
75
+
70
76
  sitemaps.push filename
71
77
  end
72
78
 
@@ -74,7 +80,7 @@ module SitemapGenerator
74
80
  def write_index
75
81
  buffer = ""
76
82
  xml = Builder::XmlMarkup.new(:target => buffer)
77
- eval(File.read(SitemapGenerator.templates[:sitemap_index]), binding)
83
+ eval(SitemapGenerator.templates.sitemap_index, binding)
78
84
  filename = File.join(Rails.root, "public", index_file)
79
85
  write_file(filename, buffer)
80
86
  show_progress("Sitemap Index", filename, buffer) if verbose
@@ -143,28 +149,6 @@ module SitemapGenerator
143
149
  puts "** #{title} too big! The uncompressed size exceeds 10Mb" if buffer.size > 10.megabytes
144
150
  end
145
151
 
146
- # Copy templates/sitemap.rb to config if not there yet.
147
- def install_sitemap_rb
148
- if File.exist?(File.join(Rails.root, 'config/sitemap.rb'))
149
- puts "already exists: config/sitemap.rb, file not copied"
150
- else
151
- FileUtils.cp(SitemapGenerator.templates[:sitemap_sample], File.join(Rails.root, 'config/sitemap.rb'))
152
- puts "created: config/sitemap.rb"
153
- end
154
- end
155
-
156
- # Remove config/sitemap.rb if exists.
157
- def uninstall_sitemap_rb
158
- if File.exist?(File.join(Rails.root, 'config/sitemap.rb'))
159
- File.rm(File.join(Rails.root, 'config/sitemap.rb'))
160
- end
161
- end
162
-
163
- # Clean sitemap files in output directory.
164
- def clean_files
165
- FileUtils.rm(Dir[File.join(Rails.root, 'public/sitemap*.xml.gz')])
166
- end
167
-
168
152
  # Ping search engines passing sitemap location.
169
153
  def ping_search_engines
170
154
  super index_file
@@ -3,13 +3,14 @@ module SitemapGenerator
3
3
  # The object passed to the add_links block in config/sitemap.rb is a Generator instance.
4
4
  class Mapper
5
5
  attr_accessor :set
6
-
6
+
7
7
  def initialize(set)
8
8
  @set = set
9
9
  end
10
-
10
+
11
11
  def add(loc, options = {})
12
12
  set.add_link Link.generate(loc, options)
13
13
  end
14
14
  end
15
- end
15
+ end
16
+
@@ -0,0 +1,43 @@
1
+ module SitemapGenerator
2
+ # Provide convenient access to template files. E.g.
3
+ #
4
+ # SitemapGenerator.templates.sitemap_index
5
+ #
6
+ # Lazy-load and cache for efficient access.
7
+ # Define an accessor method for each template file.
8
+ class Templates
9
+ FILES = {
10
+ :sitemap_index => 'sitemap_index.builder',
11
+ :sitemap_xml => 'xml_sitemap.builder',
12
+ :sitemap_sample => 'sitemap.rb',
13
+ }
14
+
15
+ # Dynamically define accessors for each key defined in <tt>FILES</tt>
16
+ attr_accessor *FILES.keys
17
+ FILES.keys.each do |name|
18
+ eval <<-END
19
+ define_method(:#{name}) do
20
+ @#{name} ||= read_template(:#{name})
21
+ end
22
+ END
23
+ end
24
+
25
+ def initialize(root = SitemapGenerator.root)
26
+ @root = root
27
+ end
28
+
29
+ # Return the full path to a template.
30
+ #
31
+ # <tt>file</tt> template symbol e.g. <tt>:sitemap_index</tt>
32
+ def template_path(template)
33
+ File.join(@root, 'templates', self.class::FILES[template])
34
+ end
35
+
36
+ protected
37
+
38
+ # Read the template file and return its contents.
39
+ def read_template(template)
40
+ File.read(template_path(template))
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,29 @@
1
+ module SitemapGenerator
2
+ module Utilities
3
+ extend self
4
+
5
+ # Copy templates/sitemap.rb to config if not there yet.
6
+ def install_sitemap_rb
7
+ if File.exist?(File.join(RAILS_ROOT, 'config/sitemap.rb'))
8
+ puts "already exists: config/sitemap.rb, file not copied"
9
+ else
10
+ FileUtils.cp(
11
+ SitemapGenerator.templates.template_path(:sitemap_sample),
12
+ File.join(RAILS_ROOT, 'config/sitemap.rb'))
13
+ puts "created: config/sitemap.rb"
14
+ end
15
+ end
16
+
17
+ # Remove config/sitemap.rb if exists.
18
+ def uninstall_sitemap_rb
19
+ if File.exist?(File.join(RAILS_ROOT, 'config/sitemap.rb'))
20
+ File.rm(File.join(RAILS_ROOT, 'config/sitemap.rb'))
21
+ end
22
+ end
23
+
24
+ # Clean sitemap files in output directory.
25
+ def clean_files
26
+ FileUtils.rm(Dir[File.join(RAILS_ROOT, 'public/sitemap*.xml.gz')])
27
+ end
28
+ end
29
+ end
data/rails/install.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  # Install hook code here
2
- SitemapGenerator::Sitemap.install_sitemap_rb
2
+ SitemapGenerator::Utilities.install_sitemap_rb
data/rails/uninstall.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  # Uninstall hook code here
2
- SitemapGenerator::Sitemap.uninstall_sitemap_rb
2
+ SitemapGenerator::Utilities.uninstall_sitemap_rb
@@ -1,15 +1,19 @@
1
1
  require 'zlib'
2
- require 'sitemap_generator'
2
+ begin
3
+ require 'sitemap_generator'
4
+ rescue LoadError, NameError
5
+ # Application should work without vlad
6
+ end
3
7
 
4
8
  namespace :sitemap do
5
9
  desc "Install a default config/sitemap.rb file"
6
10
  task :install do
7
- SitemapGenerator::Sitemap.install_sitemap_rb
11
+ SitemapGenerator::Utilities.install_sitemap_rb
8
12
  end
9
13
 
10
14
  desc "Delete all Sitemap files in public/ directory"
11
15
  task :clean do
12
- SitemapGenerator::Sitemap.clean_files
16
+ SitemapGenerator::Utilities.clean_files
13
17
  end
14
18
 
15
19
  desc "Create Sitemap XML files in public/ directory (rake -s for no output)"
@@ -32,7 +36,8 @@ namespace :sitemap do
32
36
  SitemapGenerator::Sitemap.class_eval do
33
37
  include ActionController::UrlWriter
34
38
  end
35
- end
39
+ end
36
40
  SitemapGenerator::Sitemap.create_files
37
41
  end
38
42
  end
43
+
data/templates/sitemap.rb CHANGED
@@ -10,12 +10,12 @@ SitemapGenerator::Sitemap.add_links do |sitemap|
10
10
  # Usage: sitemap.add path, options
11
11
  # (default options are used if you don't specify)
12
12
  #
13
- # Defaults: :priority => 0.5, :changefreq => 'weekly',
13
+ # Defaults: :priority => 0.5, :changefreq => 'weekly',
14
14
  # :lastmod => Time.now, :host => default_host
15
15
 
16
-
16
+
17
17
  # Examples:
18
-
18
+
19
19
  # add '/articles'
20
20
  sitemap.add articles_path, :priority => 0.7, :changefreq => 'daily'
21
21
 
@@ -26,17 +26,17 @@ SitemapGenerator::Sitemap.add_links do |sitemap|
26
26
 
27
27
  # add merchant path
28
28
  sitemap.add '/purchase', :priority => 0.7, :host => "https://www.example.com"
29
-
29
+
30
30
  end
31
31
 
32
32
  # Including Sitemaps from Rails Engines.
33
33
  #
34
- # These Sitemaps should be almost identical to a regular Sitemap file except
34
+ # These Sitemaps should be almost identical to a regular Sitemap file except
35
35
  # they needn't define their own SitemapGenerator::Sitemap.default_host since
36
36
  # they will undoubtedly share the host name of the application they belong to.
37
37
  #
38
38
  # As an example, say we have a Rails Engine in vendor/plugins/cadability_client
39
39
  # We can include its Sitemap here as follows:
40
- #
40
+ #
41
41
  # file = File.join(Rails.root, 'vendor/plugins/cadability_client/config/sitemap.rb')
42
42
  # eval(open(file).read, binding, file)
@@ -1,4 +1,4 @@
1
-
1
+ # encoding: utf-8
2
2
  # <?xml version="1.0" encoding="UTF-8"?>
3
3
  # <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
4
4
  # <sitemap>
@@ -19,4 +19,5 @@ xml.sitemapindex "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do
19
19
  xml.lastmod w3c_date(File.mtime(file))
20
20
  end
21
21
  end
22
- end
22
+ end
23
+
@@ -1,15 +1,38 @@
1
+ # encoding: utf-8
1
2
  xml.instruct!
2
- xml.urlset "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
3
- "xsi:schemaLocation" => "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd",
3
+ xml.urlset "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
4
+ "xsi:schemaLocation" => "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd",
5
+ "xmlns:image" => "http://www.google.com/schemas/sitemap-image/1.1",
4
6
  "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do
5
7
 
6
- links.each do |link|
7
- xml.url do
8
- xml.loc link[:loc]
9
- xml.lastmod w3c_date(link[:lastmod]) if link[:lastmod]
10
- xml.changefreq link[:changefreq] if link[:changefreq]
11
- xml.priority link[:priority] if link[:priority]
12
- end
13
- end
8
+ links.each_with_index do |link,index|
9
+ buffer_url = ""
10
+ url = Builder::XmlMarkup.new(:target=>buffer_url)
11
+ url.url do
12
+ url.loc link[:loc]
13
+ url.lastmod w3c_date(link[:lastmod]) if link[:lastmod]
14
+ url.changefreq link[:changefreq] if link[:changefreq]
15
+ url.priority link[:priority] if link[:priority]
14
16
 
17
+ unless link[:images].blank?
18
+ link[:images].each do |image|
19
+ url.image:image do
20
+ url.image :loc, image[:loc]
21
+ url.image :caption, image[:caption] if image[:caption]
22
+ url.image :geo_location, image[:geo_location] if image[:geo_location]
23
+ url.image :title, image[:title] if image[:title]
24
+ url.image :license, image[:license] if image[:license]
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ if (buffer+buffer_url).size < 10.megabytes
31
+ xml << buffer_url
32
+ else
33
+ slice_index = index
34
+ break
35
+ end
36
+ end
15
37
  end
38
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 5
9
- version: 0.2.5
8
+ - 6
9
+ version: 0.2.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Adam Salter
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-19 00:00:00 -07:00
18
+ date: 2010-05-17 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: "0"
31
31
  type: :development
32
32
  version_requirements: *id001
33
- description: A Rails 3-compatible gem to easily generate enterprise class Sitemaps readable by all search engines. Automatically ping search engines to notify them of new sitemaps, including Google, Yahoo and Bing. Provides rake tasks to easily manage your sitemaps. Won't clobber your old sitemaps if the new one fails to generate. Setup a cron schedule and never worry about your sitemaps again.
33
+ description: A Rails 3-compatible gem/plugin to generate enterprise-class Sitemaps using a familiar Rails Routes-like DSL. Sitemaps are readable by all search engines and adhere to the Sitemap protocol specification. Automatically pings search engines to notify them of new sitemaps (including Google, Yahoo and Bing). Provides rake tasks to easily manage your sitemaps. Supports image sitemaps and handles millions of links.
34
34
  email: kjvarga@gmail.com
35
35
  executables: []
36
36
 
@@ -51,6 +51,8 @@ files:
51
51
  - lib/sitemap_generator/rails_helper.rb
52
52
  - lib/sitemap_generator/railtie.rb
53
53
  - lib/sitemap_generator/tasks.rb
54
+ - lib/sitemap_generator/templates.rb
55
+ - lib/sitemap_generator/utilities.rb
54
56
  - rails/install.rb
55
57
  - rails/uninstall.rb
56
58
  - tasks/sitemap_generator_tasks.rake
@@ -86,6 +88,6 @@ rubyforge_project:
86
88
  rubygems_version: 1.3.6
87
89
  signing_key:
88
90
  specification_version: 3
89
- summary: Easily generate enterprise class Sitemaps for your Rails site using a simple 'Rails Routes'-like DSL and a single Rake task
91
+ summary: Easily generate enterprise class Sitemaps for your Rails site using a familiar Rails Routes-like DSL
90
92
  test_files: []
91
93