sitemap_notifier 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
|
|
1
|
+
# replace this with your own url
|
2
|
+
SitemapNotifier::Notifier.sitemap_url = "http://example.com/sitemap.xml"
|
3
|
+
|
4
|
+
# source models – default is :all for all models
|
5
|
+
# SitemapNotifier::Notifier.sources = [:articles, :categories]
|
6
|
+
|
7
|
+
# enabled in which environments – default is [:production]
|
8
|
+
# SitemapNotifier::Notifier.environments = [:development, :production]
|
9
|
+
# SitemapNotifier::Notifier.environments = :all
|
10
|
+
|
11
|
+
# delay to wait between notifications – default is 600 seconds
|
12
|
+
# SitemapNotifier::Notifier.delay = 30
|
13
|
+
|
14
|
+
# additional urls – be sure to call this after setting sitemap_url
|
15
|
+
# SitemapNotifier::Notifier.urls << "http://localhost:3000/ping"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SitemapNotifier
|
2
|
+
module ActiveRecord
|
3
|
+
def notify_sitemap
|
4
|
+
notifier = ::SitemapNotifier::Notifier
|
5
|
+
|
6
|
+
if notifier.sources == :all || notifier.sources.include?(self.class.name.tableize.to_sym)
|
7
|
+
notifier.notify!
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.included(base)
|
12
|
+
base.after_save :notify_sitemap
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
module SitemapNotifier
|
6
|
+
class Notifier
|
7
|
+
class << self
|
8
|
+
# sitemap url
|
9
|
+
attr_accessor :sitemap_url
|
10
|
+
|
11
|
+
# source
|
12
|
+
attr_writer :sources
|
13
|
+
def sources
|
14
|
+
@sources ||= :all
|
15
|
+
end
|
16
|
+
|
17
|
+
# delay
|
18
|
+
attr_writer :delay
|
19
|
+
def delay
|
20
|
+
@delay ||= 600
|
21
|
+
end
|
22
|
+
|
23
|
+
# environments
|
24
|
+
attr_writer :environments
|
25
|
+
def environments
|
26
|
+
@environments ||= [:production]
|
27
|
+
end
|
28
|
+
|
29
|
+
# urls
|
30
|
+
attr_writer :urls
|
31
|
+
def urls
|
32
|
+
@urls ||= ["http://www.google.com/webmasters/sitemaps/ping?sitemap=#{CGI::escape(sitemap_url)}",
|
33
|
+
"http://www.bing.com/webmaster/ping.aspx?siteMap=#{CGI::escape(sitemap_url)}",
|
34
|
+
"http://submissions.ask.com/ping?sitemap=#{CGI::escape(sitemap_url)}"]
|
35
|
+
# no Yahoo here, as they will be using Bing from september 15th, 2011
|
36
|
+
end
|
37
|
+
|
38
|
+
# running pid
|
39
|
+
attr_accessor :running_pid
|
40
|
+
|
41
|
+
def notify!
|
42
|
+
raise "sitemap_url not set – use SitemapNotifier::Notifier.sitemap_url = 'xx'" unless sitemap_url
|
43
|
+
|
44
|
+
if (environments == :all || environments.include?(Rails.env.to_sym)) && !running?
|
45
|
+
self.running_pid = fork do
|
46
|
+
Rails.logger.info "Notifying search engines of changes to sitemap..."
|
47
|
+
|
48
|
+
urls.each do |url|
|
49
|
+
if get_url(url)
|
50
|
+
Rails.logger.info "#{url} – ok"
|
51
|
+
else
|
52
|
+
Rails.logger.info "#{url} – failed"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
sleep delay
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
def get_url(url)
|
65
|
+
uri = URI.parse(url)
|
66
|
+
begin
|
67
|
+
return Net::HTTPSuccess === Net::HTTP.get_response(uri)
|
68
|
+
rescue Exception
|
69
|
+
return false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def running?
|
74
|
+
return false unless running_pid
|
75
|
+
|
76
|
+
begin
|
77
|
+
Process.getpgid(running_pid)
|
78
|
+
true
|
79
|
+
rescue Errno::ESRCH
|
80
|
+
false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sitemap_notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Lasse Bunk
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-20 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Ruby on Rails plugin that automatically notifies Google, Bing, Yahoo, and Ask.com of changes to your models, i.e. changes to your sitemap.
|
22
|
+
email: lassebunk@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/generators/sitemap_notifier/sitemap_notifier_generator.rb
|
31
|
+
- lib/generators/sitemap_notifier/templates/initializer.rb
|
32
|
+
- lib/sitemap_notifier/active_record.rb
|
33
|
+
- lib/sitemap_notifier/notifier.rb
|
34
|
+
- lib/sitemap_notifier.rb
|
35
|
+
homepage: http://github.com/lassebunk/sitemap_notifier
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
hash: 3
|
49
|
+
segments:
|
50
|
+
- 0
|
51
|
+
version: "0"
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.8.10
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Automatically notify search engines when your models are updated.
|
68
|
+
test_files: []
|
69
|
+
|