jekyll-sitemap 0.12.0 → 0.13.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: c389f3b3fb31f59c71861d1db7fb3ead58b6cd55
4
- data.tar.gz: 71d6f86a78f5b2f403ac9119953af38eb05bc8bf
3
+ metadata.gz: 545a5dae100fc813cfc730407cc0d3bf3656d008
4
+ data.tar.gz: 5840efbad8ffbe12ec88479e5b9ba9517055618b
5
5
  SHA512:
6
- metadata.gz: 3cedbd8b869f0905b9b6cf6b8a8fe2961b4b2e7191d44cd68539c7d4742a38d75f689cc19007d8cdc548c6c19bc9b9579bdbcfc049756541f7948dee6b046fc2
7
- data.tar.gz: 3d9c5ce959997df32df9ccaadd28a3be44dca64cd4c0f3f06b99589f83c0265572e6ed3af161b8ab0b0413eeaebece48f5c7311bae8e9220b25b6d849aacbfca
6
+ metadata.gz: 6ea2addd12b55152f253503281d60b7453969b7133cc680dffdd471aa80cde89c1782f3cb704707bddb9bd71830249d39616a7ffa4c0c574435ec0d68d456431
7
+ data.tar.gz: ed2f2f20b26e9445347b3c729b60096930862a33034e6314a30c0323d66a0f716eb94d164c0f518cee54a1c76e451d008815252eeafa11311bd3978000ca6735
data/.rubocop.yml CHANGED
@@ -2,7 +2,7 @@ inherit_gem:
2
2
  jekyll: .rubocop.yml
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 1.9
5
+ TargetRubyVersion: 2.0
6
6
  Include:
