massive_sitemap 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +20 -3
- data/VERSION +1 -1
- data/lib/massive_sitemap/ping.rb +15 -4
- data/spec/massive_sitemap_spec.rb +8 -1
- data/spec/ping_spec.rb +16 -7
- metadata +6 -6
data/README.md
CHANGED
@@ -8,14 +8,31 @@ It implements various generation stategies, e.g. to split large Sitemaps into mu
|
|
8
8
|
|
9
9
|
## Usage
|
10
10
|
|
11
|
-
A simple usecase which fits most of the standard scenarios
|
11
|
+
A simple usecase which fits most of the standard scenarios. This example adds `http://test.com/about` to the sitemap.
|
12
12
|
|
13
13
|
|
14
14
|
```ruby
|
15
15
|
require 'massive_sitemap'
|
16
16
|
|
17
|
-
index_url = MassiveSitemap.generate(:url => 'test.
|
18
|
-
add "
|
17
|
+
index_url = MassiveSitemap.generate(:url => 'test.com') do
|
18
|
+
add "/about"
|
19
|
+
end
|
20
|
+
MassiveSitemap.ping(index_url)
|
21
|
+
|
22
|
+
```
|
23
|
+
|
24
|
+
### Using Rails (ActiveRecord)
|
25
|
+
|
26
|
+
This exmaple itterates of the `User` resource and adds each with a `change_frequency`, `last_modified` and `priority` to the sitemap. In case there are more than 50.000 users, the sitemap will be auto-split in multiple files. See
|
27
|
+
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'massive_sitemap'
|
31
|
+
|
32
|
+
index_url = MassiveSitemap.generate(:url => 'test.com') do
|
33
|
+
User.all do |user|
|
34
|
+
add "/users/#{user.id}", :change_frequency => 'weekly', :last_modified => user.updated_at, :priority => 0.9
|
35
|
+
end
|
19
36
|
end
|
20
37
|
MassiveSitemap.ping(index_url)
|
21
38
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.1.0
|
data/lib/massive_sitemap/ping.rb
CHANGED
@@ -5,22 +5,30 @@ require 'open-uri'
|
|
5
5
|
|
6
6
|
# Ping Search Engines to pull the latest update
|
7
7
|
module MassiveSitemap
|
8
|
+
extend self
|
9
|
+
|
8
10
|
ENGINES_URLS = {
|
9
11
|
:google => 'http://www.google.com/webmasters/tools/ping?sitemap=%s',
|
10
12
|
:bing => 'http://www.bing.com/webmaster/ping.aspx?siteMap=%s',
|
11
13
|
:ask => 'http://submissions.ask.com/ping?sitemap=%s',
|
14
|
+
:yandex => 'http://webmaster.yandex.ru/wmconsole/sitemap_list.xml?host=%s',
|
12
15
|
}
|
13
16
|
|
14
|
-
|
17
|
+
DEFAULT_ENGINES = [:google, :bing, :yandex] #ask seems to be down, so disable for now by default
|
18
|
+
|
19
|
+
def ping(url, engines = DEFAULT_ENGINES)
|
15
20
|
url = verify_and_escape(url)
|
16
21
|
|
17
22
|
Array(engines).each do |engine|
|
18
23
|
if engine_url = ENGINES_URLS[engine]
|
19
|
-
|
24
|
+
begin
|
25
|
+
open(engine_url % url)
|
26
|
+
rescue => e
|
27
|
+
log_error(engine, e)
|
28
|
+
end
|
20
29
|
end
|
21
30
|
end
|
22
31
|
end
|
23
|
-
module_function :ping
|
24
32
|
|
25
33
|
private
|
26
34
|
def verify_and_escape(url)
|
@@ -28,5 +36,8 @@ module MassiveSitemap
|
|
28
36
|
raise URI::InvalidURIError, url if path.to_s.empty?
|
29
37
|
CGI::escape("#{schema || 'http://'}#{host}#{path}")
|
30
38
|
end
|
31
|
-
|
39
|
+
|
40
|
+
def log_error(engine, error)
|
41
|
+
$stderr.puts "Error pinging #{engine} #{error.message}"
|
42
|
+
end
|
32
43
|
end
|
@@ -80,6 +80,13 @@ describe MassiveSitemap do
|
|
80
80
|
output.should include("<loc>http://test.de/track/name</loc>")
|
81
81
|
end
|
82
82
|
|
83
|
+
it 'adds url with no tryiling root for domain' do
|
84
|
+
MassiveSitemap.generate(:url => 'test.de') do
|
85
|
+
add "/track/name"
|
86
|
+
end
|
87
|
+
output.should include("<loc>http://test.de/track/name</loc>")
|
88
|
+
end
|
89
|
+
|
83
90
|
it "to fail for existing file" do
|
84
91
|
File.open(filename, 'w') {}
|
85
92
|
expect do
|
@@ -170,7 +177,7 @@ describe MassiveSitemap do
|
|
170
177
|
PINGS = [
|
171
178
|
"http://www.google.com/webmasters/tools/ping?sitemap=http%3A%2F%2Ftest.de%2Fsitemap_index.xml",
|
172
179
|
"http://www.bing.com/webmaster/ping.aspx?siteMap=http%3A%2F%2Ftest.de%2Fsitemap_index.xml",
|
173
|
-
"http://
|
180
|
+
"http://webmaster.yandex.ru/wmconsole/sitemap_list.xml?host=http%3A%2F%2Ftest.de%2Fsitemap_index.xml",
|
174
181
|
]
|
175
182
|
|
176
183
|
it 'calls all engines' do
|
data/spec/ping_spec.rb
CHANGED
@@ -5,21 +5,21 @@ describe MassiveSitemap do
|
|
5
5
|
let(:url) { "http://www.example.com" }
|
6
6
|
|
7
7
|
describe "verify_and_escape" do
|
8
|
-
it { MassiveSitemap.verify_and_escape
|
9
|
-
it { MassiveSitemap.verify_and_escape
|
10
|
-
it { MassiveSitemap.verify_and_escape
|
8
|
+
it { MassiveSitemap.send(:verify_and_escape, "example.com/test").should == "http%3A%2F%2Fexample.com%2Ftest" }
|
9
|
+
it { MassiveSitemap.send(:verify_and_escape, "http://example.com/test").should == "http%3A%2F%2Fexample.com%2Ftest" }
|
10
|
+
it { MassiveSitemap.send(:verify_and_escape, "https://example.com/test").should == "https%3A%2F%2Fexample.com%2Ftest" }
|
11
11
|
|
12
12
|
it "raise if invalid url" do
|
13
13
|
expect do
|
14
|
-
MassiveSitemap.verify_and_escape
|
14
|
+
MassiveSitemap.send(:verify_and_escape, "example.com/")
|
15
15
|
end.to raise_error URI::InvalidURIError
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "ping" do
|
20
|
-
it "calles google and
|
21
|
-
MassiveSitemap.should_receive(:open).twice
|
22
|
-
MassiveSitemap.ping(url, [:google, :
|
20
|
+
it "calles google and yandex" do
|
21
|
+
MassiveSitemap.should_receive(:open).twice
|
22
|
+
MassiveSitemap.ping(url, [:google, :yandex])
|
23
23
|
end
|
24
24
|
|
25
25
|
it "doesn't fail for unknown engines" do
|
@@ -27,6 +27,15 @@ describe MassiveSitemap do
|
|
27
27
|
MassiveSitemap.ping(url, :unknown)
|
28
28
|
end.to_not raise_error
|
29
29
|
end
|
30
|
+
|
31
|
+
it "doesn't fail when it can't talk to an engine" do
|
32
|
+
MassiveSitemap.should_receive(:open).twice.and_raise(StandardError)
|
33
|
+
MassiveSitemap.stub(:log_error) # supress error output
|
34
|
+
|
35
|
+
expect do
|
36
|
+
MassiveSitemap.ping(url, [:google, :ask])
|
37
|
+
end.to_not raise_error
|
38
|
+
end
|
30
39
|
end
|
31
40
|
end
|
32
41
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: massive_sitemap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-15 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70119062645900 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70119062645900
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70119062645420 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70119062645420
|
36
36
|
description: MassiveSitemap - build huge sitemaps painfree. Differential updates keeps
|
37
37
|
generation time short and reduces load on DB. It's heavealy inspired by BigSitemaps
|
38
38
|
and offers compatiable API
|