sitemap 0.1b2 → 0.1
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.
- data/README.rdoc +25 -1
- data/lib/generators/sitemap/USAGE +2 -0
- data/lib/generators/sitemap/install_generator.rb +17 -0
- data/lib/generators/sitemap/templates/sitemap.rb +26 -0
- data/lib/sitemap.rb +1 -142
- data/lib/sitemap/generator.rb +145 -0
- data/lib/sitemap/ping.rb +0 -1
- data/sitemap.gemspec +1 -1
- metadata +13 -9
data/README.rdoc
CHANGED
@@ -2,9 +2,23 @@
|
|
2
2
|
|
3
3
|
A simple ruby on rails sitemap generator.
|
4
4
|
|
5
|
+
== Instalation
|
6
|
+
|
7
|
+
Install the gem:
|
8
|
+
|
9
|
+
gem install sitemap
|
10
|
+
|
11
|
+
Or as a plugin:
|
12
|
+
|
13
|
+
rails plugin install git://github.com/viseztrance/rails-sitemap.git
|
14
|
+
|
15
|
+
Then create the initial config file:
|
16
|
+
|
17
|
+
rails g sitemap:install
|
18
|
+
|
5
19
|
== Usage
|
6
20
|
|
7
|
-
|
21
|
+
In your sitemap config file, paths can be indexed as follows:
|
8
22
|
|
9
23
|
Sitemap::Generator.instance.load :host => "mywebsite.com" do
|
10
24
|
path :root, :priority => 1
|
@@ -23,6 +37,16 @@ Ping search engines:
|
|
23
37
|
|
24
38
|
rake sitemap:ping
|
25
39
|
|
40
|
+
== Setting defaults
|
41
|
+
|
42
|
+
You may change the defaults for either <tt>params</tt> or <tt>search</tt> options as follows:
|
43
|
+
|
44
|
+
Sitemap.defaults[:params] = { :format => "html" }
|
45
|
+
|
46
|
+
== Limitations
|
47
|
+
|
48
|
+
Sitemaps can only have up to 50000 urls and an uncompressed size of 10MB. This issue will be resolved in a future release.
|
49
|
+
|
26
50
|
== License
|
27
51
|
|
28
52
|
This package is licensed under the MIT license and/or the Creative
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Sitemap
|
2
|
+
|
3
|
+
module Generators
|
4
|
+
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
def generate_config
|
10
|
+
copy_file "sitemap.rb", "config/sitemap.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Sitemap::Generator.instance.load :host => "mywebsite.com" do
|
2
|
+
|
3
|
+
# Sample path:
|
4
|
+
# path :faq
|
5
|
+
# The specified path must exist in your routes file (usually specified through :as).
|
6
|
+
|
7
|
+
# Sample path with params:
|
8
|
+
# path :faq, :params => { :format => "html", :filter => "recent" }
|
9
|
+
# Depending on the route, the resolved url could be http://mywebsite.com/frequent-questions.html?filter=recent.
|
10
|
+
|
11
|
+
# Sample resource:
|
12
|
+
# resources :articles
|
13
|
+
|
14
|
+
# Sample resource with custom objects:
|
15
|
+
# resources :articles, :objects => proc { Article.published }
|
16
|
+
|
17
|
+
# Sample resource with search options:
|
18
|
+
# resources :articles, :priority => 0.8, :change_frequency => "monthly"
|
19
|
+
|
20
|
+
# Sample resource with block options:
|
21
|
+
# resources :activities,
|
22
|
+
# :skip_index => true,
|
23
|
+
# :updated_at => proc { |activity| activity.published_at.strftime("%Y-%m-%d") }
|
24
|
+
# :params => { :subdomain => proc { |activity| activity.location } }
|
25
|
+
|
26
|
+
end
|
data/lib/sitemap.rb
CHANGED
@@ -9,6 +9,7 @@ require "singleton"
|
|
9
9
|
require "builder"
|
10
10
|
require "sitemap/railtie"
|
11
11
|
require "sitemap/ping"
|
12
|
+
require "sitemap/generator"
|
12
13
|
|
13
14
|
module Sitemap
|
14
15
|
|
@@ -23,146 +24,4 @@ module Sitemap
|
|
23
24
|
}
|
24
25
|
}
|
25
26
|
|
26
|
-
class Generator
|
27
|
-
|
28
|
-
include Singleton
|
29
|
-
|
30
|
-
SEARCH_ATTRIBUTES = {
|
31
|
-
:updated_at => "lastmod",
|
32
|
-
:change_frequency => "changefreq",
|
33
|
-
:priority => "priority"
|
34
|
-
}
|
35
|
-
|
36
|
-
attr_accessor :entries, :host, :routes
|
37
|
-
|
38
|
-
# Instantiates a new object.
|
39
|
-
# Should never be called directly.
|
40
|
-
def initialize
|
41
|
-
self.class.send(:include, Rails.application.routes.url_helpers)
|
42
|
-
self.entries = []
|
43
|
-
end
|
44
|
-
|
45
|
-
# Sets the urls to be indexed.
|
46
|
-
#
|
47
|
-
# The +host+, or any other global option can be set here:
|
48
|
-
#
|
49
|
-
# Sitemap::Generator.instance.load :host => "mywebsite.com" do
|
50
|
-
# ...
|
51
|
-
# end
|
52
|
-
#
|
53
|
-
# Simple paths can be added as follows:
|
54
|
-
#
|
55
|
-
# Sitemap::Generator.instance.load :host => "mywebsite.com" do
|
56
|
-
# path :faq
|
57
|
-
# end
|
58
|
-
#
|
59
|
-
# Object collections are supported too:
|
60
|
-
#
|
61
|
-
# Sitemap::Generator.instance.load :host => "mywebsite.com" do
|
62
|
-
# resources :activities
|
63
|
-
# end
|
64
|
-
#
|
65
|
-
# Search options such as frequency and priority can be declared as an options hash:
|
66
|
-
#
|
67
|
-
# Sitemap::Generator.instance.load :host => "mywebsite.com" do
|
68
|
-
# path :root, :priority => 1
|
69
|
-
# path :faq, :priority => 0.8, :change_frequency => "daily"
|
70
|
-
# resources :activities, :change_frequency => "weekly"
|
71
|
-
# end
|
72
|
-
#
|
73
|
-
def load(options = {}, &block)
|
74
|
-
options.each do |k, v|
|
75
|
-
self.send("#{k}=", v)
|
76
|
-
end
|
77
|
-
self.routes = block
|
78
|
-
end
|
79
|
-
|
80
|
-
# Adds the specified url or object (such as an ActiveRecord model instance).
|
81
|
-
# In either case the data is being looked up in the current application routes.
|
82
|
-
#
|
83
|
-
# Params can be specified as follows:
|
84
|
-
#
|
85
|
-
# # config/routes.rb
|
86
|
-
# match "/frequent-questions" => "static#faq", :as => "faq"
|
87
|
-
#
|
88
|
-
# # config/sitemap.rb
|
89
|
-
# path :faq, :params => { :filter => "recent" }
|
90
|
-
#
|
91
|
-
# The resolved url would be <tt>http://mywebsite.com/frequent-questions?filter=recent</tt>.
|
92
|
-
#
|
93
|
-
def path(object, options = {})
|
94
|
-
params = Sitemap.defaults[:params].clone.merge!(options[:params] || {})
|
95
|
-
params[:host] ||= host # Use global host if none was specified.
|
96
|
-
params.merge!(params) { |type, value| get_data(object, value) }
|
97
|
-
|
98
|
-
search = Sitemap.defaults[:search].clone.merge!(options.select { |k, v| SEARCH_ATTRIBUTES.keys.include?(k) })
|
99
|
-
search.merge!(search) { |type, value| get_data(object, value) }
|
100
|
-
|
101
|
-
self.entries << {
|
102
|
-
:object => object,
|
103
|
-
:search => search,
|
104
|
-
:params => params
|
105
|
-
}
|
106
|
-
end
|
107
|
-
|
108
|
-
# Adds the associated object types.
|
109
|
-
#
|
110
|
-
# The following will map all Activity entries, as well as the index (<tt>/activities</tt>) page:
|
111
|
-
#
|
112
|
-
# resources :activities
|
113
|
-
#
|
114
|
-
# You can also specify which entries are being mapped:
|
115
|
-
#
|
116
|
-
# resources :articles, :objects => proc { Article.published }
|
117
|
-
#
|
118
|
-
# To skip the index action and map only the records:
|
119
|
-
#
|
120
|
-
# resources :articles, :skip_index => true
|
121
|
-
#
|
122
|
-
# As with the path, you can specify params through the +params+ options hash.
|
123
|
-
# The params can also be build conditionally by using a +proc+:
|
124
|
-
#
|
125
|
-
# resources :activities, :params => { :host => proc { |activity| [activity.location, host].join(".") } }, :skip_index => true
|
126
|
-
#
|
127
|
-
# In this case the host will change based the each of the objects associated +location+ attribute.
|
128
|
-
# Because the index page doesn't have this attribute it's best to skip it.
|
129
|
-
#
|
130
|
-
def resources(type, options = {})
|
131
|
-
path(type) unless options[:skip_index]
|
132
|
-
objects = options[:objects] ? options[:objects].call : type.to_s.classify.constantize.all
|
133
|
-
options.reject! { |k, v| k == :objects }
|
134
|
-
|
135
|
-
objects.each do |object|
|
136
|
-
path(object, options)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# Parses the loaded data and returns the xml entries.
|
141
|
-
def build
|
142
|
-
instance_exec(self, &routes)
|
143
|
-
xml = Builder::XmlMarkup.new(:indent => 2)
|
144
|
-
file = File.read(File.expand_path("../views/index.xml.builder", __FILE__))
|
145
|
-
instance_eval file
|
146
|
-
end
|
147
|
-
|
148
|
-
# Builds xml entries and saves the data to the specified location.
|
149
|
-
def save(location)
|
150
|
-
file = File.new(location, "w")
|
151
|
-
file.write(build)
|
152
|
-
file.close
|
153
|
-
end
|
154
|
-
|
155
|
-
# URL to the <tt>sitemap.xml</tt> file.
|
156
|
-
def file_url
|
157
|
-
URI::HTTP.build(:host => host, :path => "/sitemap.xml").to_s
|
158
|
-
end
|
159
|
-
|
160
|
-
private
|
161
|
-
|
162
|
-
def get_data(object, data)
|
163
|
-
data.is_a?(Proc) ? data.call(object) : data
|
164
|
-
end
|
165
|
-
|
166
|
-
end
|
167
|
-
|
168
27
|
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
module Sitemap
|
2
|
+
|
3
|
+
class Generator
|
4
|
+
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
SEARCH_ATTRIBUTES = {
|
8
|
+
:updated_at => "lastmod",
|
9
|
+
:change_frequency => "changefreq",
|
10
|
+
:priority => "priority"
|
11
|
+
}
|
12
|
+
|
13
|
+
attr_accessor :entries, :host, :routes
|
14
|
+
|
15
|
+
# Instantiates a new object.
|
16
|
+
# Should never be called directly.
|
17
|
+
def initialize
|
18
|
+
self.class.send(:include, Rails.application.routes.url_helpers)
|
19
|
+
self.entries = []
|
20
|
+
end
|
21
|
+
|
22
|
+
# Sets the urls to be indexed.
|
23
|
+
#
|
24
|
+
# The +host+, or any other global option can be set here:
|
25
|
+
#
|
26
|
+
# Sitemap::Generator.instance.load :host => "mywebsite.com" do
|
27
|
+
# ...
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# Simple paths can be added as follows:
|
31
|
+
#
|
32
|
+
# Sitemap::Generator.instance.load :host => "mywebsite.com" do
|
33
|
+
# path :faq
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# Object collections are supported too:
|
37
|
+
#
|
38
|
+
# Sitemap::Generator.instance.load :host => "mywebsite.com" do
|
39
|
+
# resources :activities
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# Search options such as frequency and priority can be declared as an options hash:
|
43
|
+
#
|
44
|
+
# Sitemap::Generator.instance.load :host => "mywebsite.com" do
|
45
|
+
# path :root, :priority => 1
|
46
|
+
# path :faq, :priority => 0.8, :change_frequency => "daily"
|
47
|
+
# resources :activities, :change_frequency => "weekly"
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
def load(options = {}, &block)
|
51
|
+
options.each do |k, v|
|
52
|
+
self.send("#{k}=", v)
|
53
|
+
end
|
54
|
+
self.routes = block
|
55
|
+
end
|
56
|
+
|
57
|
+
# Adds the specified url or object (such as an ActiveRecord model instance).
|
58
|
+
# In either case the data is being looked up in the current application routes.
|
59
|
+
#
|
60
|
+
# Params can be specified as follows:
|
61
|
+
#
|
62
|
+
# # config/routes.rb
|
63
|
+
# match "/frequent-questions" => "static#faq", :as => "faq"
|
64
|
+
#
|
65
|
+
# # config/sitemap.rb
|
66
|
+
# path :faq, :params => { :filter => "recent" }
|
67
|
+
#
|
68
|
+
# The resolved url would be <tt>http://mywebsite.com/frequent-questions?filter=recent</tt>.
|
69
|
+
#
|
70
|
+
def path(object, options = {})
|
71
|
+
params = Sitemap.defaults[:params].clone.merge!(options[:params] || {})
|
72
|
+
params[:host] ||= host # Use global host if none was specified.
|
73
|
+
params.merge!(params) { |type, value| get_data(object, value) }
|
74
|
+
|
75
|
+
search = Sitemap.defaults[:search].clone.merge!(options.select { |k, v| SEARCH_ATTRIBUTES.keys.include?(k) })
|
76
|
+
search.merge!(search) { |type, value| get_data(object, value) }
|
77
|
+
|
78
|
+
self.entries << {
|
79
|
+
:object => object,
|
80
|
+
:search => search,
|
81
|
+
:params => params
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
# Adds the associated object types.
|
86
|
+
#
|
87
|
+
# The following will map all Activity entries, as well as the index (<tt>/activities</tt>) page:
|
88
|
+
#
|
89
|
+
# resources :activities
|
90
|
+
#
|
91
|
+
# You can also specify which entries are being mapped:
|
92
|
+
#
|
93
|
+
# resources :articles, :objects => proc { Article.published }
|
94
|
+
#
|
95
|
+
# To skip the index action and map only the records:
|
96
|
+
#
|
97
|
+
# resources :articles, :skip_index => true
|
98
|
+
#
|
99
|
+
# As with the path, you can specify params through the +params+ options hash.
|
100
|
+
# The params can also be build conditionally by using a +proc+:
|
101
|
+
#
|
102
|
+
# resources :activities, :params => { :host => proc { |activity| [activity.location, host].join(".") } }, :skip_index => true
|
103
|
+
#
|
104
|
+
# In this case the host will change based the each of the objects associated +location+ attribute.
|
105
|
+
# Because the index page doesn't have this attribute it's best to skip it.
|
106
|
+
#
|
107
|
+
def resources(type, options = {})
|
108
|
+
path(type) unless options[:skip_index]
|
109
|
+
objects = options[:objects] ? options[:objects].call : type.to_s.classify.constantize.all
|
110
|
+
options.reject! { |k, v| k == :objects }
|
111
|
+
|
112
|
+
objects.each do |object|
|
113
|
+
path(object, options)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# Parses the loaded data and returns the xml entries.
|
118
|
+
def build
|
119
|
+
instance_exec(self, &routes)
|
120
|
+
xml = Builder::XmlMarkup.new(:indent => 2)
|
121
|
+
file = File.read(File.expand_path("../../views/index.xml.builder", __FILE__))
|
122
|
+
instance_eval file
|
123
|
+
end
|
124
|
+
|
125
|
+
# Builds xml entries and saves the data to the specified location.
|
126
|
+
def save(location)
|
127
|
+
file = File.new(location, "w")
|
128
|
+
file.write(build)
|
129
|
+
file.close
|
130
|
+
end
|
131
|
+
|
132
|
+
# URL to the <tt>sitemap.xml</tt> file.
|
133
|
+
def file_url
|
134
|
+
URI::HTTP.build(:host => host, :path => "/sitemap.xml").to_s
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
def get_data(object, data)
|
140
|
+
data.is_a?(Proc) ? data.call(object) : data
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
data/lib/sitemap/ping.rb
CHANGED
@@ -7,7 +7,6 @@ module Sitemap
|
|
7
7
|
|
8
8
|
SEARCH_ENGINES = {
|
9
9
|
"Google" => "http://www.google.com/webmasters/tools/ping?sitemap=%s",
|
10
|
-
"Yahoo!" => "http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=SitemapWriter&url=%s",
|
11
10
|
"Ask.com" => "http://submissions.ask.com/ping?sitemap=%s",
|
12
11
|
"Bing" => "http://www.bing.com/webmaster/ping.aspx?siteMap=%s"
|
13
12
|
}
|
data/sitemap.gemspec
CHANGED
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sitemap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Daniel Mircea
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-10 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sqlite3
|
16
|
-
requirement: &
|
16
|
+
requirement: &17823580 !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: *17823580
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &17823140 !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: *17823140
|
36
36
|
description: A simple ruby on rails sitemap generator
|
37
37
|
email: daniel@viseztrance.com
|
38
38
|
executables: []
|
@@ -41,9 +41,13 @@ extra_rdoc_files:
|
|
41
41
|
- README.rdoc
|
42
42
|
- LICENSE
|
43
43
|
files:
|
44
|
+
- lib/generators/sitemap/USAGE
|
45
|
+
- lib/generators/sitemap/templates/sitemap.rb
|
46
|
+
- lib/generators/sitemap/install_generator.rb
|
44
47
|
- lib/views/index.xml.builder
|
45
48
|
- lib/sitemap.rb
|
46
49
|
- lib/sitemap/railtie.rb
|
50
|
+
- lib/sitemap/generator.rb
|
47
51
|
- lib/sitemap/ping.rb
|
48
52
|
- lib/tasks/sitemap.rake
|
49
53
|
- README.rdoc
|
@@ -73,9 +77,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
78
|
none: false
|
75
79
|
requirements:
|
76
|
-
- - ! '
|
80
|
+
- - ! '>='
|
77
81
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
82
|
+
version: '0'
|
79
83
|
requirements: []
|
80
84
|
rubyforge_project:
|
81
85
|
rubygems_version: 1.8.8
|