7
7
  - lib/*.rb
8
8
 
data/.travis.yml CHANGED
@@ -7,15 +7,16 @@ rvm:
7
7
  - 2.2
8
8
  matrix:
9
9
  include:
10
- - # GitHub Pages
11
- rvm: 2.3.1
12
- env: JEKYLL_VERSION=3.3.0
10
+ - rvm: 2.3.1
11
+ env: JEKYLL_VERSION=3.3.0
13
12
  env:
14
13
  matrix:
15
- - JEKYLL_VERSION=3.3
14
+ - JEKYLL_VERSION=3.3
16
15
  branches:
17
16
  only:
18
- - master
17
+ - master
18
+ git:
19
+ depth: 1000
19
20
  install:
20
21
  - travis_retry script/bootstrap
21
22
  script: script/cibuild
@@ -26,7 +27,15 @@ notifications:
26
27
  channels:
27
28
  - irc.freenode.org#jekyll
28
29
  template:
29
- - '%{repository}#%{build_number} %{message} %{build_url}'
30
+ - "%{repository}#%{build_number} %{message} %{build_url}"
30
31
  email:
31
32
  on_success: never
32
33
  on_failure: change
34
+ deploy:
35
+ provider: rubygems
36
+ api_key:
37
+ secure: O8fGRnM6OJCqC2BlVE1BqYfq5aR19ulpiHhQwRiHbtSCh8H4rYt7FLsuOwSTtRQjhWYRRSpdRt2ilfQ6PY6Jx1UkxZq5zo9QAPQ9tKxiFTm7gBpZAiAgb06eyaMBSzyQ8qe2qccaFI6CiZhsiaGMsdKsWuYpuoPmdLPd7aDyYJs=
38
+ gem: jekyll-sitemap
39
+ on:
40
+ tags: true
41
+ repo: jekyll/jekyll-sitemap
data/History.markdown CHANGED
@@ -1,3 +1,22 @@
1
+ ## 0.13.0 / 2017-01-05
2
+
3
+ ### Minor Enhancements
4
+
5
+ * Add sitemap.xsl if exists (#143)
6
+ * Add robots.txt when none exists (#146)
7
+ * Refactor and add sitemap to `site.pages` (#137)
8
+ * DRY in sitemap.xml (#136)
9
+
10
+ ### Documentation
11
+
12
+ * Fix #134: Rename "Issues" to "Known Issues" (#135)
13
+ * Fix #104: Add explanation in README for <lastmod> tag (#139)
14
+ * Update copyright attribution (#149)
15
+
16
+ ### Development Fixes
17
+
18
+ * Travis should do a deep clone (#147)
19
+
1
20
  ## 0.12.0 / 2016-10-06
2
21
 
3
22
  ### Minor Enhancements
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014 GitHub, inc.
3
+ Copyright (c) 2014-2017, GitHub, inc. and the jekyll-sitemap contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -22,6 +22,17 @@ those other gems if you *want* the sitemap to include the generated
22
22
  content, or *before* those other gems if you *don't want* the sitemap to
23
23
  include the generated content from the gems. (Programming is *hard*.)
24
24
 
25
+ Because the sitemap is added to `site.pages`, you may have to modify any
26
+ templates that iterate through all pages (for example, to build a menu of
27
+ all of the site's content).
28
+
29
+ ## `<lastmod>` tag
30
+ The `<lastmod>` tag in the `sitemap.xml` will reflect by priority:
31
+
32
+ 1. The modified date of the file as reported by the filesystem if you have `jekyll-last-modified-at` plugin installed (not compatible with Github Pages auto building)
33
+ 2. A personnalised date if you add the variable `last_modified_at:` with a date in the Front Matter
34
+ 3. The creation date of your post (correspondig to the `post.date` variable)
35
+
25
36
  ## Exclusions
26
37
 
27
38
  If you would like to exclude specific pages/posts from the sitemap set the
@@ -42,14 +53,14 @@ Use `script/console` to load a local IRB console with the Gem.
42
53
  1. `script/bootstrap`
43
54
  2. `script/cibuild`
44
55
 
56
+ ## Known Issues
57
+
58
+ 1. If the `sitemap.xml` doesn't generate in the `_site` folder, ensure `_config.yml` doesn't have `safe: true`. That prevents all plugins from working.
59
+ 2. If the `sitemap.xml` doesn't generate in the `_site` folder, ensure that you don't have a sitemap generator plugin in your `_plugin` folder.
60
+
45
61
  ## Contributing
46
62
 
47
63
  1. Fork the project
48
64
  2. Create a descriptively named feature branch
49
65
  3. Add your feature
50
66
  4. Submit a pull request
51
-
52
- ## Issues
53
-
54
- 1. If the `sitemap.xml` doesn't generate in the `_site` folder, ensure `_config.yml` doesn't have `safe: true`. That prevents all plugins from working.
55
- 2. If the `sitemap.xml` doesn't generate in the `_site` folder, ensure that you don't have a sitemap generator plugin in your `_plugin` folder.
@@ -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.12.0"
6
+ spec.version = "0.13.0"
7
7
  spec.authors = ["GitHub, Inc."]
8
8
  spec.email = "support@github.com"
9
9
  spec.homepage = "https://github.com/jekyll/jekyll-sitemap"
@@ -8,13 +8,12 @@ module Jekyll
8
8
  # Main plugin action, called by Jekyll-core
9
9
  def generate(site)
10
10
  @site = site
11
- unless sitemap_exists?
12
- write
13
- @site.keep_files ||= []
14
- @site.keep_files << "sitemap.xml"
15
- end
11
+ @site.pages << sitemap unless file_exists?("sitemap.xml")
12
+ @site.pages << robots unless file_exists?("robots.txt")
16
13
  end
17
14
 
15
+ private
16
+
18
17
  INCLUDED_EXTENSIONS = %W(
19
18
  .htm
20
19
  .html
@@ -22,46 +21,49 @@ module Jekyll
22
21
  .pdf
23
22
  ).freeze
24
23
 
24
+ # Matches all whitespace that follows
25
+ # 1. A '>' followed by a newline or
26
+ # 2. A '}' which closes a Liquid tag
27
+ # We will strip all of this whitespace to minify the template
28
+ MINIFY_REGEX = %r!(?<=>\n|})\s+!
29
+
25
30
  # Array of all non-jekyll site files with an HTML extension
26
31
  def static_files
27
32
  @site.static_files.select { |file| INCLUDED_EXTENSIONS.include? file.extname }
28
33
  end
29
34
 
30
35
  # Path to sitemap.xml template file
31
- def source_path
32
- File.expand_path "../sitemap.xml", File.dirname(__FILE__)
36
+ def source_path(file = "sitemap.xml")
37
+ File.expand_path "../#{file}", File.dirname(__FILE__)
33
38
  end
34
39
 
35
40
  # Destination for sitemap.xml file within the site source directory
36
- def destination_path
37
- if @site.respond_to?(:in_dest_dir)
38
- @site.in_dest_dir("sitemap.xml")
39
- else
40
- Jekyll.sanitized_path(@site.dest, "sitemap.xml")
41
- end
41
+ def destination_path(file = "sitemap.xml")
42
+ @site.in_dest_dir(file)
42
43
  end
43
44
 
44
- # copy sitemap template from source to destination
45
- def write
46
- FileUtils.mkdir_p File.dirname(destination_path)
47
- File.open(destination_path, "w") { |f| f.write(sitemap_content) }
48
- end
49
-
50
- def sitemap_content
45
+ def sitemap
51
46
  site_map = PageWithoutAFile.new(@site, File.dirname(__FILE__), "", "sitemap.xml")
52
- site_map.content = File.read(source_path)
47
+ site_map.content = File.read(source_path).gsub(MINIFY_REGEX, "")
53
48
  site_map.data["layout"] = nil
54
49
  site_map.data["static_files"] = static_files.map(&:to_liquid)
55
- site_map.render({}, @site.site_payload)
56
- site_map.output.gsub(%r!\s{2,}!, "\n")
50
+ site_map.data["xsl"] = file_exists?("sitemap.xsl")
51
+ site_map
52
+ end
53
+
54
+ def robots
55
+ robots = PageWithoutAFile.new(@site, File.dirname(__FILE__), "", "robots.txt")
56
+ robots.content = File.read(source_path("robots.txt"))
57
+ robots.data["layout"] = nil
58
+ robots
57
59
  end
58
60
 
59
- # Checks if a sitemap already exists in the site source
60
- def sitemap_exists?
61
+ # Checks if a file already exists in the site source
62
+ def file_exists?(file_path)
61
63
  if @site.respond_to?(:in_source_dir)
62
- File.exist? @site.in_source_dir("sitemap.xml")
64
+ File.exist? @site.in_source_dir(file_path)
63
65
  else
64
- File.exist? Jekyll.sanitized_path(@site.source, "sitemap.xml")
66
+ File.exist? Jekyll.sanitized_path(@site.source, file_path)
65
67
  end
66
68
  end
67
69
  end
data/lib/robots.txt ADDED
@@ -0,0 +1 @@
1
+ Sitemap: {{ "sitemap.xml" | absolute_url }}
data/lib/sitemap.xml CHANGED
@@ -1,41 +1,35 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
+ {% if page.xsl %}
3
+ <?xml-stylesheet type="text/xsl" href="{{ "/sitemap.xsl" | absolute_url }}"?>
4
+ {% endif %}
2
5
  <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3
- {% for post in site.posts %}{% unless post.sitemap == false %}
4
- <url>
5
- <loc>{{ post.url | absolute_url }}</loc>
6
- <lastmod>{{ post.last_modified_at | default: post.date | date_to_xmlschema }}</lastmod>
7
- </url>
8
- {% endunless %}{% endfor %}
9
- {% for page in site.html_pages %}{% unless page.sitemap == false %}
10
- <url>
11
- <loc>{{ page.url | replace:'/index.html','/' | absolute_url }}</loc>
12
- {% if page.last_modified_at %}
13
- <lastmod>{{ page.last_modified_at | date_to_xmlschema }}</lastmod>
14
- {% endif %}
15
- </url>
16
- {% endunless %}{% endfor %}
17
- {% for collection in site.collections %}{% unless collection.last.output == false or collection.output == false or collection.label == 'posts' %}
18
- {% for doc in collection.last.docs %}{% unless doc.sitemap == false %}
19
- <url>
20
- <loc>{{ doc.url | replace:'/index.html','/' | absolute_url }}</loc>
21
- {% if doc.last_modified_at %}
22
- <lastmod>{{ doc.last_modified_at | date_to_xmlschema }}</lastmod>
23
- {% endif %}
24
- </url>
25
- {% endunless %}{% endfor %}
26
- {% for doc in collection.docs %}{% unless doc.sitemap == false %}
6
+ {% assign collections = site.collections | where_exp:'collection','collection.output != false' %}
7
+ {% for collection in collections %}
8
+ {% assign docs = collection.docs | where_exp:'doc','doc.sitemap != false' %}
9
+ {% for doc in docs %}
10
+ <url>
11
+ <loc>{{ doc.url | replace:'/index.html','/' | absolute_url }}</loc>
12
+ {% if doc.last_modified_at or doc.date %}
13
+ <lastmod>{{ doc.last_modified_at | default: doc.date | date_to_xmlschema }}</lastmod>
14
+ {% endif %}
15
+ </url>
16
+ {% endfor %}
17
+ {% endfor %}
18
+
19
+ {% assign pages = site.html_pages | where_exp:'doc','doc.sitemap != false' %}
20
+ {% for page in pages %}
27
21
  <url>
28
- <loc>{{ doc.url | replace:'/index.html','/' | absolute_url }}</loc>
29
- {% if doc.last_modified_at %}
30
- <lastmod>{{ doc.last_modified_at | date_to_xmlschema }}</lastmod>
22
+ <loc>{{ page.url | replace:'/index.html','/' | absolute_url }}</loc>
23
+ {% if page.last_modified_at %}
24
+ <lastmod>{{ page.last_modified_at | date_to_xmlschema }}</lastmod>
31
25
  {% endif %}
32
26
  </url>
33
- {% endunless %}{% endfor %}
34
- {% endunless %}{% endfor %}
27
+ {% endfor %}
28
+
35
29
  {% for file in page.static_files %}
36
- <url>
37
- <loc>{{ file.path | absolute_url }}</loc>
38
- <lastmod>{{ file.modified_time | date_to_xmlschema }}</lastmod>
39
- </url>
30
+ <url>
31
+ <loc>{{ file.path | absolute_url }}</loc>
32
+ <lastmod>{{ file.modified_time | date_to_xmlschema }}</lastmod>
33
+ </url>
40
34
  {% endfor %}
41
35
  </urlset>
@@ -136,6 +136,11 @@ describe(Jekyll::JekyllSitemap) do
136
136
  expect(contents).to match /<loc>http:\/\/example\.org\/bass\/2014\/03\/02\/march-the-second\.html<\/loc>/
137
137
  expect(contents).to match /<loc>http:\/\/example\.org\/bass\/2013\/12\/12\/dec-the-second\.html<\/loc>/
138
138
  end
139
+
140
+ it "adds baseurl to robots.txt" do
141
+ content = File.read(dest_dir("robots.txt"))
142
+ expect(content).to match("Sitemap: http://example.org/bass/sitemap.xml")
143
+ end
139
144
  end
140
145
 
141
146
  context "with urls that needs URI encoding" do
@@ -155,5 +160,21 @@ describe(Jekyll::JekyllSitemap) do
155
160
  it "does not double-escape urls" do
156
161
  expect(contents).to_not match /%25/
157
162
  end
163
+
164
+ context "readme" do
165
+ let(:contents) { File.read(dest_dir("robots.txt")) }
166
+
167
+ it "has no layout" do
168
+ expect(contents).not_to match(/\ATHIS IS MY LAYOUT/)
169
+ end
170
+
171
+ it "creates a sitemap.xml file" do
172
+ expect(File.exist?(dest_dir("robots.txt"))).to be_truthy
173
+ end
174
+
175
+ it "renders liquid" do
176
+ expect(contents).to match("Sitemap: http://xn--mlaut-jva.example.org/sitemap.xml")
177
+ end
178
+ end
158
179
  end
159
180
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-sitemap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.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-10-06 00:00:00.000000000 Z
11
+ date: 2017-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -113,6 +113,7 @@ files:
113
113
  - lib/jekyll-sitemap.rb
114
114
  - lib/jekyll/jekyll-sitemap.rb
115
115
  - lib/jekyll/page_without_a_file.rb
116
+ - lib/robots.txt
116
117
  - lib/sitemap.xml
117
118
  - script/bootstrap
118
119
  - script/cibuild
@@ -167,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
168
  version: '0'
168
169
  requirements: []
169
170
  rubyforge_project:
170
- rubygems_version: 2.6.7
171
+ rubygems_version: 2.6.8
171
172
  signing_key:
172
173
  specification_version: 4
173
174
  summary: Automatically generate a sitemap.xml for your Jekyll site.