jekyll-sitemap 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f288537895b8ef8244472fe563468be566d1553
4
- data.tar.gz: 13d121259146c8ee408b5d1357000f1991b4cd55
3
+ metadata.gz: f132cc4e250a79b3f479249b8d069d1f390bfd8a
4
+ data.tar.gz: d6762c431548f94b50bae4b3856ad1c83b8088fd
5
5
  SHA512:
6
- metadata.gz: 08b221f3b82a57229d71eeb1bbaaa73a8437de679a89170d794ba836d57766e2b5ff49b4219d61b7e3817923c702d01f607421ef098843e95de15714fd72ff66
7
- data.tar.gz: 66012f77eb83fa20d36c34198a3b1b75fc34fd8ee13e1ab12ad4c2c84dbda160f8fceaf3e8af5b457578be742cfa4e26bc069df55194dcc2e0dad28fec87ab6d
6
+ metadata.gz: e6120fae9a6609421b111f579c5e476d3cdf08417ab6e804d12633ed4cba5ca8f13b84fbb612359107bb659472234c89d88979fa2d869dc51e4315267e5a199d
7
+ data.tar.gz: d68e7445917f84a6c0f16d26cb259d74fd2b8158a05754c8214d826df5e5b24eb7abc22817aa831ca7e591ba29867ebf58930b978de285f7a04da7b71277b292
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ inherit_gem:
2
+ jekyll: .rubocop.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 1.9
6
+ Include:
7
+ - lib/*.rb
8
+
9
+ Exclude:
10
+ - script/**/*
11
+ - spec/**/*
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  sudo: false
2
2
  language: ruby
3
+ cache: bundler
3
4
  rvm:
4
5
  - 2.0
5
6
  - 2.1
