sitemap_generator 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,6 +18,7 @@ Features
18
18
  Changelog
19
19
  -------
20
20
 
21
+ - v1.3.0: Support setting the sitemaps path
21
22
  - v1.2.0: Verified working with Rails 3 stable release
22
23
  - v1.1.0: [Video sitemap][sitemap_video] support
23
24
  - v0.2.6: [Image Sitemap][sitemap_images] support
@@ -35,44 +36,44 @@ The canonical repository is now: [http://github.com/kjvarga/sitemap_generator][c
35
36
  Install
36
37
  =======
37
38
 
38
- **Rails 3.x:**
39
+ **Rails 3:**
39
40
 
40
- 1. Add the gem to your <tt>Gemspec</tt>
41
+ 1. Add the gem to your `Gemfile`
41
42
 
42
- <code>gem 'sitemap_generator'</code>
43
+ gem 'sitemap_generator'
43
44
 
44
45
  2. `$ rake sitemap:install`
45
46
 
46
47
  You don't need to include the tasks in your `Rakefile` because the tasks are loaded for you.
47
48
 
48
- **Rails 2.x: As a gem**
49
+ **Pre Rails 3: As a gem**
49
50
 
50
51
  1. Add the gem as a dependency in your <tt>config/environment.rb</tt>
51
52
 
52
- <code>config.gem 'sitemap_generator', :lib => false</code>
53
+ config.gem 'sitemap_generator', :lib => false
53
54
 
54
55
  2. `$ rake gems:install`
55
56
 
56
- 3. Add the following to your <tt>RAILS_ROOT/Rakefile</tt>
57
+ 3. Add the following to your `Rakefile`
57
58
 
58
- <pre>begin
59
- require 'sitemap_generator/tasks'
60
- rescue Exception => e
61
- puts "Warning, couldn't load gem tasks: #{e.message}! Skipping..."
62
- end</pre>
59
+ begin
60
+ require 'sitemap_generator/tasks'
61
+ rescue Exception => e
62
+ puts "Warning, couldn't load gem tasks: #{e.message}! Skipping..."
63
+ end
63
64
 
64
65
  4. `$ rake sitemap:install`
65
66
 
66
- **Rails 2.x: As a plugin**
67
+ **Pre Rails 3: As a plugin**
67
68
 
68
- 1. <code>$ ./script/plugin install git://github.com/kjvarga/sitemap_generator.git</code>
69
+ 1. `$ ./script/plugin install git://github.com/kjvarga/sitemap_generator.git`
69
70
 
70
71
  Usage
71
72
  ======
72
73
 
73
- <code>rake sitemap:install</code> creates a <tt>config/sitemap.rb</tt> file which will contain your logic for generating the Sitemap files.
74
+ <code>rake sitemap:install</code> creates a <tt>config/sitemap.rb</tt> file which contains your logic for generating the Sitemap files.
74
75
 
75
- Once you have configured your sitemap in <tt>config/sitemap.rb</tt> run <code>rake sitemap:refresh</code> as needed to create/rebuild your Sitemap files. Sitemaps are generated into the <tt>public/</tt> folder and are named <tt>sitemap_index.xml.gz</tt>, <tt>sitemap1.xml.gz</tt>, <tt>sitemap2.xml.gz</tt>, etc.
76
+ Once you have configured your sitemap in <tt>config/sitemap.rb</tt> (see Configuration below) run <code>rake sitemap:refresh</code> as needed to create/rebuild your Sitemap files. Sitemaps are generated into the <tt>public/</tt> folder and are named <tt>sitemap_index.xml.gz</tt>, <tt>sitemap1.xml.gz</tt>, <tt>sitemap2.xml.gz</tt>, etc.
76
77
 
77
78
  Using <code>rake sitemap:refresh</code> will notify major search engines to let them know that a new Sitemap is available (Google, Yahoo, Bing, Ask, SitemapWriter). To generate new Sitemaps without notifying search engines (for example when running in a local environment) use <code>rake sitemap:refresh:no_ping</code>.
78
79
 
@@ -99,21 +100,100 @@ You should add the Sitemap index file to <code>public/robots.txt</code> to help
99
100
 
100
101
  Sitemap: http://www.example.org/sitemap_index.xml.gz
101
102
 
102
- Image and Video Sitemaps
103
+ Image Sitemaps
103
104
  -----------
104
105
 
105
106
  Images can be added to a sitemap URL by passing an <tt>:images</tt> array to <tt>add()</tt>. Each item in the array must be a Hash containing tags defined by the [Image Sitemap][image_tags] specification. For example:
106
107
 
107
108
  sitemap.add('/index.html', :images => [{ :loc => 'http://www.example.com/image.png', :title => 'Image' }])
108
109
 
110
+ Supported image options include:
111
+
112
+ * `loc` Required, location of the image
113
+ * `caption`
114
+ * `geo_location`
115
+ * `title`
116
+ * `license`
117
+
118
+ Video Sitemaps
119
+ -----------
120
+
109
121
  A video can be added to a sitemap URL by passing a <tt>:video</tt> Hash to <tt>add()</tt>. The Hash can contain tags defined by the [Video Sitemap specification][video_tags]. To associate more than one <tt>tag</tt> with a video, pass the tags as an array with the key <tt>:tags</tt>.
110
122
 
111
123
  sitemap.add('/index.html', :video => { :thumbnail_loc => 'http://www.example.com/video1_thumbnail.png', :title => 'Title', :description => 'Description', :content_loc => 'http://www.example.com/cool_video.mpg', :tags => %w[one two three], :category => 'Category' })
112
124
 
113
- Example <code>config/sitemap.rb</code>
125
+ Supported video options include:
126
+
127
+ * `thumbnail_loc` Required
128
+ * `title` Required
129
+ * `description` Required
130
+ * `content_loc` Depends. At least one of `player_loc` or `content_loc` is required
131
+ * `player_loc` Depends. At least one of `player_loc` or `content_loc` is required
132
+ * `expiration_date` Recommended
133
+ * `duration` Recommended
134
+ * `rating`
135
+ * `view_count`
136
+ * `publication_date`
137
+ * `family_friendly`
138
+ * `tags` A list of tags if more than one tag.
139
+ * `tag` A single tag. See `tags`
140
+ * `category`
141
+ * `gallery_loc`
142
+
143
+ Configuration
144
+ ======
145
+
146
+ The sitemap configuration file can be found in <tt>config/sitemap.rb</tt>. When you run a rake task to refresh your sitemaps this file is evaluated. It contains all your configuration settings, as well as your sitemap definition.
147
+
148
+ Sitemap Links
149
+ ----------
150
+
151
+ The Root Path <tt>/</tt> and Sitemap Index file are automatically added to your sitemap. Links are added to the Sitemap output in the order they are specified. Add links to your sitemap by calling <tt>add_links</tt>, passing a black which receives the sitemap object. Then call <tt>add(path, options)</tt> on the sitemap to add a link.
152
+
153
+ For Example:
154
+
155
+ SitemapGenerator::Sitemap.add_links do |sitemap|
156
+ sitemap.add '/reports'
157
+ end
158
+
159
+ The Rails URL helpers are automatically included for you if Rails is detected. So in your call to <tt>add</tt> you can use them to generate paths for your active records, e.g.:
160
+
161
+ Article.find_each do |article|
162
+ sitemap.add article_path(article), :lastmod => article.updated_at
163
+ end
164
+
165
+ For large sitemaps it is advisable to iterate through your Active Records in batches to avoid loading all records into memory at once. As of Rails 2.3.2 you can use <tt>ActiveRecord::Base#find_each</tt> or <tt>ActiveRecord::Base#find_in_batches</tt> to do batched finds, which can significantly improve sitemap performance.
166
+
167
+ Valid [options to <tt>add</tt>](http://sitemaps.org/protocol.php#xmlTagDefinitions) are:
168
+
169
+ * `priority` The priority of this URL relative to other URLs on your site. Valid values range from 0.0 to 1.0. Default _0.5_
170
+ * `changefreq` One of: always, hourly, daily, weekly, monthly, yearly, never. Default _weekly_
171
+ * `lastmod` Time instance. The date of last modification. Default `Time.now`
172
+ * `host` Optional host for the link's URL. Defaults to `default_host`
173
+
174
+ Sitemaps Path
175
+ ----------
176
+
177
+ By default sitemaps are generated into <tt>public/</tt>. You can customize the location for your generated sitemaps by setting <tt>sitemaps_path</tt> to a path relative to your public directory. The directory will be created for you if it does not already exist.
178
+
179
+ For example:
180
+
181
+ SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps/'
182
+
183
+ Will generate sitemaps into the `public/sitemaps/` directory. If you want your sitemaps to be findable by robots, you need to specify the location of your sitemap index file in your <tt>public/robots.txt</tt>.
184
+
185
+ Sitemaps Host
186
+ ----------
187
+
188
+ You must set the <tt>default_host</tt> that is to be used when adding links to your sitemap. The hostname should match the host that the sitemaps are going to be served from. For example:
189
+
190
+ SitemapGenerator::Sitemap.default_host = "http://www.example.com"
191
+
192
+ The hostname must include the full protocol.
193
+
194
+ Example Configuration File
114
195
  ---------
115
196
 
116
- # Set the host name for URL creation
117
197
  SitemapGenerator::Sitemap.default_host = "http://www.example.com"
118
198
  SitemapGenerator::Sitemap.yahoo_app_id = nil # Set to your Yahoo AppID to ping Yahoo
119
199
 
@@ -146,18 +226,6 @@ Example <code>config/sitemap.rb</code>
146
226
  end
147
227
  end
148
228
 
149
- # Including Sitemaps from Rails Engines.
150
- #
151
- # These Sitemaps should be almost identical to a regular Sitemap file except
152
- # they needn't define their own SitemapGenerator::Sitemap.default_host since
153
- # they will undoubtedly share the host name of the application they belong to.
154
- #
155
- # As an example, say we have a Rails Engine in vendor/plugins/cadability_client
156
- # We can include its Sitemap here as follows:
157
- #
158
- file = File.join(Rails.root, 'vendor/plugins/cadability_client/config/sitemap.rb')
159
- eval(open(file).read, binding, file)
160
-
161
229
  Raison d'être
162
230
  -------
163
231
 
@@ -197,16 +265,7 @@ Tested and working on:
197
265
  Notes
198
266
  =======
199
267
 
200
- 1) For large sitemaps it may be useful to split your generation into batches to avoid running out of memory. E.g.:
201
-
202
- # add movies
203
- Movie.find_in_batches(:batch_size => 1000) do |movies|
204
- movies.each do |movie|
205
- sitemap.add "/movies/show/#{movie.to_param}", :lastmod => movie.updated_at, :changefreq => 'weekly'
206
- end
207
- end
208
-
209
- 2) New Capistrano deploys will remove your Sitemap files, unless you run `rake sitemap:refresh`. The way around this is to create a cap task:
268
+ 1) New Capistrano deploys will remove your Sitemap files, unless you run `rake sitemap:refresh`. The way around this is to create a cap task to copy the sitemaps from the previous deploy:
210
269
 
