sitemap_generator 1.2.3 → 1.3.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/VERSION +1 -1
- data/lib/sitemap_generator/builder/sitemap_file.rb +10 -1
- data/lib/sitemap_generator/interpreter.rb +20 -8
- data/lib/sitemap_generator/link_set.rb +38 -15
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.1
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'builder'
|
2
2
|
require 'zlib'
|
3
|
-
require 'action_view'
|
3
|
+
require 'action_view' # for number_to_human_size
|
4
|
+
require 'fileutils'
|
4
5
|
|
5
6
|
module SitemapGenerator
|
6
7
|
module Builder
|
@@ -111,6 +112,14 @@ module SitemapGenerator
|
|
111
112
|
def finalize!
|
112
113
|
raise SitemapGenerator::SitemapFinalized if self.finalized?
|
113
114
|
|
115
|
+
# Ensure that the directory exists
|
116
|
+
dir = File.dirname(self.full_path)
|
117
|
+
if !File.exists?(dir)
|
118
|
+
FileUtils.mkdir_p(dir)
|
119
|
+
elsif !File.directory?(dir)
|
120
|
+
raise SitemapError.new("#{dir} should be a directory!")
|
121
|
+
end
|
122
|
+
|
114
123
|
open(self.full_path, 'wb') do |file|
|
115
124
|
gz = Zlib::GzipWriter.new(file)
|
116
125
|
gz.write @xml_wrapper_start
|
@@ -11,18 +11,30 @@ module SitemapGenerator
|
|
11
11
|
include ActionController::UrlWriter
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
# Call with a block to evaluate a dynamic config. The only method exposed for you is
|
15
|
+
# `add` to add a link to the sitemap object attached to this interpreter.
|
16
|
+
#
|
17
|
+
# @param sitemap a sitemap object
|
18
|
+
# @param sitemap_config_file full path to the config file (default is config/sitemap.rb)
|
19
|
+
def initialize(sitemap, sitemap_config_file=nil, &block)
|
20
|
+
@sitemap = sitemap
|
21
|
+
if block_given?
|
22
|
+
instance_eval(&block)
|
23
|
+
else
|
24
|
+
sitemap_config_file ||= File.join(::Rails.root, 'config/sitemap.rb')
|
25
|
+
config = open(sitemap_config_file).read
|
26
|
+
eval(config)
|
27
|
+
end
|
17
28
|
end
|
18
29
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
# end
|
30
|
+
def add(*args)
|
31
|
+
@sitemap.add(*args)
|
32
|
+
end
|
23
33
|
|
34
|
+
# Evaluate the sitemap config file in this namespace which includes the
|
35
|
+
# URL helpers.
|
24
36
|
def self.run
|
25
|
-
new
|
37
|
+
new(SitemapGenerator::Sitemap)
|
26
38
|
end
|
27
39
|
end
|
28
40
|
end
|
@@ -7,7 +7,7 @@ module SitemapGenerator
|
|
7
7
|
class LinkSet
|
8
8
|
include ActionView::Helpers::NumberHelper # for number_with_delimiter
|
9
9
|
|
10
|
-
|
10
|
+
attr_reader :default_host, :public_path, :sitemaps_path
|
11
11
|
attr_accessor :sitemap, :sitemap_index
|
12
12
|
attr_accessor :verbose, :yahoo_app_id
|
13
13
|
|
@@ -18,26 +18,25 @@ module SitemapGenerator
|
|
18
18
|
#
|
19
19
|
# TODO: Refactor so that we can have multiple instances
|
20
20
|
# of LinkSet.
|
21
|
-
def create
|
21
|
+
def create(&block)
|
22
22
|
require 'sitemap_generator/interpreter'
|
23
23
|
|
24
|
-
self.public_path = File.join(::Rails.root, 'public/') if self.public_path.nil?
|
25
|
-
|
26
|
-
# Default host is not set yet. Set it on these objects when `add_links` is called
|
27
|
-
self.sitemap_index = SitemapGenerator::Builder::SitemapIndexFile.new(public_path, sitemap_index_path)
|
28
|
-
self.sitemap = SitemapGenerator::Builder::SitemapFile.new(public_path, new_sitemap_path)
|
29
|
-
|
30
24
|
start_time = Time.now
|
31
|
-
|
25
|
+
if self.sitemap_index.finalized?
|
26
|
+
self.sitemap_index = SitemapGenerator::Builder::SitemapIndexFile.new(@public_path, sitemap_index_path)
|
27
|
+
self.sitemap = SitemapGenerator::Builder::SitemapFile.new(@public_path, new_sitemap_path)
|
28
|
+
end
|
29
|
+
|
30
|
+
SitemapGenerator::Interpreter.new(self, &block)
|
32
31
|
unless self.sitemap.finalized?
|
33
32
|
self.sitemap_index.add(self.sitemap)
|
34
33
|
puts self.sitemap.summary if verbose
|
35
34
|
end
|
36
35
|
self.sitemap_index.finalize!
|
37
36
|
end_time = Time.now
|
38
|
-
|
37
|
+
|
39
38
|
if verbose
|
40
|
-
puts self.sitemap_index.summary
|
39
|
+
puts self.sitemap_index.summary
|
41
40
|
puts "\nSitemap stats: #{number_with_delimiter(self.sitemap_index.total_link_count)} links / #{self.sitemap_index.sitemaps.size} sitemaps / " +
|
42
41
|
("%dm%02ds" % (end_time - start_time).divmod(60))
|
43
42
|
end
|
@@ -54,9 +53,15 @@ module SitemapGenerator
|
|
54
53
|
# <tt>default_host</tt> hostname including protocol to use in all sitemap links
|
55
54
|
# e.g. http://en.google.ca
|
56
55
|
def initialize(public_path = nil, sitemaps_path = nil, default_host = nil)
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
@default_host = default_host
|
57
|
+
@public_path = public_path
|
58
|
+
@sitemaps_path = sitemaps_path
|
59
|
+
|
60
|
+
@public_path = File.join(::Rails.root, 'public/') if @public_path.nil?
|
61
|
+
|
62
|
+
# Default host is not set yet. Set it on these objects when `add_links` is called
|
63
|
+
self.sitemap_index = SitemapGenerator::Builder::SitemapIndexFile.new(@public_path, sitemap_index_path)
|
64
|
+
self.sitemap = SitemapGenerator::Builder::SitemapFile.new(@public_path, new_sitemap_path)
|
60
65
|
end
|
61
66
|
|
62
67
|
# Entry point for users.
|
@@ -132,7 +137,25 @@ module SitemapGenerator
|
|
132
137
|
def link_count
|
133
138
|
self.sitemap_index.total_link_count
|
134
139
|
end
|
135
|
-
|
140
|
+
|
141
|
+
def default_host=(value)
|
142
|
+
@default_host = value
|
143
|
+
self.sitemap_index.hostname = value unless self.sitemap_index.finalized?
|
144
|
+
self.sitemap.hostname = value unless self.sitemap.finalized?
|
145
|
+
end
|
146
|
+
|
147
|
+
def public_path=(value)
|
148
|
+
@public_path = value
|
149
|
+
self.sitemap_index.public_path = value unless self.sitemap_index.finalized?
|
150
|
+
self.sitemap.public_path = value unless self.sitemap.finalized?
|
151
|
+
end
|
152
|
+
|
153
|
+
def sitemaps_path=(value)
|
154
|
+
@sitemaps_path = value
|
155
|
+
self.sitemap_index.sitemap_path = sitemap_index_path unless self.sitemap_index.finalized?
|
156
|
+
self.sitemap.sitemap_path = new_sitemap_path unless self.sitemap.finalized?
|
157
|
+
end
|
158
|
+
|
136
159
|
protected
|
137
160
|
|
138
161
|
# Return the current sitemap filename with index.
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
- 2
|
9
8
|
- 3
|
10
|
-
|
9
|
+
- 1
|
10
|
+
version: 1.3.1
|
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-
|
19
|
+
date: 2010-11-02 00:00:00 -07:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|