bunto-sitemap 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +11 -0
  5. data/.travis.yml +34 -0
  6. data/Gemfile +6 -0
  7. data/History.markdown +4 -0
  8. data/LICENSE.md +21 -0
  9. data/README.md +55 -0
  10. data/Rakefile +6 -0
  11. data/bunto-sitemap.gemspec +23 -0
  12. data/lib/bunto-sitemap.rb +74 -0
  13. data/lib/sitemap.xml +46 -0
  14. data/script/bootstrap +3 -0
  15. data/script/cibuild +8 -0
  16. data/script/console +34 -0
  17. data/script/release +7 -0
  18. data/spec/bunto-sitemap_spec.rb +152 -0
  19. data/spec/fixtures/_config.yml +9 -0
  20. data/spec/fixtures/_layouts/some_default.html +4 -0
  21. data/spec/fixtures/_my_collection/custom_permalink.md +5 -0
  22. data/spec/fixtures/_my_collection/custom_permalink_2.md +5 -0
  23. data/spec/fixtures/_my_collection/test.html +4 -0
  24. data/spec/fixtures/_my_collection/this-has-non-standard-chars.md +5 -0
  25. data/spec/fixtures/_other_things/test2.html +4 -0
  26. data/spec/fixtures/_posts/2015-12-12-dec-the-second.md +4 -0
  27. data/spec/fixtures/_posts/2016-01-18-jekyll-last-modified-at.md +4 -0
  28. data/spec/fixtures/_posts/2016-03-02-march-the-second.md +4 -0
  29. data/spec/fixtures/_posts/2016-03-04-march-the-fourth.md +4 -0
  30. data/spec/fixtures/_posts/2016-05-11-exclude-this-post.md +5 -0
  31. data/spec/fixtures/bunto-last-modified-at/page.html +4 -0
  32. data/spec/fixtures/feeds/atom.xml +6 -0
  33. data/spec/fixtures/images/hubot.png +0 -0
  34. data/spec/fixtures/index.html +4 -0
  35. data/spec/fixtures/some-subfolder/exclude-this-page.html +5 -0
  36. data/spec/fixtures/some-subfolder/htm.htm +1 -0
  37. data/spec/fixtures/some-subfolder/test_index.html +4 -0
  38. data/spec/fixtures/some-subfolder/this-is-a-subfile.html +1 -0
  39. data/spec/fixtures/some-subfolder/this-is-a-subpage.html +4 -0
  40. data/spec/fixtures/some-subfolder/xhtml.xhtml +1 -0
  41. data/spec/spec_helper.rb +21 -0
  42. data/spec/test_bunto-last-modified-at.rb +34 -0
  43. metadata +193 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 57bbd4f8145f3089712f7072bfd66b66a0a82db6