211
270
  after "deploy:update_code", "deploy:copy_old_sitemap"
212
271
 
@@ -225,11 +284,8 @@ Known Bugs
225
284
  Wishlist & Coming Soon
226
285
  ========
227
286
 
228
- - Ultimately I'd like to make this gem framework agnostic. It is better suited to being run as a command-line tool as opposed to Ruby-specific Rake tasks.
229
- - Add rake tasks/options to validate the generated sitemaps.
230
- - Support News, Mobile, Geo and other types of sitemaps
231
- - Support for generating sitemaps for sites with multiple domains. Sitemaps can be generated into subdirectories and we can use Rack middleware to rewrite requests for sitemaps to the correct subdirectory based on the request host.
232
- - Auto coverage testing. Generate a report of broken URLs by checking the status codes of each page in the sitemap.
287
+ - Support for read-only filesystems
288
+ - Support for plain Ruby and Merb sitemaps
233
289
 
234
290
  Thanks (in no particular order)
235
291
  ========
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.4
1
+ 1.3.5
@@ -64,7 +64,6 @@ module SitemapGenerator
64
64
  builder.video :view_count, video[:view_count] if video[:view_count]
65
65
  builder.video :publication_date, video[:publication_date] if video[:publication_date]
66
66
  builder.video :expiration_date, video[:expiration_date] if video[:expiration_date]
