sitemap_generator 3.3 → 3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +44 -16
- data/VERSION +1 -1
- data/lib/sitemap_generator/adapters/s3_adapter.rb +15 -7
- data/lib/sitemap_generator/builder/sitemap_file.rb +1 -0
- data/lib/sitemap_generator/builder/sitemap_url.rb +12 -3
- data/spec/sitemap_generator/alternate_sitemap_spec.rb +28 -0
- data/spec/sitemap_generator/builder/sitemap_url_spec.rb +15 -0
- metadata +13 -11
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Sitemaps adhere to the [Sitemap 0.9 protocol][sitemap_protocol] specification.
|
|
7
7
|
## Features
|
8
8
|
|
9
9
|
* Framework agnostic
|
10
|
-
* Supports [News sitemaps][sitemap_news], [Video sitemaps][sitemap_video], [Image sitemaps][sitemap_images], [Geo sitemaps][sitemap_geo]
|
10
|
+
* Supports [News sitemaps][sitemap_news], [Video sitemaps][sitemap_video], [Image sitemaps][sitemap_images], [Geo sitemaps][sitemap_geo], [Mobile sitemaps][sitemap_mobile] and [Alternate Links][alternate_links]
|
11
11
|
* Supports read-only filesystems like Heroku via uploading to a remote host like Amazon S3
|
12
12
|
* Compatible with Rails 2 & 3
|
13
13
|
* Adheres to the [Sitemap 0.9 protocol][sitemap_protocol]
|
@@ -17,7 +17,6 @@ Sitemaps adhere to the [Sitemap 0.9 protocol][sitemap_protocol] specification.
|
|
17
17
|
* Ensures your old sitemaps stay in place if the new sitemap fails to generate
|
18
18
|
* Gives you complete control over your sitemaps and their content
|
19
19
|
|
20
|
-
|
21
20
|
### Show Me
|
22
21
|
|
23
22
|
Install:
|
@@ -69,6 +68,7 @@ Does your website use SitemapGenerator to generate Sitemaps? Where would you be
|
|
69
68
|
|
70
69
|
## Changelog
|
71
70
|
|
71
|
+
* v3.4: Support [alternate links][alternate_links] for urls; Support configurable options in the `SitemapGenerator::S3Adapter`
|
72
72
|
* v3.3: **Support creating sitemaps with no index file**. A big thank-you to [Eric Hochberger][ehoch] for generously paying for this feature.
|
73
73
|
* v3.2.1: Fix syntax error in SitemapGenerator::S3Adapter
|
74
74
|
* v3.2: **Support mobile tags**, **SitemapGenerator::S3Adapter** a simple S3 adapter which uses Fog and doesn't require CarrierWave; Remove Ask from the sitemap ping because the service has been shutdown; [Turn off `include_index`][include_index_change] by default; Fix the news XML namespace; Only include autoplay attribute if present
|
@@ -498,6 +498,8 @@ You can read more about `add` in the [XML Specification](http://sitemaps.org/pro
|
|
498
498
|
|
499
499
|
### Supported Options to `add`
|
500
500
|
|
501
|
+
For other options be sure to check out the **Sitemap Extensions** section below.
|
502
|
+
|
501
503
|
* `changefreq` - Default: `'weekly'` (String).
|
502
504
|
|
503
505
|
Indicates how often the content of the page changes. One of `'always'`, `'hourly'`, `'daily'`, `'weekly'`, `'monthly'`, `'yearly'` or `'never'`. Example:
|
@@ -744,14 +746,14 @@ end
|
|
744
746
|
|
745
747
|
#### Supported options
|
746
748
|
|
747
|
-
*
|
748
|
-
*
|
749
|
-
*
|
750
|
-
*
|
751
|
-
*
|
752
|
-
*
|
753
|
-
*
|
754
|
-
*
|
749
|
+
* `:publication_name`
|
750
|
+
* `:publication_language`
|
751
|
+
* `:publication_date`
|
752
|
+
* `:genres`
|
753
|
+
* `:access`
|
754
|
+
* `:title`
|
755
|
+
* `:keywords`
|
756
|
+
* `:stock_tickers`
|
755
757
|
|
756
758
|
|
757
759
|
### Image Sitemaps
|
@@ -770,11 +772,11 @@ end
|
|
770
772
|
|
771
773
|
#### Supported options
|
772
774
|
|
773
|
-
*
|
774
|
-
*
|
775
|
-
*
|
776
|
-
*
|
777
|
-
*
|
775
|
+
* `:loc` Required, location of the image
|
776
|
+
* `:caption`
|
777
|
+
* `:geo_location`
|
778
|
+
* `:title`
|
779
|
+
* `:license`
|
778
780
|
|
779
781
|
|
780
782
|
### Video Sitemaps
|
@@ -816,7 +818,32 @@ end
|
|
816
818
|
|
817
819
|
#### Supported options
|
818
820
|
|
819
|
-
*
|
821
|
+
* `:format` Required, either 'kml' or 'georss'
|
822
|
+
|
823
|
+
|
824
|
+
### Alternate Links
|
825
|
+
|
826
|
+
A useful feature for internationalization is to specify alternate links for a url.
|
827
|
+
|
828
|
+
Alternate links can be added by passing an `:alternate` Hash to `add`. You can pass more than one alternate link by passing an array of hashes using the `:alternates` option.
|
829
|
+
|
830
|
+
Check out the Google specification [here][alternate_links].
|
831
|
+
|
832
|
+
#### Example
|
833
|
+
|
834
|
+
```ruby
|
835
|
+
SitemapGenerator::Sitemap.create do
|
836
|
+
add('/index.html', :alternate => {
|
837
|
+
:href => 'http://www.example.de/index.html',
|
838
|
+
:lang => 'de'
|
839
|
+
})
|
840
|
+
end
|
841
|
+
```
|
842
|
+
|
843
|
+
#### Supported options
|
844
|
+
|
845
|
+
* `:href` - Required, string.
|
846
|
+
* `:lang` - Required, string.
|
820
847
|
|
821
848
|
|
822
849
|
## Raison d'être
|
@@ -901,3 +928,4 @@ Copyright (c) 2009 Karl Varga released under the MIT license
|
|
901
928
|
[remote_hosts]:https://github.com/kjvarga/sitemap_generator/wiki/Generate-Sitemaps-on-read-only-filesystems-like-Heroku
|
902
929
|
[include_index_change]:https://github.com/kjvarga/sitemap_generator/issues/70
|
903
930
|
[ehoch]:https://github.com/ehoch
|
931
|
+
[alternate_links]:http://support.google.com/webmasters/bin/answer.py?hl=en&answer=2620865
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.4
|
@@ -3,23 +3,31 @@ require 'fog'
|
|
3
3
|
module SitemapGenerator
|
4
4
|
class S3Adapter
|
5
5
|
|
6
|
+
def initialize(opts = {})
|
7
|
+
@aws_access_key_id = opts[:aws_access_key_id] || ENV['AWS_ACCESS_KEY_ID']
|
8
|
+
@aws_secret_access_key = opts[:aws_secret_access_key] || ENV['AWS_SECRET_ACCESS_KEY']
|
9
|
+
@fog_provider = opts[:fog_provider] || ENV['FOG_PROVIDER']
|
10
|
+
@fog_directory = opts[:fog_directory] || ENV['FOG_DIRECTORY']
|
11
|
+
end
|
12
|
+
|
6
13
|
# Call with a SitemapLocation and string data
|
7
14
|
def write(location, raw_data)
|
8
15
|
SitemapGenerator::FileAdapter.new.write(location, raw_data)
|
9
|
-
|
16
|
+
|
10
17
|
credentials = {
|
11
|
-
:aws_access_key_id =>
|
12
|
-
:aws_secret_access_key =>
|
13
|
-
:provider =>
|
18
|
+
:aws_access_key_id => @aws_access_key_id,
|
19
|
+
:aws_secret_access_key => @aws_secret_access_key,
|
20
|
+
:provider => @fog_provider,
|
14
21
|
}
|
15
|
-
|
22
|
+
|
16
23
|
storage = Fog::Storage.new(credentials)
|
17
|
-
directory = storage.directories.get(
|
24
|
+
directory = storage.directories.get(@fog_directory)
|
18
25
|
directory.files.create(
|
19
|
-
:key => location.path_in_public,
|
26
|
+
:key => location.path_in_public,
|
20
27
|
:body => File.open(location.path),
|
21
28
|
:public => true
|
22
29
|
)
|
23
30
|
end
|
31
|
+
|
24
32
|
end
|
25
33
|
end
|
@@ -36,6 +36,7 @@ module SitemapGenerator
|
|
36
36
|
xmlns:geo="http://www.google.com/geo/schemas/sitemap/1.0"
|
37
37
|
xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
|
38
38
|
xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0"
|
39
|
+
xmlns:xhtml="http://www.w3.org/1999/xhtml"
|
39
40
|
>
|
40
41
|
HTML
|
41
42
|
@xml_wrapper_start.gsub!(/\s+/, ' ').gsub!(/ *> */, '>').strip!
|
@@ -27,6 +27,7 @@ module SitemapGenerator
|
|
27
27
|
# * +geo+
|
28
28
|
# * +news+
|
29
29
|
# * +mobile+
|
30
|
+
# * +alternate+/+alternates+
|
30
31
|
def initialize(path, options={})
|
31
32
|
options = options.dup
|
32
33
|
if sitemap = path.is_a?(SitemapGenerator::Builder::SitemapFile) && path
|
@@ -34,12 +35,15 @@ module SitemapGenerator
|
|
34
35
|
path = sitemap.location.path_in_public
|
35
36
|
end
|
36
37
|
|
37
|
-
SitemapGenerator::Utilities.assert_valid_keys(options, :priority, :changefreq, :lastmod, :host, :images, :video, :geo, :news, :videos, :mobile)
|
38
|
-
SitemapGenerator::Utilities.reverse_merge!(options, :priority => 0.5, :changefreq => 'weekly', :lastmod => Time.now, :images => [], :news => {}, :videos => [], :mobile => false)
|
38
|
+
SitemapGenerator::Utilities.assert_valid_keys(options, :priority, :changefreq, :lastmod, :host, :images, :video, :geo, :news, :videos, :mobile, :alternate, :alternates)
|
39
|
+
SitemapGenerator::Utilities.reverse_merge!(options, :priority => 0.5, :changefreq => 'weekly', :lastmod => Time.now, :images => [], :news => {}, :videos => [], :mobile => false, :alternates => [])
|
39
40
|
raise "Cannot generate a url without a host" unless SitemapGenerator::Utilities.present?(options[:host])
|
40
41
|
if video = options.delete(:video)
|
41
42
|
options[:videos] = video.is_a?(Array) ? options[:videos].concat(video) : options[:videos] << video
|
42
43
|
end
|
44
|
+
if alternate = options.delete(:alternate)
|
45
|
+
options[:alternates] = alternate.is_a?(Array) ? options[:alternates].concat(alternate) : options[:alternates] << alternate
|
46
|
+
end
|
43
47
|
|
44
48
|
path = path.to_s.sub(/^\//, '')
|
45
49
|
loc = path.empty? ? options[:host] : (options[:host].to_s.sub(/\/$/, '') + '/' + path)
|
@@ -53,7 +57,8 @@ module SitemapGenerator
|
|
53
57
|
:news => prepare_news(options[:news]),
|
54
58
|
:videos => options[:videos],
|
55
59
|
:geo => options[:geo],
|
56
|
-
:mobile => options[:mobile]
|
60
|
+
:mobile => options[:mobile],
|
61
|
+
:alternates => options[:alternates]
|
57
62
|
)
|
58
63
|
end
|
59
64
|
|
@@ -120,6 +125,10 @@ module SitemapGenerator
|
|
120
125
|
end
|
121
126
|
end
|
122
127
|
|
128
|
+
self[:alternates].each do |alternate|
|
129
|
+
builder.xhtml :link, :rel => 'alternate', :hreflang => alternate[:lang], :href => alternate[:href]
|
130
|
+
end
|
131
|
+
|
123
132
|
unless SitemapGenerator::Utilities.blank?(self[:geo])
|
124
133
|
geo = self[:geo]
|
125
134
|
builder.geo :geo do
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "SitemapGenerator" do
|
4
|
+
|
5
|
+
it "should add alternate links to sitemap" do
|
6
|
+
xml_fragment = SitemapGenerator::Builder::SitemapUrl.new('link_with_alternates.html',
|
7
|
+
:host => 'http://www.example.com',
|
8
|
+
:alternates => [
|
9
|
+
{
|
10
|
+
:lang => 'de',
|
11
|
+
:href => 'http://www.example.de/link_with_alternate.html'
|
12
|
+
}
|
13
|
+
]
|
14
|
+
).to_xml
|
15
|
+
|
16
|
+
doc = Nokogiri::XML.parse("<root xmlns='http://www.sitemaps.org/schemas/sitemap/0.9' xmlns:xhtml='http://www.w3.org/1999/xhtml'>#{xml_fragment}</root>")
|
17
|
+
url = doc.css('url')
|
18
|
+
url.should_not be_nil
|
19
|
+
url.css('loc').text.should == 'http://www.example.com/link_with_alternates.html'
|
20
|
+
|
21
|
+
alternate = url.at_xpath('xhtml:link')
|
22
|
+
alternate.should_not be_nil
|
23
|
+
alternate.attribute('rel').value.should == 'alternate'
|
24
|
+
alternate.attribute('hreflang').value.should == 'de'
|
25
|
+
alternate.attribute('href').value.should == 'http://www.example.de/link_with_alternate.html'
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -67,6 +67,21 @@ describe SitemapGenerator::Builder::SitemapUrl do
|
|
67
67
|
loc[:videos].should == [3,4,1,2]
|
68
68
|
end
|
69
69
|
|
70
|
+
it "should support a :alternates option" do
|
71
|
+
loc = SitemapGenerator::Builder::SitemapUrl.new('', :host => 'http://test.com', :alternates => [1,2,3])
|
72
|
+
loc[:alternates].should == [1,2,3]
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should support a singular :alternate option" do
|
76
|
+
loc = SitemapGenerator::Builder::SitemapUrl.new('', :host => 'http://test.com', :alternate => 1)
|
77
|
+
loc[:alternates].should == [1]
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should support an array :alternate option" do
|
81
|
+
loc = SitemapGenerator::Builder::SitemapUrl.new('', :host => 'http://test.com', :alternate => [1,2], :alternates => [3,4])
|
82
|
+
loc[:alternates].should == [3,4,1,2]
|
83
|
+
end
|
84
|
+
|
70
85
|
it "should not fail if invalid characters are used in the URL" do
|
71
86
|
special = ':$&+,;:=?@'
|
72
87
|
url = SitemapGenerator::Builder::SitemapUrl.new("/#{special}", :host => "http://example.com/#{special}/")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sitemap_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '3.
|
4
|
+
version: '3.4'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2012-10-03 00:00:00.000000000Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mocha
|
17
|
-
requirement: &
|
17
|
+
requirement: &70204620843820 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70204620843820
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: nokogiri
|
28
|
-
requirement: &
|
28
|
+
requirement: &70204620843380 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70204620843380
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &70204620842960 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70204620842960
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: builder
|
50
|
-
requirement: &
|
50
|
+
requirement: &70204620842540 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70204620842540
|
59
59
|
description: SitemapGenerator is an XML Sitemap generator written in Ruby with automatic
|
60
60
|
Rails integration. It supports Video, News, Image and Geo sitemaps and includes
|
61
61
|
Rake tasks for managing your sitemaps.
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- spec/files/sitemap.create.rb
|
102
102
|
- spec/files/sitemap.deprecated.rb
|
103
103
|
- spec/files/sitemap.groups.rb
|
104
|
+
- spec/sitemap_generator/alternate_sitemap_spec.rb
|
104
105
|
- spec/sitemap_generator/application_spec.rb
|
105
106
|
- spec/sitemap_generator/builder/sitemap_file_spec.rb
|
106
107
|
- spec/sitemap_generator/builder/sitemap_index_file_spec.rb
|
@@ -147,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
148
|
version: '0'
|
148
149
|
segments:
|
149
150
|
- 0
|
150
|
-
hash: -
|
151
|
+
hash: -4570809208005834438
|
151
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
153
|
none: false
|
153
154
|
requirements:
|
@@ -156,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
157
|
version: '0'
|
157
158
|
segments:
|
158
159
|
- 0
|
159
|
-
hash: -
|
160
|
+
hash: -4570809208005834438
|
160
161
|
requirements: []
|
161
162
|
rubyforge_project:
|
162
163
|
rubygems_version: 1.8.10
|
@@ -168,6 +169,7 @@ test_files:
|
|
168
169
|
- spec/files/sitemap.create.rb
|
169
170
|
- spec/files/sitemap.deprecated.rb
|
170
171
|
- spec/files/sitemap.groups.rb
|
172
|
+
- spec/sitemap_generator/alternate_sitemap_spec.rb
|
171
173
|
- spec/sitemap_generator/application_spec.rb
|
172
174
|
- spec/sitemap_generator/builder/sitemap_file_spec.rb
|
173
175
|
- spec/sitemap_generator/builder/sitemap_index_file_spec.rb
|