data/History.markdown CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.11.0 / 2016-07-08
2
+
3
+ * Add Rubocop (#100)
4
+ * Allow Travis to cache dependencies (#108)
5
+ * Properly Escape URLs (#107)
6
+ * Include PDF files in sitemap (#109)
7
+
1
8
  ## 0.10.0 / 2016-01-05
2
9
 
3
10
  * URI encode sitemap URLs (#85)
@@ -20,23 +27,16 @@
20
27
  * Call each page `page` in pages loop in `sitemap.xml` for clarity (#64)
21
28
  * Remove `changefreq` (#34)
22
29
  * Remove `priority` (#33)
23
- * Don't strip 'index.html' when there is more to filename (#68)
30
+ * Don't strip 'index.html' when there is more to filename ## Minor Enhancements (#68)
24
31
 
25
32
  ## 0.7.0 / 2014-12-07
26
33
 
27
- ## Minor Enhancements
28
-
29
34
  * Make `site.baseurl` support more robust (#59)
30
- * Add `site.baseurl` to base site URL construction (#50)
31
-
32
- ## Development Fixes
33
-
34
- * Remove unnecessary spaces and escaping in README (#58)
35
+ * Add `site.baseurl` to base site URL construction ## Development Fixes (#50)
36
+ * Remove unnecessary spaces and escaping in README ## Bug Fixes (#58)
35
37
 
36
38
  ## 0.6.3 / 2014-11-11
37
39
 
38
- ## Bug Fixes
39
-
40
40
  * Be backwards-compatible when `Site#in_source_dir` and `Site#in_dest_dir` don't exist (#57)
41
41
 
42
42
  ## 0.6.2 / 2014-11-08
@@ -84,10 +84,7 @@
84
84
  ### Bug Fixes
85
85
 
86
86
  * Force sitemap layout to be `nil` (#16)
87
- * Correct seconds in timestamp for static files (#24)
88
-
89
- # Development Fixes
90
-
87
+ * Correct seconds in timestamp for static files # Development Fixes (#24)
91
88
  * Upgrade to Rspec 3.0 and use `be_truthy` (#24)
92
89
 
93
90
  ## 0.4.0 / 2014-05-06
@@ -3,7 +3,7 @@
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "jekyll-sitemap"
5
5
  spec.summary = "Automatically generate a sitemap.xml for your Jekyll site."
6
- spec.version = "0.10.0"
6
+ spec.version = "0.11.0"
7
7
  spec.authors = ["GitHub, Inc."]
8
8
  spec.email = "support@github.com"
9
9
  spec.homepage = "https://github.com/jekyll/jekyll-sitemap"
@@ -14,9 +14,12 @@ Gem::Specification.new do |spec|
14
14
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
15
  spec.require_paths = ["lib"]
16
16
 
17
+ spec.add_runtime_dependency "addressable", "~>2.4.0"
18
+
17
19
  spec.add_development_dependency "jekyll", ">= 2.0"
18
20
  spec.add_development_dependency "jekyll-last-modified-at", "0.3.4"
19
21
  spec.add_development_dependency "rspec", "~> 3.0"
20
22
  spec.add_development_dependency "rake"
21
23
  spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rubocop"
22
25
  end
@@ -1,74 +1,3 @@
1
- require 'fileutils'
2
-
3
- module Jekyll
4
- class PageWithoutAFile < Page
5
- def read_yaml(*)
6
- @data ||= {}
7
- end
8
- end
9
-
10
- class JekyllSitemap < Jekyll::Generator
11
- safe true
12
- priority :lowest
13
-
14
- # Main plugin action, called by Jekyll-core
15
- def generate(site)
16
- @site = site
17
- @site.config["time"] = Time.new
18
- @site.config["html_files"] = html_files.map(&:to_liquid)
19
- unless sitemap_exists?
20
- write
21
- @site.keep_files ||= []
22
- @site.keep_files << "sitemap.xml"
23
- end
24
- end
25
-
26
- HTML_EXTENSIONS = %W(
27
- .html
28
- .xhtml
29
- .htm
30
- )
31
-
32
- # Array of all non-jekyll site files with an HTML extension
33
- def html_files
34
- @site.static_files.select { |file| HTML_EXTENSIONS.include? file.extname }
35
- end
36
-
37
- # Path to sitemap.xml template file
38
- def source_path
39
- File.expand_path "sitemap.xml", File.dirname(__FILE__)
40
- end
41
-
42
- # Destination for sitemap.xml file within the site source directory
43
- def destination_path
44
- if @site.respond_to?(:in_dest_dir)
45
- @site.in_dest_dir("sitemap.xml")
46
- else
47
- Jekyll.sanitized_path(@site.dest, "sitemap.xml")
48
- end
49
- end
50
-
51
- # copy sitemap template from source to destination
52
- def write
53
- FileUtils.mkdir_p File.dirname(destination_path)
54
- File.open(destination_path, 'w') { |f| f.write(sitemap_content) }
55
- end
56
-
57
- def sitemap_content
58
- site_map = PageWithoutAFile.new(@site, File.dirname(__FILE__), "", "sitemap.xml")
59
- site_map.content = File.read(source_path)
60
- site_map.data["layout"] = nil
61
- site_map.render({}, @site.site_payload)
62
- site_map.output.gsub(/\s{2,}/, "\n")
63
- end
64
-
65
- # Checks if a sitemap already exists in the site source
66
- def sitemap_exists?
67
- if @site.respond_to?(:in_source_dir)
68
- File.exists? @site.in_source_dir("sitemap.xml")
69
- else
70
- File.exists? Jekyll.sanitized_path(@site.source, "sitemap.xml")
71
- end
72
- end
73
- end
74
- end
1
+ require 'jekyll/sitemap_filters'
2
+ require 'jekyll/page_without_a_file'
3
+ require 'jekyll/jekyll-sitemap'
@@ -0,0 +1,69 @@
1
+ require 'fileutils'
2
+
3
+ module Jekyll
4
+ class JekyllSitemap < Jekyll::Generator
5
+ safe true
6
+ priority :lowest
7
+
8
+ # Main plugin action, called by Jekyll-core
9
+ def generate(site)
10
+ @site = site
11
+ @site.config["time"] = Time.new
12
+ unless sitemap_exists?
13
+ write
14
+ @site.keep_files ||= []
15
+ @site.keep_files << "sitemap.xml"
16
+ end
17
+ end
18
+
19
+ INCLUDED_EXTENSIONS = %W(
20
+ .htm
21
+ .html
22
+ .xhtml
23
+ .pdf
24
+ ).freeze
25
+
26
+ # Array of all non-jekyll site files with an HTML extension
27
+ def static_files
28
+ @site.static_files.select { |file| INCLUDED_EXTENSIONS.include? file.extname }
29
+ end
30
+
31
+ # Path to sitemap.xml template file
32
+ def source_path
33
+ File.expand_path "../sitemap.xml", File.dirname(__FILE__)
34
+ end
35
+
36
+ # Destination for sitemap.xml file within the site source directory
37
+ def destination_path
38
+ if @site.respond_to?(:in_dest_dir)
39
+ @site.in_dest_dir("sitemap.xml")
40
+ else
41
+ Jekyll.sanitized_path(@site.dest, "sitemap.xml")
42
+ end
43
+ end
44
+
45
+ # copy sitemap template from source to destination
46
+ def write
47
+ FileUtils.mkdir_p File.dirname(destination_path)
48
+ File.open(destination_path, 'w') { |f| f.write(sitemap_content) }
49
+ end
50
+
51
+ def sitemap_content
52
+ site_map = PageWithoutAFile.new(@site, File.dirname(__FILE__), "", "sitemap.xml")
53
+ site_map.content = File.read(source_path)
54
+ site_map.data["layout"] = nil
55
+ site_map.data["static_files"] = static_files.map(&:to_liquid)
56
+ site_map.render({}, @site.site_payload)
57
+ site_map.output.gsub(/\s{2,}/, "\n")
58
+ end
59
+
60
+ # Checks if a sitemap already exists in the site source
61
+ def sitemap_exists?
62
+ if @site.respond_to?(:in_source_dir)
63
+ File.exist? @site.in_source_dir("sitemap.xml")
64
+ else
65
+ File.exist? Jekyll.sanitized_path(@site.source, "sitemap.xml")
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,7 @@
1
+ module Jekyll
2
+ class PageWithoutAFile < Page
3
+ def read_yaml(*)
4
+ @data ||= {}
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'addressable/uri'
2
+
3
+ module Jekyll
4
+ module SitemapFilters
5
+ def normalize_url(input)
6
+ Addressable::URI.parse(input).normalize.to_s
7
+ end
8
+ end
9
+ end
10
+ Liquid::Template.register_filter(Jekyll::SitemapFilters)
data/lib/sitemap.xml CHANGED
@@ -3,7 +3,7 @@
3
3
  {% capture site_url %}{% if site.url %}{{ site.url | append: site.baseurl }}{% else %}{{ site.github.url }}{% endif %}{% endcapture %}
4
4
  {% for post in site.posts %}{% unless post.sitemap == false %}
5
5
  <url>
6
- <loc>{{ post.url | prepend: site_url | uri_escape }}</loc>
6
+ <loc>{{ post.url | prepend: site_url | normalize_url }}</loc>
7
7
  {% if post.last_modified_at %}
8
8
  <lastmod>{{ post.last_modified_at | date_to_xmlschema }}</lastmod>
9
9
  {% else %}
@@ -13,7 +13,7 @@
13
13
  {% endunless %}{% endfor %}
14
14
  {% for page in site.html_pages %}{% unless page.sitemap == false %}
15
15
  <url>
16
- <loc>{{ page.url | replace:'/index.html','/' | prepend: site_url | uri_escape }}</loc>
16
+ <loc>{{ page.url | replace:'/index.html','/' | prepend: site_url | normalize_url }}</loc>
17
17
  {% if page.last_modified_at %}
18
18
  <lastmod>{{ page.last_modified_at | date_to_xmlschema }}</lastmod>
19
19
  {% endif %}
@@ -22,7 +22,7 @@
22
22
  {% for collection in site.collections %}{% unless collection.last.output == false or collection.output == false or collection.label == 'posts' %}
23
23
  {% for doc in collection.last.docs %}{% unless doc.sitemap == false %}
24
24
  <url>
25
- <loc>{{ doc.url | replace:'/index.html','/' | prepend: site_url | uri_escape }}</loc>
25
+ <loc>{{ doc.url | replace:'/index.html','/' | prepend: site_url | normalize_url }}</loc>
26
26
  {% if doc.last_modified_at %}
27
27
  <lastmod>{{ doc.last_modified_at | date_to_xmlschema }}</lastmod>
28
28
  {% endif %}
@@ -30,16 +30,16 @@
30
30
  {% endunless %}{% endfor %}
31
31
  {% for doc in collection.docs %}{% unless doc.sitemap == false %}
32
32
  <url>
33
- <loc>{{ doc.url | replace:'/index.html','/' | prepend: site_url | uri_escape }}</loc>
33
+ <loc>{{ doc.url | replace:'/index.html','/' | prepend: site_url | normalize_url }}</loc>
34
34
  {% if doc.last_modified_at %}
35
35
  <lastmod>{{ doc.last_modified_at | date_to_xmlschema }}</lastmod>
36
36
  {% endif %}
37
37
  </url>
38
38
  {% endunless %}{% endfor %}
39
39
  {% endunless %}{% endfor %}
40
- {% for file in site.html_files %}
40
+ {% for file in page.static_files %}
41
41
  <url>
42
- <loc>{{ file.path | prepend: site_url | uri_escape }}</loc>
42
+ <loc>{{ file.path | prepend: site_url | normalize_url }}</loc>
43
43
  <lastmod>{{ file.modified_time | date_to_xmlschema }}</lastmod>
44
44
  </url>
45
45
  {% endfor %}
data/script/cibuild CHANGED
@@ -3,3 +3,6 @@ set -e
3
3
 
4
4
  bundle exec rspec
5
5
  bundle exec rspec spec/test_jekyll-last-modified-at.rb
6
+ if [ "$JEKYLL_VERSION" = "3.0" ]; then
7
+ bundle exec rubocop -S -D
8
+ fi
@@ -0,0 +1,3 @@
1
+ ---
2
+ permalink: "/2016/04/02/错误.html"
3
+ ---
@@ -0,0 +1,3 @@
1
+ ---
2
+ permalink: "/2016/04/03/%E9%94%99%E8%AF%AF.html"
3
+ ---
File without changes
@@ -93,6 +93,10 @@ describe(Jekyll::JekyllSitemap) do
93
93
  expect(contents).to match /\/some-subfolder\/htm\.htm/
94
94
  end
95
95
 
96
+ it "does include assets or any static files with .pdf extension" do
97
+ expect(contents).to match %r!/static_files/test.pdf!
98
+ end
99
+
96
100
  it "does not include posts that have set 'sitemap: false'" do
97
101
  expect(contents).not_to match /\/exclude-this-post\.html<\/loc>/
98
102
  end
@@ -106,7 +110,7 @@ describe(Jekyll::JekyllSitemap) do
106
110
  end
107
111
 
108
112
  it "includes the correct number of items" do
109
- expect(contents.scan(/(?=<url>)/).count).to eql 15
113
+ expect(contents.scan(/(?=<url>)/).count).to eql 19
110
114
  end
111
115
 
112
116
  context "with a baseurl" do
@@ -134,18 +138,21 @@ describe(Jekyll::JekyllSitemap) do
134
138
  end
135
139
  end
136
140
 
137
- context "with site url that needs URI encoding" do
141
+ context "with urls that needs URI encoding" do
138
142
  let(:config) do
139
- Jekyll.configuration(Jekyll::Utils.deep_merge_hashes(overrides, {"url" => "http://has ümlaut.org"}))
143
+ Jekyll.configuration(Jekyll::Utils.deep_merge_hashes(overrides, {"url" => "http://ümlaut.example.org"}))
140
144
  end
141
145
 
142
146
  it "performs URI encoding of site url" do
143
- expect(contents).to match /<loc>http:\/\/has%20%C3%BCmlaut\.org\/<\/loc>/
144
- expect(contents).to match /<loc>http:\/\/has%20%C3%BCmlaut\.org\/some-subfolder\/this-is-a-subpage\.html<\/loc>/
145
- expect(contents).to match /<loc>http:\/\/has%20%C3%BCmlaut\.org\/2014\/03\/04\/march-the-fourth\.html<\/loc>/
147
+ expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/</loc>!
148
+ expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/some-subfolder/this-is-a-subpage.html</loc>!
149
+ expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/2014/03/04/march-the-fourth.html</loc>!
150
+ expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/2016/04/01/%E9%94%99%E8%AF%AF.html</loc>!
151
+ expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/2016/04/02/%E9%94%99%E8%AF%AF.html</loc>!
152
+ expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/2016/04/03/%E9%94%99%E8%AF%AF.html</loc>!
146
153
  end
147
154
 
148
- it "does not double-escape site url" do
155
+ it "does not double-escape urls" do
149
156
  expect(contents).to_not match /%25/
150
157
  end
151
158
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-sitemap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-25 00:00:00.000000000 Z
11
+ date: 2016-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: addressable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.4.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.4.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: jekyll
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: '1.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description:
84
112
  email: support@github.com
85
113
  executables: []
@@ -88,6 +116,7 @@ extra_rdoc_files: []
88
116
  files:
89
117
  - ".gitignore"
90
118
  - ".rspec"
119
+ - ".rubocop.yml"
91
120
  - ".travis.yml"
92
121
  - Gemfile
93
122
  - History.markdown
@@ -96,6 +125,9 @@ files:
96
125
  - Rakefile
97
126
  - jekyll-sitemap.gemspec
98
127
  - lib/jekyll-sitemap.rb
128
+ - lib/jekyll/jekyll-sitemap.rb
129
+ - lib/jekyll/page_without_a_file.rb
130
+ - lib/jekyll/sitemap_filters.rb
99
131
  - lib/sitemap.xml
100
132
  - script/bootstrap
101
133
  - script/cibuild
@@ -113,6 +145,9 @@ files:
113
145
  - spec/fixtures/_posts/2014-03-04-march-the-fourth.md
114
146
  - spec/fixtures/_posts/2014-05-11-exclude-this-post.md
115
147
  - spec/fixtures/_posts/2015-01-18-jekyll-last-modified-at.md
148
+ - spec/fixtures/_posts/2016-04-01-错误.html
149
+ - spec/fixtures/_posts/2016-04-02-错误.html
150
+ - spec/fixtures/_posts/2016-04-03-错误.html
116
151
  - spec/fixtures/feeds/atom.xml
117
152
  - spec/fixtures/images/hubot.png
118
153
  - spec/fixtures/index.html
@@ -123,6 +158,7 @@ files:
123
158
  - spec/fixtures/some-subfolder/this-is-a-subfile.html
124
159
  - spec/fixtures/some-subfolder/this-is-a-subpage.html
125
160
  - spec/fixtures/some-subfolder/xhtml.xhtml
161
+ - spec/fixtures/static_files/test.pdf
126
162
  - spec/jekyll-sitemap_spec.rb
127
163
  - spec/spec_helper.rb
128
164
  - spec/test_jekyll-last-modified-at.rb
@@ -146,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
182
  version: '0'
147
183
  requirements: []
148
184
  rubyforge_project:
149
- rubygems_version: 2.5.1
185
+ rubygems_version: 2.4.8
150
186
  signing_key:
151
187
  specification_version: 4
152
188
  summary: Automatically generate a sitemap.xml for your Jekyll site.
@@ -163,6 +199,9 @@ test_files:
163
199
  - spec/fixtures/_posts/2014-03-04-march-the-fourth.md
164
200
  - spec/fixtures/_posts/2014-05-11-exclude-this-post.md
165
201
  - spec/fixtures/_posts/2015-01-18-jekyll-last-modified-at.md
202
+ - spec/fixtures/_posts/2016-04-01-错误.html
203
+ - spec/fixtures/_posts/2016-04-02-错误.html
204
+ - spec/fixtures/_posts/2016-04-03-错误.html
166
205
  - spec/fixtures/feeds/atom.xml
167
206
  - spec/fixtures/images/hubot.png
168
207
  - spec/fixtures/index.html
@@ -173,6 +212,7 @@ test_files:
173
212
  - spec/fixtures/some-subfolder/this-is-a-subfile.html
174
213
  - spec/fixtures/some-subfolder/this-is-a-subpage.html
175
214
  - spec/fixtures/some-subfolder/xhtml.xhtml
215
+ - spec/fixtures/static_files/test.pdf
176
216
  - spec/jekyll-sitemap_spec.rb
177
217
  - spec/spec_helper.rb
178
218
  - spec/test_jekyll-last-modified-at.rb