67
- builder.video :duration, video[:duration] if video[:duration]
68
67
  builder.video :family_friendly, (video[:family_friendly] ? 'yes' : 'no') if video[:family_friendly]
69
68
  builder.video :duration, video[:duration] if video[:duration]
70
69
  video[:tags].each {|tag| builder.video :tag, tag } if video[:tags]
@@ -1,3 +1,5 @@
1
+ require 'sitemap_generator'
2
+
1
3
  module SitemapGenerator
2
4
 
3
5
  # Evaluate a sitemap config file within the context of a class that includes the
@@ -1,26 +1,18 @@
1
- environment = begin
2
-
3
- # Try to require the library. If we are installed as a gem, this should work.
4
- # We don't need to load the environment.
5
- require 'sitemap_generator'
6
- []
7
-
8
- rescue LoadError
9
-
10
- # We must be installed as a plugin. Make sure the environment is loaded
11
- # when running all rake tasks.
12
- [:environment]
13
-
14
- end
15
-
16
1
  namespace :sitemap do
2
+ # Require sitemap_generator at runtime. If we don't do this the ActionView helpers are included
3
+ # before the Rails environment can be loaded by other Rake tasks, which causes problems
4
+ # for those tasks when rendering using ActionView.
5
+ task :require do
6
+ require 'sitemap_generator'
7
+ end
8
+
17
9
  desc "Install a default config/sitemap.rb file"