4
+ data.tar.gz: d86d007a861fb0b46d37d9abf28e4bcad2a46f35
5
+ SHA512:
6
+ metadata.gz: eb1f728fa1ebe4d4e0830911e359f89600ffadb56605badc5bee8dcc55ef03aef385f6d077cef53a1661449d302ca39983a28bb51785a9ccbbefca33cc322c72
7
+ data.tar.gz: c139abf79bed207f9422544fd932af0475370bff882064dc4cff307037bac11c8c2939bd15b6557e96968fa993a01e8366882d92e6faf18d504a9c4f4de8e202
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ spec/dest
4
+ .bundle
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ inherit_gem:
2
+ bunto: .rubocop.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 1.9
6
+ Include:
7
+ - lib/*.rb
8
+
9
+ Exclude:
10
+ - script/**/*
11
+ - spec/**/*
data/.travis.yml ADDED
@@ -0,0 +1,34 @@
1
+ # Travis CI
2
+
3
+ sudo: false
4
+ language: ruby
5
+ rvm:
6
+ - 2.0
7
+ - 2.1
8
+ - 2.2
9
+ matrix:
10
+ include:
11
+ - # GitHub Pages
12
+ - rvm: 1.9.3
13
+ env: BUNTO_VERSION=1.0
14
+ env:
15
+ matrix:
16
+ - BUNTO_VERSION=1.0
17
+ branches:
18
+ only:
19
+ - master
20
+ install:
21
+ - travis_retry script/bootstrap
22
+ script: script/cibuild
23
+ notifications:
24
+ webhooks:
25
+ urls:
26
+ - https://webhooks.gitter.im/e/8e6011bb9dce6d5c0753
27
+ on_success: change # options: [always|never|change] default: always
28
+ on_failure: always # options: [always|never|change] default: always
29
+ on_start: never # options: [always|never|change] default: always
30
+ email:
31
+ recipients:
32
+ - SuriyaaKudoIsc@users.noreply.github.com
33
+ on_success: never
34
+ on_failure: never
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ if ENV["BUNTO_VERSION"]
5
+ gem "bunto", "~> #{ENV["BUNTO_VERSION"]}"
6
+ end
data/History.markdown ADDED
@@ -0,0 +1,4 @@
1
+ # History
2
+
3
+ ## 1.0.0 / 2016-03-13
4
+ * Birthday!
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016-present GitHub, inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Bunto Sitemap Generator Plugin
2
+
3
+ *Bunto plugin to silently generate a sitemaps.org compliant sitemap for your Bunto site*
4
+
5
+ [![Build Status](https://travis-ci.org/bunto/bunto-sitemap.svg?branch=master)](https://travis-ci.org/bunto/bunto-sitemap)
6
+
7
+ ## Usage
8
+
9
+ 1. Add `gem 'bunto-sitemap'` to your site's Gemfile and run `bundle`
10
+ 2. Add the following to your site's `_config.yml`:
11
+
12
+ ```yml
13
+ gems:
14
+ - bunto-sitemap
15
+ ```
16
+
17
+ If all gem plugins have the same `priority`, they will be executed in the
18
+ order they are required, generally. Thus, if you have other plugins which
19
+ generate content and store that content in `site.pages`, `site.posts`, or
20
+ `site.collections`, be sure to require `bunto-sitemap` either *after*
21
+ those other gems if you *want* the sitemap to include the generated
22
+ content, or *before* those other gems if you *don't want* the sitemap to
23
+ include the generated content from the gems. (Programming is *hard*.)
24
+
25
+ ## Exclusions
26
+
27
+ If you would like to exclude specific pages/posts from the sitemap set the
28
+ sitemap flag to `false` in the front matter for the page/post.
29
+
30
+ ```yml
31
+ sitemap: false
32
+ ```
33
+
34
+ ## Developing locally
35
+
36
+ Use `script/bootstrap` to bootstrap your local development environment.
37
+
38
+ Use `script/console` to load a local IRB console with the Gem.
39
+
40
+ ## Testing
41
+
42
+ 1. `script/bootstrap`
43
+ 2. `script/cibuild`
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork the project
48
+ 2. Create a descriptively named feature branch
49
+ 3. Add your feature
50
+ 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.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "bunto-sitemap"
5
+ spec.summary = "Automatically generate a sitemap.xml for your Bunto site."
6
+ spec.version = "1.0.0"
7
+ spec.authors = ["GitHub, Inc."]
8
+ spec.email = "support@github.com"
9
+ spec.homepage = "https://github.com/bunto/bunto-sitemap"
10
+ spec.licenses = ["MIT"]
11
+
12
+ spec.files = `git ls-files -z`.split("\x0")
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_development_dependency "bunto", ">= 1.0"
18
+ spec.add_development_dependency "bunto-last-modified-at", "1.0"
19
+ spec.add_development_dependency "rspec", "~> 3.0"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rubocop"
23
+ end
@@ -0,0 +1,74 @@
1
+ require 'fileutils'
2
+
3
+ module Bunto
4
+ class PageWithoutAFile < Page
5
+ def read_yaml(*)
6
+ @data ||= {}
7
+ end
8
+ end
9
+
10
+ class BuntoSitemap < Bunto::Generator
11
+ safe true
12
+ priority :lowest
13
+
14
+ # Main plugin action, called by Bunto-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
+ ).freeze
31
+
32
+ # Array of all non-bunto 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
+ Bunto.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.exist? @site.in_source_dir("sitemap.xml")
69
+ else
70
+ File.exist? Bunto.sanitized_path(@site.source, "sitemap.xml")
71
+ end
72
+ end
73
+ end
74
+ end
data/lib/sitemap.xml ADDED
@@ -0,0 +1,46 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <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
+ {% capture site_url %}{% if site.url %}{{ site.url | append: site.baseurl }}{% else %}{{ site.github.url }}{% endif %}{% endcapture %}
4
+ {% for post in site.posts %}{% unless post.sitemap == false %}
5
+ <url>
6
+ <loc>{{ post.url | prepend: site_url | uri_escape }}</loc>
7
+ {% if post.last_modified_at %}
8
+ <lastmod>{{ post.last_modified_at | date_to_xmlschema }}</lastmod>
9
+ {% else %}
10
+ <lastmod>{{ post.date | date_to_xmlschema }}</lastmod>
11
+ {% endif %}
12
+ </url>
13
+ {% endunless %}{% endfor %}
14
+ {% for page in site.html_pages %}{% unless page.sitemap == false %}
15
+ <url>
16
+ <loc>{{ page.url | replace:'/index.html','/' | prepend: site_url | uri_escape }}</loc>
17
+ {% if page.last_modified_at %}
18
+ <lastmod>{{ page.last_modified_at | date_to_xmlschema }}</lastmod>
19
+ {% endif %}
20
+ </url>
21
+ {% endunless %}{% endfor %}
22
+ {% for collection in site.collections %}{% unless collection.last.output == false or collection.output == false or collection.label == 'posts' %}
23
+ {% for doc in collection.last.docs %}{% unless doc.sitemap == false %}
24
+ <url>
25
+ <loc>{{ doc.url | replace:'/index.html','/' | prepend: site_url | uri_escape }}</loc>
26
+ {% if doc.last_modified_at %}
27
+ <lastmod>{{ doc.last_modified_at | date_to_xmlschema }}</lastmod>
28
+ {% endif %}
29
+ </url>
30
+ {% endunless %}{% endfor %}
31
+ {% for doc in collection.docs %}{% unless doc.sitemap == false %}
32
+ <url>
33
+ <loc>{{ doc.url | replace:'/index.html','/' | prepend: site_url | uri_escape }}</loc>
34
+ {% if doc.last_modified_at %}
35
+ <lastmod>{{ doc.last_modified_at | date_to_xmlschema }}</lastmod>
36
+ {% endif %}
37
+ </url>
38
+ {% endunless %}{% endfor %}
39
+ {% endunless %}{% endfor %}
40
+ {% for file in site.html_files %}
41
+ <url>
42
+ <loc>{{ file.path | prepend: site_url | uri_escape }}</loc>
43
+ <lastmod>{{ file.modified_time | date_to_xmlschema }}</lastmod>
44
+ </url>
45
+ {% endfor %}
46
+ </urlset>
data/script/bootstrap ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ bundle install
data/script/cibuild ADDED
@@ -0,0 +1,8 @@
1
+ #!/bin/sh
2
+ set -e
3
+
4
+ bundle exec rspec
5
+ bundle exec rspec spec/test_bunto-last-modified-at.rb
6
+ if [ "$BUNTO_VERSION" = "1.0" ]; then
7
+ bundle exec rubocop -S -D
8
+ fi
data/script/console ADDED
@@ -0,0 +1,34 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ def relative_to_root(path)
4
+ File.expand_path(path, File.dirname(File.dirname(__FILE__)))
5
+ end
6
+
7
+ require 'bunto'
8
+ require relative_to_root('lib/bunto-sitemap.rb')
9
+ require 'pry-debugger'
10
+
11
+ SOURCE_DIR = relative_to_root('spec/fixtures')
12
+ DEST_DIR = relative_to_root('spec/dest')
13
+
14
+ def source_dir(*files)
15
+ File.join(SOURCE_DIR, *files)
16
+ end
17
+
18
+ def dest_dir(*files)
19
+ File.join(DEST_DIR, *files)
20
+ end
21
+
22
+ def config(overrides = {})
23
+ Bunto.configuration({
24
+ "source" => source_dir,
25
+ "destination" => dest_dir,
26
+ "url" => "http://example.org"
27
+ }).merge(overrides)
28
+ end
29
+
30
+ def site(configuration = config)
31
+ Bunto::Site.new(configuration)
32
+ end
33
+
34
+ binding.pry
data/script/release ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ # Tag and push a release.
3
+
4
+ set -e
5
+
6
+ script/cibuild
7
+ bundle exec rake release
@@ -0,0 +1,152 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe(Bunto::BuntoSitemap) do
6
+ let(:overrides) do
7
+ {
8
+ "source" => source_dir,
9
+ "destination" => dest_dir,
10
+ "url" => "http://example.org",
11
+ "collections" => {
12
+ "my_collection" => { "output" => true },
13
+ "other_things" => { "output" => false }
14
+ }
15
+ }
16
+ end
17
+ let(:config) do
18
+ Bunto.configuration(overrides)
19
+ end
20
+ let(:site) { Bunto::Site.new(config) }
21
+ let(:contents) { File.read(dest_dir("sitemap.xml")) }
22
+ before(:each) do
23
+ site.process
24
+ end
25
+
26
+ it "has no layout" do
27
+ expect(contents).not_to match(/\ATHIS IS MY LAYOUT/)
28
+ end
29
+
30
+ it "creates a sitemap.xml file" do
31
+ expect(File.exist?(dest_dir("sitemap.xml"))).to be_truthy
32
+ end
33
+
34
+ it "doesn't have multiple new lines or trailing whitespace" do
35
+ expect(contents).to_not match /\s+\n/
36
+ expect(contents).to_not match /\n{2,}/
37
+ end
38
+
39
+ it "puts all the pages in the sitemap.xml file" do
40
+ expect(contents).to match /<loc>http:\/\/example\.org\/<\/loc>/
41
+ expect(contents).to match /<loc>http:\/\/example\.org\/some-subfolder\/this-is-a-subpage\.html<\/loc>/
42
+ end
43
+
44
+ it "only strips 'index.html' from end of permalink" do
45
+ expect(contents).to match /<loc>http:\/\/example\.org\/some-subfolder\/test_index\.html<\/loc>/
46
+ end
47
+
48
+ it "puts all the posts in the sitemap.xml file" do
49
+ expect(contents).to match /<loc>http:\/\/example\.org\/2014\/03\/04\/march-the-fourth\.html<\/loc>/
50
+ expect(contents).to match /<loc>http:\/\/example\.org\/2014\/03\/02\/march-the-second\.html<\/loc>/
51
+ expect(contents).to match /<loc>http:\/\/example\.org\/2013\/12\/12\/dec-the-second\.html<\/loc>/
52
+ end
53
+
54
+ describe "collections" do
55
+ it "puts all the `output:true` into sitemap.xml" do
56
+ expect(contents).to match /<loc>http:\/\/example\.org\/my_collection\/test\.html<\/loc>/
57
+ end
58
+
59
+ it "doesn't put all the `output:false` into sitemap.xml" do
60
+ expect(contents).to_not match /<loc>http:\/\/example\.org\/other_things\/test2\.html<\/loc>/
61
+ end
62
+
63
+ it "remove 'index.html' for directory custom permalinks" do
64
+ expect(contents).to match /<loc>http:\/\/example\.org\/permalink\/<\/loc>/
65
+ end
66
+
67
+ it "doesn't remove filename for non-directory custom permalinks" do
68
+ expect(contents).to match /<loc>http:\/\/example\.org\/permalink\/unique_name\.html<\/loc>/
69
+ end
70
+
71
+ it "performs URI encoding of site paths" do
72
+ expect(contents).to match /<loc>http:\/\/example\.org\/this%20url%20has%20an%20%C3%BCmlaut<\/loc>/
73
+ end
74
+ end
75
+
76
+ it "generates the correct date for each of the posts" do
77
+ expect(contents).to match /<lastmod>2014-03-04T00:00:00(-|\+)\d+:\d+<\/lastmod>/
78
+ expect(contents).to match /<lastmod>2014-03-02T00:00:00(-|\+)\d+:\d+<\/lastmod>/
79
+ expect(contents).to match /<lastmod>2013-12-12T00:00:00(-|\+)\d+:\d+<\/lastmod>/
80
+ end
81
+
82
+ it "puts all the static HTML files in the sitemap.xml file" do
83
+ expect(contents).to match /<loc>http:\/\/example\.org\/some-subfolder\/this-is-a-subfile\.html<\/loc>/
84
+ end
85
+
86
+ it "does not include assets or any static files that aren't .html" do
87
+ expect(contents).not_to match /<loc>http:\/\/example\.org\/images\/hubot\.png<\/loc>/
88
+ expect(contents).not_to match /<loc>http:\/\/example\.org\/feeds\/atom\.xml<\/loc>/
89
+ end
90
+
91
+ it "does include assets or any static files with .xhtml and .htm extensions" do
92
+ expect(contents).to match /\/some-subfolder\/xhtml\.xhtml/
93
+ expect(contents).to match /\/some-subfolder\/htm\.htm/
94
+ end
95
+
96
+ it "does not include posts that have set 'sitemap: false'" do
97
+ expect(contents).not_to match /\/exclude-this-post\.html<\/loc>/
98
+ end
99
+
100
+ it "does not include pages that have set 'sitemap: false'" do
101
+ expect(contents).not_to match /\/exclude-this-page\.html<\/loc>/
102
+ end
103
+
104
+ it "correctly formats timestamps of static files" do
105
+ expect(contents).to match /\/this-is-a-subfile\.html<\/loc>\s+<lastmod>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(-|\+)\d{2}:\d{2}<\/lastmod>/
106
+ end
107
+
108
+ it "includes the correct number of items" do
109
+ expect(contents.scan(/(?=<url>)/).count).to eql 15
110
+ end
111
+
112
+ context "with a baseurl" do
113
+ let(:config) do
114
+ Bunto.configuration(Bunto::Utils.deep_merge_hashes(overrides, {"baseurl" => "/bass"}))
115
+ end
116
+
117
+ it "correctly adds the baseurl to the static files" do
118
+ expect(contents).to match /<loc>http:\/\/example\.org\/bass\/some-subfolder\/this-is-a-subfile\.html<\/loc>/
119
+ end
120
+
121
+ it "correctly adds the baseurl to the collections" do
122
+ expect(contents).to match /<loc>http:\/\/example\.org\/bass\/my_collection\/test\.html<\/loc>/
123
+ end
124
+
125
+ it "correctly adds the baseurl to the pages" do
126
+ expect(contents).to match /<loc>http:\/\/example\.org\/bass\/<\/loc>/
127
+ expect(contents).to match /<loc>http:\/\/example\.org\/bass\/some-subfolder\/this-is-a-subpage\.html<\/loc>/
128
+ end
129
+
130
+ it "correctly adds the baseurl to the posts" do
131
+ expect(contents).to match /<loc>http:\/\/example\.org\/bass\/2014\/03\/04\/march-the-fourth\.html<\/loc>/
132
+ expect(contents).to match /<loc>http:\/\/example\.org\/bass\/2014\/03\/02\/march-the-second\.html<\/loc>/
133
+ expect(contents).to match /<loc>http:\/\/example\.org\/bass\/2013\/12\/12\/dec-the-second\.html<\/loc>/
134
+ end
135
+ end
136
+
137
+ context "with site url that needs URI encoding" do
138
+ let(:config) do
139
+ Bunto.configuration(Bunto::Utils.deep_merge_hashes(overrides, {"url" => "http://has ümlaut.org"}))
140
+ end
141
+
142
+ 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>/
146
+ end
147
+
148
+ it "does not double-escape site url" do
149
+ expect(contents).to_not match /%25/
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,9 @@
1
+ timezone: UTC
2
+
3
+ defaults:
4
+ -
5
+ scope:
6
+ path: ""
7
+ type: page
8
+ values:
9
+ layout: some_default
@@ -0,0 +1,4 @@
1
+ ---
2
+ ---
3
+ THIS IS MY LAYOUT
4
+ {{ content }}
@@ -0,0 +1,5 @@
1
+ ---
2
+ permalink: /permalink/
3
+ ---
4
+
5
+ # Custom permalink
@@ -0,0 +1,5 @@
1
+ ---
2
+ permalink: /permalink/unique_name.html
3
+ ---
4
+
5
+ # Unique html name
@@ -0,0 +1,4 @@
1
+ ---
2
+ ---
3
+
4
+ This is just a test.
@@ -0,0 +1,5 @@
1
+ ---
2
+ permalink: this url has an ümlaut
3
+ ---
4
+
5
+ # URL contains characters that need to be URI encoded
@@ -0,0 +1,4 @@
1
+ ---
2
+ ---
3
+
4
+ This file shouldn't show up in the sitemap.
@@ -0,0 +1,4 @@
1
+ ---
2
+ ---
3
+
4
+ December the twelfth, actually.
@@ -0,0 +1,4 @@
1
+ ---
2
+ ---
3
+
4
+ Please don't modify this file. It's modified time is important.
@@ -0,0 +1,4 @@
1
+ ---
2
+ ---
3
+
4
+ March the second!
@@ -0,0 +1,4 @@
1
+ ---
2
+ ---
3
+
4
+ March the fourth!
@@ -0,0 +1,5 @@
1
+ ---
2
+ sitemap: false
3
+ ---
4
+
5
+ This post should not appear in the sitemap.
@@ -0,0 +1,4 @@
1
+ ---
2
+ ---
3
+
4
+ This is a page with a modified time.
@@ -0,0 +1,6 @@
1
+ ---
2
+ ---
3
+
4
+ <?xml version="1.0" encoding="utf-8"?>
5
+ <feed xmlns="http://www.w3.org/2005/Atom">
6
+ </feed>
Binary file
@@ -0,0 +1,4 @@
1
+ ---
2
+ ---
3
+
4
+ HERE IS MY SITE I AM SO EXCITED TO BE USING GITHUB PAGES
@@ -0,0 +1,5 @@
1
+ ---
2
+ sitemap: false
3
+ ---
4
+
5
+ Exclude this page
@@ -0,0 +1 @@
1
+ This file has an .htm extension, and should be included in the sitemap
@@ -0,0 +1,4 @@
1
+ ---
2
+ ---
3
+
4
+ The permalink of this page does not end with a '/', but with a filename
@@ -0,0 +1,4 @@
1
+ ---
2
+ ---
3
+
4
+ This is a subpage!
@@ -0,0 +1 @@
1
+ This file has an .xhtml extension, and should be included in the sitemap
@@ -0,0 +1,21 @@
1
+ require 'bunto'
2
+ require File.expand_path('../lib/bunto-sitemap', File.dirname(__FILE__))
3
+
4
+ Bunto.logger.log_level = :error
5
+
6
+ RSpec.configure do |config|
7
+ config.run_all_when_everything_filtered = true
8
+ config.filter_run :focus
9
+ config.order = 'random'
10
+
11
+ SOURCE_DIR = File.expand_path("../fixtures", __FILE__)
12
+ DEST_DIR = File.expand_path("../dest", __FILE__)
13
+
14
+ def source_dir(*files)
15
+ File.join(SOURCE_DIR, *files)
16
+ end
17
+
18
+ def dest_dir(*files)
19
+ File.join(DEST_DIR, *files)
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'bunto-last-modified-at'
3
+
4
+ describe(Bunto::BuntoSitemap) do
5
+ let(:overrides) do
6
+ {
7
+ "source" => source_dir,
8
+ "destination" => dest_dir,
9
+ "url" => "http://example.org",
10
+ "collections" => {
11
+ "my_collection" => { "output" => true },
12
+ "other_things" => { "output" => false }
13
+ }
14
+ }
15
+ end
16
+ let(:config) do
17
+ Bunto.configuration(overrides)
18
+ end
19
+ let(:site) { Bunto::Site.new(config) }
20
+ let(:contents) { File.read(dest_dir("sitemap.xml")) }
21
+ before(:each) do
22
+ site.process
23
+ end
24
+
25
+ context "with bunto-last-modified-at" do
26
+ it "correctly adds the modified time to the posts" do
27
+ expect(contents).to match /<loc>http:\/\/example.org\/2015\/01\/18\/bunto-last-modified-at.html<\/loc>\s+<lastmod>2015-01-19T07:03:38\+00:00<\/lastmod>/
28
+ end
29
+
30
+ it "correctly adds the modified time to the pages" do
31
+ expect(contents).to match /<loc>http:\/\/example.org\/bunto-last-modified-at\/page.html<\/loc>\s+<lastmod>2015-01-19T07:03:38\+00:00<\/lastmod>/
32
+ end
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bunto-sitemap
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - GitHub, Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bunto
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bunto-last-modified-at
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email: support@github.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".gitignore"
104
+ - ".rspec"
105
+ - ".rubocop.yml"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - History.markdown
109
+ - LICENSE.md
110
+ - README.md
111
+ - Rakefile
112
+ - bunto-sitemap.gemspec
113
+ - lib/bunto-sitemap.rb
114
+ - lib/sitemap.xml
115
+ - script/bootstrap
116
+ - script/cibuild
117
+ - script/console
118
+ - script/release
119
+ - spec/bunto-sitemap_spec.rb
120
+ - spec/fixtures/_config.yml
121
+ - spec/fixtures/_layouts/some_default.html
122
+ - spec/fixtures/_my_collection/custom_permalink.md
123
+ - spec/fixtures/_my_collection/custom_permalink_2.md
124
+ - spec/fixtures/_my_collection/test.html
125
+ - spec/fixtures/_my_collection/this-has-non-standard-chars.md
126
+ - spec/fixtures/_other_things/test2.html
127
+ - spec/fixtures/_posts/2015-12-12-dec-the-second.md
128
+ - spec/fixtures/_posts/2016-01-18-jekyll-last-modified-at.md
129
+ - spec/fixtures/_posts/2016-03-02-march-the-second.md
130
+ - spec/fixtures/_posts/2016-03-04-march-the-fourth.md
131
+ - spec/fixtures/_posts/2016-05-11-exclude-this-post.md
132
+ - spec/fixtures/bunto-last-modified-at/page.html
133
+ - spec/fixtures/feeds/atom.xml
134
+ - spec/fixtures/images/hubot.png
135
+ - spec/fixtures/index.html
136
+ - spec/fixtures/some-subfolder/exclude-this-page.html
137
+ - spec/fixtures/some-subfolder/htm.htm
138
+ - spec/fixtures/some-subfolder/test_index.html
139
+ - spec/fixtures/some-subfolder/this-is-a-subfile.html
140
+ - spec/fixtures/some-subfolder/this-is-a-subpage.html
141
+ - spec/fixtures/some-subfolder/xhtml.xhtml
142
+ - spec/spec_helper.rb
143
+ - spec/test_bunto-last-modified-at.rb
144
+ homepage: https://github.com/bunto/bunto-sitemap
145
+ licenses:
146
+ - MIT
147
+ metadata: {}
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 2.2.2
165
+ signing_key:
166
+ specification_version: 4
167
+ summary: Automatically generate a sitemap.xml for your Bunto site.
168
+ test_files:
169
+ - spec/bunto-sitemap_spec.rb
170
+ - spec/fixtures/_config.yml
171
+ - spec/fixtures/_layouts/some_default.html
172
+ - spec/fixtures/_my_collection/custom_permalink.md
173
+ - spec/fixtures/_my_collection/custom_permalink_2.md
174
+ - spec/fixtures/_my_collection/test.html
175
+ - spec/fixtures/_my_collection/this-has-non-standard-chars.md
176
+ - spec/fixtures/_other_things/test2.html
177
+ - spec/fixtures/_posts/2015-12-12-dec-the-second.md
178
+ - spec/fixtures/_posts/2016-01-18-jekyll-last-modified-at.md
179
+ - spec/fixtures/_posts/2016-03-02-march-the-second.md
180
+ - spec/fixtures/_posts/2016-03-04-march-the-fourth.md
181
+ - spec/fixtures/_posts/2016-05-11-exclude-this-post.md
182
+ - spec/fixtures/bunto-last-modified-at/page.html
183
+ - spec/fixtures/feeds/atom.xml
184
+ - spec/fixtures/images/hubot.png
185
+ - spec/fixtures/index.html
186
+ - spec/fixtures/some-subfolder/exclude-this-page.html
187
+ - spec/fixtures/some-subfolder/htm.htm
188
+ - spec/fixtures/some-subfolder/test_index.html
189
+ - spec/fixtures/some-subfolder/this-is-a-subfile.html
190
+ - spec/fixtures/some-subfolder/this-is-a-subpage.html
191
+ - spec/fixtures/some-subfolder/xhtml.xhtml
192
+ - spec/spec_helper.rb
193
+ - spec/test_bunto-last-modified-at.rb