middleman-sitemap 0.0.5 → 0.0.6
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.
- checksums.yaml +4 -4
- data/features/multiple_sitemaps.feature +20 -1
- data/lib/middleman-sitemap.rb +4 -96
- data/lib/middleman-sitemap/extension.rb +100 -0
- data/middleman-sitemap.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f8f539efe5586eba219cffefa34d05936988698
|
4
|
+
data.tar.gz: 38c2ee30b0f4609f9c99c64e653e1760c70dd057
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7423df9fc0816b610fd75046ed0eb0d2810d10e65a683f832b521ccba0e93190fdf0a3645afacee2a0464186fd6e030f725511ab2c25456d9324c2562f6db76d
|
7
|
+
data.tar.gz: 676b2db45e38175c1a048dc7034d8475c3cc3335d903b60d4ae2d2d5c427a56b7090da2fc281c0d60f43ae7b50dca5340c9f4cfab1eabfa6514cbadda817e404
|
@@ -7,8 +7,27 @@ Feature: Multiple sitemaps for large sites
|
|
7
7
|
| build/sitemap.xml |
|
8
8
|
|
9
9
|
@slow
|
10
|
-
Scenario:
|
10
|
+
Scenario: Large site should have multiple sitemaps
|
11
11
|
Given a successfully built app at "large-site-app"
|
12
12
|
Then the following files should exist:
|
13
13
|
| build/sitemap1.xml |
|
14
14
|
| build/sitemap2.xml |
|
15
|
+
|
16
|
+
Scenario: Small site should have multiple sitemaps
|
17
|
+
Given a successfully built app at "gzip-app"
|
18
|
+
Then the following files should not exist:
|
19
|
+
| build/sitemap1.xml |
|
20
|
+
| build/sitemap2.xml |
|
21
|
+
|
22
|
+
@slow
|
23
|
+
Scenario: Site should have multiple sitemaps even when gzipped
|
24
|
+
Given a fixture app "large-site-app"
|
25
|
+
And a file named "config.rb" with:
|
26
|
+
"""
|
27
|
+
activate :gzip
|
28
|
+
activate :sitemap
|
29
|
+
"""
|
30
|
+
And a successfully built app at "large-site-app"
|
31
|
+
Then the following files should exist:
|
32
|
+
| build/sitemap1.xml |
|
33
|
+
| build/sitemap2.xml |
|
data/lib/middleman-sitemap.rb
CHANGED
@@ -1,101 +1,9 @@
|
|
1
1
|
# Require core library
|
2
2
|
require 'middleman-core'
|
3
3
|
|
4
|
-
|
5
|
-
class Sitemap < ::Middleman::Extension
|
6
|
-
option :gzip, true, 'Whether or not to GZIP the resulting file'
|
7
|
-
option :hostname, "http://www.example.com", "The hostname for your website"
|
8
|
-
|
9
|
-
def initialize(app, options_hash={}, &block)
|
10
|
-
# Call super to build options from the options_hash
|
11
|
-
super
|
12
|
-
|
13
|
-
# Require libraries only when activated
|
14
|
-
require 'erb'
|
15
|
-
|
16
|
-
# set up your extension
|
17
|
-
# puts options.my_option
|
18
|
-
end
|
19
|
-
|
20
|
-
def after_build(builder)
|
21
|
-
@builder = builder
|
22
|
-
pages = app.sitemap.resources.find_all{ |p| p.source_file.match(/\.html$/) }
|
23
|
-
|
24
|
-
if pages.count > 50000
|
25
|
-
sitemaps = build_multiple_sitemaps(pages)
|
26
|
-
else
|
27
|
-
sitemaps = [build_sitemap("sitemap.xml", pages)]
|
28
|
-
end
|
29
|
-
|
30
|
-
if options.gzip
|
31
|
-
sitemaps.each do |sitemap|
|
32
|
-
gzip_file(File.read(sitemap))
|
33
|
-
@builder.say_status :create, "#{sitemap}.gz"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def build_sitemap_index(sitemaps)
|
39
|
-
@hostname = options.hostname
|
40
|
-
@sitemaps = sitemaps
|
41
|
-
template = Tilt::ERBTemplate.new(File.expand_path(File.join("#{File.dirname(__FILE__)}", "../templates/sitemapindex.xml.erb")))
|
42
|
-
sitemap = template.render(self)
|
43
|
-
|
44
|
-
outfile = File.join(app.build_dir, "sitemap.xml")
|
45
|
-
File.open(outfile, 'w') {|f| f.write(sitemap) }
|
46
|
-
|
47
|
-
@builder.say_status :create, "build/sitemap.xml"
|
48
|
-
|
49
|
-
return "build/sitemap.xml"
|
50
|
-
end
|
51
|
-
|
52
|
-
def build_sitemap(name, pages)
|
53
|
-
@pages = pages
|
54
|
-
@hostname = options.hostname
|
55
|
-
template = Tilt::ERBTemplate.new(File.expand_path(File.join("#{File.dirname(__FILE__)}", "../templates/sitemap.xml.erb")))
|
56
|
-
sitemap = template.render(self)
|
57
|
-
|
58
|
-
outfile = File.join(app.build_dir, name)
|
59
|
-
File.open(outfile, 'w') {|f| f.write(sitemap) }
|
60
|
-
|
61
|
-
@builder.say_status :create, "build/#{name}"
|
62
|
-
|
63
|
-
return "build/#{name}"
|
64
|
-
end
|
65
|
-
|
66
|
-
def build_multiple_sitemaps(pages)
|
67
|
-
built_sitemaps = []
|
68
|
-
total_sitemaps = (pages.count / 50000.0).ceil
|
69
|
-
pages_per_sitemap = (50000.0 / total_sitemaps).ceil
|
70
|
-
built_sitemaps << build_sitemap_index(total_sitemaps)
|
71
|
-
1.upto(total_sitemaps) do |i|
|
72
|
-
sitemap_pages = pages[((i - 1) * pages_per_sitemap)...(i * pages_per_sitemap)]
|
73
|
-
built_sitemaps << build_sitemap("sitemap#{i}.xml", sitemap_pages)
|
74
|
-
end
|
75
|
-
|
76
|
-
return built_sitemaps
|
77
|
-
end
|
78
|
-
|
79
|
-
def gzip_file(sitemap)
|
80
|
-
require 'zlib'
|
81
|
-
File.open(File.join(@app.build_dir, "sitemap.xml.gz"), 'wb') do |f|
|
82
|
-
gz = Zlib::GzipWriter.new(f, Zlib::BEST_COMPRESSION)
|
83
|
-
gz.write sitemap
|
84
|
-
gz.close
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# Returns a URL with proper HTML entities
|
89
|
-
def urlencode(url)
|
90
|
-
purl = URI.parse(url)
|
91
|
-
path_match = purl.path.match(/\/([^.]+)/)
|
92
|
-
if path_match
|
93
|
-
escaped_path = app.escape_html(path_match[1])
|
94
|
-
purl.path = "/#{escaped_path}.html"
|
95
|
-
end
|
96
|
-
return purl.to_s
|
97
|
-
end
|
4
|
+
require 'middleman-sitemap/commands'
|
98
5
|
|
6
|
+
::Middleman::Extensions.register(:sitemap) do
|
7
|
+
require 'middleman-sitemap/extension'
|
8
|
+
Sitemap
|
99
9
|
end
|
100
|
-
|
101
|
-
::Middleman::Extensions.register(:sitemap, Sitemap)
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# Extension namespace
|
2
|
+
class Sitemap < ::Middleman::Extension
|
3
|
+
option :gzip, true, 'Whether or not to GZIP the resulting file'
|
4
|
+
option :hostname, "http://www.example.com", "The hostname for your website"
|
5
|
+
|
6
|
+
def initialize(app, options_hash={}, &block)
|
7
|
+
# Call super to build options from the options_hash
|
8
|
+
super
|
9
|
+
|
10
|
+
# Require libraries only when activated
|
11
|
+
require 'erb'
|
12
|
+
|
13
|
+
# set up your extension
|
14
|
+
# puts options.my_option
|
15
|
+
end
|
16
|
+
|
17
|
+
def after_build(builder)
|
18
|
+
@builder = builder
|
19
|
+
generate_sitemap
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate_sitemap
|
23
|
+
pages = app.sitemap.resources.find_all{ |p| p.ext == ".html" }
|
24
|
+
|
25
|
+
if pages.count > 50000
|
26
|
+
sitemaps = build_multiple_sitemaps(pages)
|
27
|
+
else
|
28
|
+
sitemaps = [build_sitemap("sitemap.xml", pages)]
|
29
|
+
end
|
30
|
+
|
31
|
+
if options.gzip
|
32
|
+
sitemaps.each do |sitemap|
|
33
|
+
gzip_file(File.read(sitemap))
|
34
|
+
@builder.say_status :create, "#{sitemap}.gz" if @builder
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def build_sitemap_index(sitemaps)
|
40
|
+
@hostname = options.hostname
|
41
|
+
@sitemaps = sitemaps
|
42
|
+
template = Tilt::ERBTemplate.new(File.expand_path(File.join("#{File.dirname(__FILE__)}", "../../templates/sitemapindex.xml.erb")))
|
43
|
+
sitemap = template.render(self)
|
44
|
+
|
45
|
+
outfile = File.join(app.build_dir, "sitemap.xml")
|
46
|
+
File.open(outfile, 'w') {|f| f.write(sitemap) }
|
47
|
+
|
48
|
+
@builder.say_status :create, "build/sitemap.xml"
|
49
|
+
|
50
|
+
return "build/sitemap.xml"
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_sitemap(name, pages)
|
54
|
+
@pages = pages
|
55
|
+
@hostname = options.hostname
|
56
|
+
template = Tilt::ERBTemplate.new(File.expand_path(File.join("#{File.dirname(__FILE__)}", "../../templates/sitemap.xml.erb")))
|
57
|
+
sitemap = template.render(self)
|
58
|
+
|
59
|
+
outfile = File.join(app.build_dir, name)
|
60
|
+
File.open(outfile, 'w') {|f| f.write(sitemap) }
|
61
|
+
|
62
|
+
@builder.say_status :create, "build/#{name}"
|
63
|
+
|
64
|
+
return "build/#{name}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def build_multiple_sitemaps(pages)
|
68
|
+
built_sitemaps = []
|
69
|
+
total_sitemaps = (pages.count / 50000.0).ceil
|
70
|
+
pages_per_sitemap = (50000.0 / total_sitemaps).ceil
|
71
|
+
built_sitemaps << build_sitemap_index(total_sitemaps)
|
72
|
+
1.upto(total_sitemaps) do |i|
|
73
|
+
sitemap_pages = pages[((i - 1) * pages_per_sitemap)...(i * pages_per_sitemap)]
|
74
|
+
built_sitemaps << build_sitemap("sitemap#{i}.xml", sitemap_pages)
|
75
|
+
end
|
76
|
+
|
77
|
+
return built_sitemaps
|
78
|
+
end
|
79
|
+
|
80
|
+
def gzip_file(sitemap)
|
81
|
+
require 'zlib'
|
82
|
+
File.open(File.join(@app.build_dir, "sitemap.xml.gz"), 'wb') do |f|
|
83
|
+
gz = Zlib::GzipWriter.new(f, Zlib::BEST_COMPRESSION)
|
84
|
+
gz.write sitemap
|
85
|
+
gz.close
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Returns a URL with proper HTML entities
|
90
|
+
def urlencode(url)
|
91
|
+
purl = URI.parse(url)
|
92
|
+
path_match = purl.path.match(/\/([^.]+)/)
|
93
|
+
if path_match
|
94
|
+
escaped_path = app.escape_html(path_match[1])
|
95
|
+
purl.path = "/#{escaped_path}.html"
|
96
|
+
end
|
97
|
+
return purl.to_s
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
data/middleman-sitemap.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-sitemap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Larry Staton Jr.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|
@@ -51053,6 +51053,7 @@ files:
|
|
51053
51053
|
- fixtures/weird-urls-app/source/stylesheets/test.css
|
51054
51054
|
- fixtures/weird-urls-app/source/this-&-that.html
|
51055
51055
|
- lib/middleman-sitemap.rb
|
51056
|
+
- lib/middleman-sitemap/extension.rb
|
51056
51057
|
- lib/middleman_extension.rb
|
51057
51058
|
- middleman-sitemap.gemspec
|
51058
51059
|
- templates/sitemap.xml.erb
|