18
- task :install => environment do
10
+ task :install => ['sitemap:require'] do
19
11
  SitemapGenerator::Utilities.install_sitemap_rb(verbose)
20
12
  end
21
13
 
22
14
  desc "Delete all Sitemap files in public/ directory"
23
- task :clean => environment do
15
+ task :clean => ['sitemap:require'] do
24
16
  SitemapGenerator::Utilities.clean_files
25
17
  end
26
18
 
@@ -32,7 +24,9 @@ namespace :sitemap do
32
24
  desc "Create Sitemap XML files (don't ping search engines)"
33
25
  task 'refresh:no_ping' => ['sitemap:create']
34
26
 
35
- task :create => [:environment] do
27
+ # Require sitemap_generator to handle the case that we are installed as a gem and are set to not
28
+ # automatically be required. If the library has already been required, this is harmless.
29
+ task :create => [:environment, 'sitemap:require'] do
36
30
  SitemapGenerator::Sitemap.verbose = verbose
37
31
  SitemapGenerator::Sitemap.create
38
32
  end
data/templates/sitemap.rb CHANGED
@@ -7,36 +7,22 @@ SitemapGenerator::Sitemap.add_links do |sitemap|
7
7
  # The root path '/' and sitemap index file are added automatically.
8
8
  # Links are added to the Sitemap in the order they are specified.
9
9
  #
10
- # Usage: sitemap.add path, options
10
+ # Usage: sitemap.add(path, options={})
11
11
  # (default options are used if you don't specify)
12
12
  #
13
13
  # Defaults: :priority => 0.5, :changefreq => 'weekly',
14
14
  # :lastmod => Time.now, :host => default_host
15
-
16
-
15
+ #
16
+ #
17
17
  # Examples:
18
-
19
- # add '/articles'
20
- sitemap.add articles_path, :priority => 0.7, :changefreq => 'daily'
21
-
22
- # add all individual articles
23
- Article.find(:all).each do |a|
24
- sitemap.add article_path(a), :lastmod => a.updated_at
25
- end
26
-
27
- # add merchant path
28
- sitemap.add '/purchase', :priority => 0.7, :host => "https://www.example.com"
29
-
30
- end
31
-
32
- # Including Sitemaps from Rails Engines.
33
- #
34
- # These Sitemaps should be almost identical to a regular Sitemap file except
35
- # they needn't define their own SitemapGenerator::Sitemap.default_host since
36
- # they will undoubtedly share the host name of the application they belong to.
37
- #
38
- # As an example, say we have a Rails Engine in vendor/plugins/cadability_client
39
- # We can include its Sitemap here as follows:
40
- #
41
- # file = File.join(Rails.root, 'vendor/plugins/cadability_client/config/sitemap.rb')
42
- # eval(open(file).read, binding, file)
18
+ #
19
+ # Add '/articles'
20
+ #
21
+ # sitemap.add articles_path, :priority => 0.7, :changefreq => 'daily'
22
+ #
23
+ # Add individual articles:
24
+ #
25
+ # Article.find_each do |article|
26
+ # sitemap.add article_path(article), :lastmod => article.updated_at
27
+ # end
28
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sitemap_generator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 4
10
- version: 1.3.4
9
+ - 5
10
+ version: 1.3.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Karl Varga
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-06 00:00:00 -08:00
19
+ date: 2010-12-07 00:00:00 -08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency