Add bin and edit workflow
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 9s

This commit is contained in:
2026-09-16 13:11:16 -06:00
parent c8ac4fcae5
commit 4cee170d66
17576 changed files with 895740 additions and 2 deletions
+6
View File
@@ -0,0 +1,6 @@
.bundle
*.gem
Gemfile.lock
spec/dest
spec/fixtures/.jekyll-cache
vendor/bundle
+2
View File
@@ -0,0 +1,2 @@
--color
--format progress
@@ -0,0 +1,9 @@
inherit_from: .rubocop_todo.yml
require: rubocop-jekyll
inherit_gem:
rubocop-jekyll: .rubocop.yml
AllCops:
Exclude:
- vendor/**/*
@@ -0,0 +1,26 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-12-06 11:55:46 +0100 using RuboCop version 0.61.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 1
Lint/Debugger:
Exclude:
- 'script/console'
# Offense count: 3
# Configuration parameters: CountComments, Max, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Exclude:
- 'spec/jekyll-sitemap_spec.rb'
- 'spec/test_jekyll-last-modified-at.rb'
# Offense count: 17
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 154
+48
View File
@@ -0,0 +1,48 @@
language: ruby
cache: bundler
rvm:
- &latest_ruby 2.6
- 2.4
matrix:
include:
# GitHub Pages
- rvm: 2.5.3
env:
- JEKYLL_VERSION="~> 3.8.5"
- GITHUB_PAGES=1 # Only set on one build in matrix
- rvm: *latest_ruby
env: JEKYLL_VERSION=">= 4.0.0"
env:
matrix:
- JEKYLL_VERSION="~> 3.8"
branches:
only:
- master
- /^v\d+\.\d+\.\d+/
git:
depth: 1000
before_install:
- gem update --system
install:
- travis_retry script/bootstrap
script: script/cibuild
notifications:
irc:
on_success: change
on_failure: change
channels:
- irc.freenode.org#jekyll
template:
- "%{repository}#%{build_number} %{message} %{build_url}"
email:
on_success: never
on_failure: change
deploy:
provider: rubygems
api_key:
secure: O8fGRnM6OJCqC2BlVE1BqYfq5aR19ulpiHhQwRiHbtSCh8H4rYt7FLsuOwSTtRQjhWYRRSpdRt2ilfQ6PY6Jx1UkxZq5zo9QAPQ9tKxiFTm7gBpZAiAgb06eyaMBSzyQ8qe2qccaFI6CiZhsiaGMsdKsWuYpuoPmdLPd7aDyYJs=
gem: jekyll-sitemap
on:
tags: true
repo: jekyll/jekyll-sitemap
condition: "$GITHUB_PAGES == 1"
+6
View File
@@ -0,0 +1,6 @@
# frozen_string_literal: true
source "https://rubygems.org"
gemspec
gem "jekyll", ENV["JEKYLL_VERSION"] if ENV["JEKYLL_VERSION"]
@@ -0,0 +1,221 @@
## 1.4.0 / 2019-11-21
### Minor Enhancements
* Avoid overwriting an existing robots.txt (#246)
### Bug Fixes
* Simulate `last_modified_at` injection by plugin (#256)
## 1.3.1 / 2019-03-25
### Bug Fixes
* Update plugin metadata and dev environment (#244)
### Development Fixes
* Lock requirement for `jekyll-last-modified-at` to `>= 1.0`
## 1.3.0 / 2019-03-21
* Allow Jekyll v4 (still alpha)
### Documentation
* Add PDF file exclusion documentation (#213)
* Correct capitalization of GitHub (#207)
### Development Fixes
* Use Ruby 2.3 and Rubocop 0.55 (#214)
* chore(deps): rubocop-jekyll-0.3 (#227)
## 1.2.0 / 2018-01-25
### Minor Enhancements
* Remove excluded static files from the sitemap (#166)
* filter/replace static index.html paths to permalink (#170)
### Development Fixes
* Condition the static file tests on Jekyll 3.4.2 and above (#167)
* Update versions for Travis (#174)
* Fix Travis Deploy (#173)
* Test against Jekyll 3.4.x *and* latest 3.x (#177)
* Define path with __dir__ (#186)
* Style: Rubocop auto-correct (#195)
* Test against Ruby 2.5 (#201)
### Documentation
* Add note about use with Github Pages gem (#179)
* Fix a couple of typos (#184)
* Use plugins instead of gems in README config (#185)
* Docs: set site.url in config (#172)
## 1.1.1 / 2017-04-11
* Cut a new version to alleviate sha256 checksum issue on RubyGems.org (#165)
## 1.1.0 / 2017-04-10
### Minor Enhancements
* escape& (#162)
* feat: remove 404 pages from the sitemap. closes #113 (#164)
## 1.0.0 / 2017-01-06
* No new changes
## 0.13.0 / 2017-01-05
### Minor Enhancements
* Add sitemap.xsl if exists (#143)
* Add robots.txt when none exists (#146)
* Refactor and add sitemap to `site.pages` (#137)
* DRY in sitemap.xml (#136)
### Documentation
* Fix #134: Rename "Issues" to "Known Issues" (#135)
* Fix #104: Add explanation in README for <lastmod> tag (#139)
* Update copyright attribution (#149)
### Development Fixes
* Travis should do a deep clone (#147)
## 0.12.0 / 2016-10-06
### Minor Enhancements
* Don't set @site.config["time"] on sitemap generation (#131)
* Use filters to clean up Liquid template (#128)
### Development Fixes
* Appease Rubocop (#132)
* Drop Addressable dependency (#133)
## 0.11.0 / 2016-07-08
* Add Rubocop (#100)
* Allow Travis to cache dependencies (#108)
* Properly Escape URLs (#107)
* Include PDF files in sitemap (#109)
## 0.10.0 / 2016-01-05
* URI encode sitemap URLs (#85)
* Do not include 'posts' collection twice (#92)
* Fix GitHub Pages tests to test just the Jekyll version (#87)
* Allow HTML files to end with `.xhtml` or `.htm` (#93)
* Simplify whitespace regex for stripping whitespace (#96)
## 0.9.0 / 2015-09-21
* Test against Jekyll 2, 3, and the GitHub Pages version. (#83)
## 0.8.1 / 2015-03-11
* Do not assume all pages have changed (#35)
* Remove duplicated range from regex (#73)
## 0.8.0 / 2015-02-03
* Call each page `page` in pages loop in `sitemap.xml` for clarity (#64)
* Remove `changefreq` (#34)
* Remove `priority` (#33)
* Don't strip 'index.html' when there is more to filename ## Minor Enhancements (#68)
## 0.7.0 / 2014-12-07
* Make `site.baseurl` support more robust (#59)
* Add `site.baseurl` to base site URL construction ## Development Fixes (#50)
* Remove unnecessary spaces and escaping in README ## Bug Fixes (#58)
## 0.6.3 / 2014-11-11
* Be backwards-compatible when `Site#in_source_dir` and `Site#in_dest_dir` don't exist (#57)
## 0.6.2 / 2014-11-08
### Bug Fixes
* Don't attempt to read the sitemap upon page creation. (#52)
* Use new secure methods to build source & dest paths. (#53)
## 0.6.1 / 2014-10-17
### Minor Enhancements
* Strip excess whitespace (#40)
### Bug Fixes
* Add UTC offset to `<lastmod>` to handle non-UTC timezones (#49)
### Development Fixes
* Adding information about exclusion flag (#45)
## 0.6.0 / 2014-09-05
### Minor Enhancements
* Include custom collections in the sitemap. (#30)
* Use `post.last_modified_at` for post `<lastmod>` if available (#37)
## 0.5.1 / 2014-07-31
### Bug Fixes
* Explicitly set sitemap layout to `nil` to avoid warning (#32)
## 0.5.0 / 2014-06-02
### Minor Enhancements
* Allow users to exclude a page/post from the sitemap (#11)
## 0.4.1 / 2014-05-10
### Bug Fixes
* Force sitemap layout to be `nil` (#16)
* Correct seconds in timestamp for static files # Development Fixes (#24)
* Upgrade to Rspec 3.0 and use `be_truthy` (#24)
## 0.4.0 / 2014-05-06
### Major Enhancements
* Support Jekyll 2.0 (#12)
## 0.3.0 / 2014-05-05
### Minor Enhancements
* Generate sitemap using html_pages (#10)
### Bug Fixes
* Remove stray sitemap.xsl from template (#8)
### Development Fixes
* Added travis (#6)
* Better timezone support (#7)
## 0.2.0 / 2014-03-24
* Loosen Jekyll requirement (#4)
## 0.1.0 / 2014-03-15
* Birthday!
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014-present, GitHub, inc. and the jekyll-sitemap contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+92
View File
@@ -0,0 +1,92 @@
# Jekyll Sitemap Generator Plugin
*Jekyll plugin to silently generate a sitemaps.org compliant sitemap for your Jekyll site*
[![Build Status](https://travis-ci.org/jekyll/jekyll-sitemap.svg?branch=master)](https://travis-ci.org/jekyll/jekyll-sitemap)
## Usage
1. Add `gem 'jekyll-sitemap'` to your site's Gemfile and run `bundle`
2. Add the following to your site's `_config.yml`:
```yml
url: "http://example.com" # the base hostname & protocol for your site
plugins:
- jekyll-sitemap
```
💡 If you are using a Jekyll version less than 3.5.0, use the `gems` key instead of `plugins`.
If all gem plugins have the same `priority`, they will be executed in the
order they are required, generally. Thus, if you have other plugins which
generate content and store that content in `site.pages`, `site.posts`, or
`site.collections`, be sure to require `jekyll-sitemap` either *after*
those other gems if you *want* the sitemap to include the generated
content, or *before* those other gems if you *don't want* the sitemap to
include the generated content from the gems. (Programming is *hard*.)
Because the sitemap is added to `site.pages`, you may have to modify any
templates that iterate through all pages (for example, to build a menu of
all of the site's content).
## Note on Use with GitHub Pages Gem
The GitHub Pages gem ignores all plugins included in the Gemfile. If you only include `jekyll-sitemap` in the Gemfile without also including it in the `_config.yml` *the plugin will not work*. This can be confusing because the official Jekyll docs state that plugins can be included in either the Gemfile or `_config.yml`.
When building a site that uses the GitHub Pages gem, follow the instructions above and ensure that `jekyll-sitemap` is listed in the `plugins` array in `_config.yml`.
:warning: If you are using Jekyll < 3.5.0 use the `gems` key instead of `plugins`.
## `<lastmod>` tag
The `<lastmod>` tag in the `sitemap.xml` will reflect by priority:
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)
2. A personalised date if you add the variable `last_modified_at:` with a date in the Front Matter
3. The creation date of your post (corresponding to the `post.date` variable)
## Exclusions
If you would like to exclude specific pages/posts from the sitemap set the
sitemap flag to `false` in the front matter for the page/post.
```yml
sitemap: false
```
To exclude files from your sitemap. It can be achieved with configuration using [Jekyll v3.7.2 and jekyll-sitemap v1.2.0](https://github.com/jekyll/jekyll/commit/776433109b96cb644938ffbf9caf4923bdde4d7f).
Add a glob config to your `_config.yml` file.
```yml
defaults:
-
scope:
path: "assets/**/*.pdf"
values:
sitemap: false
```
## Override default development settings
[Follow these instructions on Jekyll's documentation](https://jekyllrb.com/docs/usage/#override-default-development-settings).
## Developing locally
* Use `script/bootstrap` to bootstrap your local development environment.
* Use `script/console` to load a local IRB console with the Gem.
## Testing
1. `script/bootstrap`
2. `script/cibuild`
## Known Issues
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.
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.
## Contributing
1. Fork the project
2. Create a descriptively named feature branch
3. Add your feature
4. Submit a pull request
+8
View File
@@ -0,0 +1,8 @@
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
@@ -0,0 +1,29 @@
# frozen_string_literal: true
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "jekyll-sitemap/version"
Gem::Specification.new do |spec|
spec.name = "jekyll-sitemap"
spec.summary = "Automatically generate a sitemap.xml for your Jekyll site."
spec.version = Jekyll::Sitemap::VERSION
spec.authors = ["GitHub, Inc."]
spec.email = "support@github.com"
spec.homepage = "https://github.com/jekyll/jekyll-sitemap"
spec.licenses = ["MIT"]
spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r!^bin/!) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
spec.require_paths = ["lib"]
spec.required_ruby_version = ">= 2.3.0"
spec.add_dependency "jekyll", ">= 3.7", "< 5.0"
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rubocop-jekyll", "~> 0.4"
end
@@ -0,0 +1,4 @@
# frozen_string_literal: true
require "jekyll/page_without_a_file"
require "jekyll/jekyll-sitemap"
@@ -0,0 +1,7 @@
# frozen_string_literal: true
module Jekyll
module Sitemap
VERSION = "1.4.0"
end
end
@@ -0,0 +1,72 @@
# frozen_string_literal: true
require "fileutils"
module Jekyll
class JekyllSitemap < Jekyll::Generator
safe true
priority :lowest
# Main plugin action, called by Jekyll-core
def generate(site)
@site = site
@site.pages << sitemap unless file_exists?("sitemap.xml")
@site.pages << robots unless file_exists?("robots.txt")
end
private
INCLUDED_EXTENSIONS = %w(
.htm
.html
.xhtml
.pdf
).freeze
# Matches all whitespace that follows
# 1. A '>' followed by a newline or
# 2. A '}' which closes a Liquid tag
# We will strip all of this whitespace to minify the template
MINIFY_REGEX = %r!(?<=>\n|})\s+!.freeze
# Array of all non-jekyll site files with an HTML extension
def static_files
@site.static_files.select { |file| INCLUDED_EXTENSIONS.include? file.extname }
end
# Path to sitemap.xml template file
def source_path(file = "sitemap.xml")
File.expand_path "../#{file}", __dir__
end
# Destination for sitemap.xml file within the site source directory
def destination_path(file = "sitemap.xml")
@site.in_dest_dir(file)
end
def sitemap
site_map = PageWithoutAFile.new(@site, __dir__, "", "sitemap.xml")
site_map.content = File.read(source_path).gsub(MINIFY_REGEX, "")
site_map.data["layout"] = nil
site_map.data["static_files"] = static_files.map(&:to_liquid)
site_map.data["xsl"] = file_exists?("sitemap.xsl")
site_map
end
def robots
robots = PageWithoutAFile.new(@site, __dir__, "", "robots.txt")
robots.content = File.read(source_path("robots.txt"))
robots.data["layout"] = nil
robots
end
# Checks if a file already exists in the site source
def file_exists?(file_path)
pages_and_files.any? { |p| p.url == "/#{file_path}" }
end
def pages_and_files
@pages_and_files ||= @site.pages + @site.static_files
end
end
end
@@ -0,0 +1,11 @@
# frozen_string_literal: true
module Jekyll
class PageWithoutAFile < Page
# rubocop:disable Naming/MemoizedInstanceVariableName
def read_yaml(*)
@data ||= {}
end
# rubocop:enable Naming/MemoizedInstanceVariableName
end
end
@@ -0,0 +1 @@
Sitemap: {{ "sitemap.xml" | absolute_url }}
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
{% if page.xsl %}
<?xml-stylesheet type="text/xsl" href="{{ "/sitemap.xsl" | absolute_url }}"?>
{% endif %}
<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">
{% assign collections = site.collections | where_exp:'collection','collection.output != false' %}
{% for collection in collections %}
{% assign docs = collection.docs | where_exp:'doc','doc.sitemap != false' %}
{% for doc in docs %}
<url>
<loc>{{ doc.url | replace:'/index.html','/' | absolute_url | xml_escape }}</loc>
{% if doc.last_modified_at or doc.date %}
<lastmod>{{ doc.last_modified_at | default: doc.date | date_to_xmlschema }}</lastmod>
{% endif %}
</url>
{% endfor %}
{% endfor %}
{% assign pages = site.html_pages | where_exp:'doc','doc.sitemap != false' | where_exp:'doc','doc.url != "/404.html"' %}
{% for page in pages %}
<url>
<loc>{{ page.url | replace:'/index.html','/' | absolute_url | xml_escape }}</loc>
{% if page.last_modified_at %}
<lastmod>{{ page.last_modified_at | date_to_xmlschema }}</lastmod>
{% endif %}
</url>
{% endfor %}
{% assign static_files = page.static_files | where_exp:'page','page.sitemap != false' | where_exp:'page','page.name != "404.html"' %}
{% for file in static_files %}
<url>
<loc>{{ file.path | replace:'/index.html','/' | absolute_url | xml_escape }}</loc>
<lastmod>{{ file.modified_time | date_to_xmlschema }}</lastmod>
</url>
{% endfor %}
</urlset>
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
set -ex
bundle install
+5
View File
@@ -0,0 +1,5 @@
#!/bin/sh
set -e
time script/fmt
time script/test
+35
View File
@@ -0,0 +1,35 @@
#! /usr/bin/env ruby
# frozen_string_literal: true
def relative_to_root(path)
File.expand_path(path, File.dirname(__dir__))
end
require "jekyll"
require relative_to_root("lib/jekyll-sitemap.rb")
require "pry-debugger"
SOURCE_DIR = relative_to_root("spec/fixtures")
DEST_DIR = relative_to_root("spec/dest")
def source_dir(*files)
File.join(SOURCE_DIR, *files)
end
def dest_dir(*files)
File.join(DEST_DIR, *files)
end
def config(overrides = {})
Jekyll.configuration(
"source" => source_dir,
"destination" => dest_dir,
"url" => "http://example.org"
).merge(overrides)
end
def site(configuration = config)
Jekyll::Site.new(configuration)
end
binding.pry
+10
View File
@@ -0,0 +1,10 @@
#!/bin/bash
set -e
echo "Rubocop $(bundle exec rubocop --version)"
bundle exec rubocop -D -E $@
success=$?
if ((success != 0)); then
echo -e "\nTry running \`script/fmt -a\` to automatically fix errors"
fi
exit $success
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
# Tag and push a release.
set -e
script/cibuild
bundle exec rake release
+5
View File
@@ -0,0 +1,5 @@
#!/bin/bash
set -ex
bundle exec rspec "$@"
bundle exec rspec spec/test_jekyll-last-modified-at.rb
+4
View File
@@ -0,0 +1,4 @@
---
---
404. That's an error.
+19
View File
@@ -0,0 +1,19 @@
timezone: UTC
defaults:
-
scope:
path: ""
type: page
values:
layout: some_default
-
scope:
path: "static_files/excluded.pdf"
values:
sitemap: false
-
scope:
path: "static_files/html_file.html"
values:
sitemap: false
@@ -0,0 +1,4 @@
---
---
THIS IS MY LAYOUT
{{ content }}
@@ -0,0 +1,5 @@
---
permalink: /permalink/
---
# Custom permalink
@@ -0,0 +1,5 @@
---
permalink: /permalink/unique_name.html
---
# Unique html name
@@ -0,0 +1,4 @@
---
---
This is just a test.
@@ -0,0 +1,5 @@
---
permalink: this url has an ümlaut
---
# URL contains characters that need to be URI encoded
@@ -0,0 +1,4 @@
---
---
This file shouldn't show up in the sitemap.
@@ -0,0 +1,4 @@
---
---
December the twelfth, actually.
@@ -0,0 +1,4 @@
---
---
March the second!
@@ -0,0 +1,4 @@
---
---
March the fourth!
@@ -0,0 +1,5 @@
---
sitemap: false
---
This post should not appear in the sitemap.
@@ -0,0 +1,4 @@
---
---
Please don't modify this file. It's modified time is important.
@@ -0,0 +1,2 @@
---
---
@@ -0,0 +1,3 @@
---
permalink: "/2016/04/02/错误.html"
---
@@ -0,0 +1,3 @@
---
permalink: "/2016/04/03/%E9%94%99%E8%AF%AF.html"
---
@@ -0,0 +1,6 @@
---
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
</feed>
Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

@@ -0,0 +1,4 @@
---
---
HERE IS MY SITE I AM SO EXCITED TO BE USING GITHUB PAGES
@@ -0,0 +1,4 @@
---
---
This is a page with a modified time.
@@ -0,0 +1,5 @@
---
sitemap: false
---
Exclude this page
@@ -0,0 +1 @@
This file has an .htm extension, and should be included in the sitemap
@@ -0,0 +1 @@
static subfolder index.html file that should be indexed as permalink
@@ -0,0 +1,4 @@
---
---
The permalink of this page does not end with a '/', but with a filename
@@ -0,0 +1,4 @@
---
---
This is a subpage!
@@ -0,0 +1 @@
This file has an .xhtml extension, and should be included in the sitemap
@@ -0,0 +1 @@
404. That's an error.
@@ -0,0 +1,256 @@
# frozen_string_literal: true
require "spec_helper"
describe(Jekyll::JekyllSitemap) do
let(:overrides) do
{
"source" => source_dir,
"destination" => dest_dir,
"url" => "http://example.org",
"collections" => {
"my_collection" => { "output" => true },
"other_things" => { "output" => false },
},
}
end
let(:config) do
Jekyll.configuration(overrides)
end
let(:site) { Jekyll::Site.new(config) }
let(:contents) { File.read(dest_dir("sitemap.xml")) }
before(:each) do
site.process
end
it "has no layout" do
expect(contents).not_to match(%r!\ATHIS IS MY LAYOUT!)
end
it "creates a sitemap.xml file" do
expect(File.exist?(dest_dir("sitemap.xml"))).to be_truthy
end
it "doesn't have multiple new lines or trailing whitespace" do
expect(contents).to_not match %r!\s+\n!
expect(contents).to_not match %r!\n{2,}!
end
it "puts all the pages in the sitemap.xml file" do
expect(contents).to match %r!<loc>http://example\.org/</loc>!
expect(contents).to match %r!<loc>http://example\.org/some-subfolder/this-is-a-subpage\.html</loc>!
end
it "only strips 'index.html' from end of permalink" do
expect(contents).to match %r!<loc>http://example\.org/some-subfolder/test_index\.html</loc>!
end
it "puts all the posts in the sitemap.xml file" do
expect(contents).to match %r!<loc>http://example\.org/2014/03/04/march-the-fourth\.html</loc>!
expect(contents).to match %r!<loc>http://example\.org/2014/03/02/march-the-second\.html</loc>!
expect(contents).to match %r!<loc>http://example\.org/2013/12/12/dec-the-second\.html</loc>!
end
describe "collections" do
it "puts all the `output:true` into sitemap.xml" do
expect(contents).to match %r!<loc>http://example\.org/my_collection/test\.html</loc>!
end
it "doesn't put all the `output:false` into sitemap.xml" do
expect(contents).to_not match %r!<loc>http://example\.org/other_things/test2\.html</loc>!
end
it "remove 'index.html' for directory custom permalinks" do
expect(contents).to match %r!<loc>http://example\.org/permalink/</loc>!
end
it "doesn't remove filename for non-directory custom permalinks" do
expect(contents).to match %r!<loc>http://example\.org/permalink/unique_name\.html</loc>!
end
it "performs URI encoding of site paths" do
expect(contents).to match %r!<loc>http://example\.org/this%20url%20has%20an%20%C3%BCmlaut</loc>!
end
end
it "generates the correct date for each of the posts" do
expect(contents).to match %r!<lastmod>2014-03-04T00:00:00(-|\+)\d+:\d+</lastmod>!
expect(contents).to match %r!<lastmod>2014-03-02T00:00:00(-|\+)\d+:\d+</lastmod>!
expect(contents).to match %r!<lastmod>2013-12-12T00:00:00(-|\+)\d+:\d+</lastmod>!
end
it "puts all the static HTML files in the sitemap.xml file" do
expect(contents).to match %r!<loc>http://example\.org/some-subfolder/this-is-a-subfile\.html</loc>!
end
it "does not include assets or any static files that aren't .html" do
expect(contents).not_to match %r!<loc>http://example\.org/images/hubot\.png</loc>!
expect(contents).not_to match %r!<loc>http://example\.org/feeds/atom\.xml</loc>!
end
it "converts static index.html files to permalink version" do
expect(contents).to match %r!<loc>http://example\.org/some-subfolder/</loc>!
end
it "does include assets or any static files with .xhtml and .htm extensions" do
expect(contents).to match %r!/some-subfolder/xhtml\.xhtml!
expect(contents).to match %r!/some-subfolder/htm\.htm!
end
it "does include assets or any static files with .pdf extension" do
expect(contents).to match %r!/static_files/test.pdf!
end
it "does not include any static files named 404.html" do
expect(contents).not_to match %r!/static_files/404.html!
end
if Gem::Version.new(Jekyll::VERSION) >= Gem::Version.new("3.4.2")
it "does not include any static files that have set 'sitemap: false'" do
expect(contents).not_to match %r!/static_files/excluded\.pdf!
end
it "does not include any static files that have set 'sitemap: false'" do
expect(contents).not_to match %r!/static_files/html_file\.html!
end
end
it "does not include posts that have set 'sitemap: false'" do
expect(contents).not_to match %r!/exclude-this-post\.html</loc>!
end
it "does not include pages that have set 'sitemap: false'" do
expect(contents).not_to match %r!/exclude-this-page\.html</loc>!
end
it "does not include the 404 page" do
expect(contents).not_to match %r!/404\.html</loc>!
end
it "correctly formats timestamps of static files" do
expect(contents).to match %r!/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>!
end
it "includes the correct number of items" do
# static_files/excluded.pdf is excluded on Jekyll 3.4.2 and above
if Gem::Version.new(Jekyll::VERSION) >= Gem::Version.new("3.4.2")
expect(contents.scan(%r!(?=<url>)!).count).to eql 20
else
expect(contents.scan(%r!(?=<url>)!).count).to eql 21
end
end
context "with a baseurl" do
let(:config) do
Jekyll.configuration(Jekyll::Utils.deep_merge_hashes(overrides, "baseurl" => "/bass"))
end
it "correctly adds the baseurl to the static files" do
expect(contents).to match %r!<loc>http://example\.org/bass/some-subfolder/this-is-a-subfile\.html</loc>!
end
it "correctly adds the baseurl to the collections" do
expect(contents).to match %r!<loc>http://example\.org/bass/my_collection/test\.html</loc>!
end
it "correctly adds the baseurl to the pages" do
expect(contents).to match %r!<loc>http://example\.org/bass/</loc>!
expect(contents).to match %r!<loc>http://example\.org/bass/some-subfolder/this-is-a-subpage\.html</loc>!
end
it "correctly adds the baseurl to the posts" do
expect(contents).to match %r!<loc>http://example\.org/bass/2014/03/04/march-the-fourth\.html</loc>!
expect(contents).to match %r!<loc>http://example\.org/bass/2014/03/02/march-the-second\.html</loc>!
expect(contents).to match %r!<loc>http://example\.org/bass/2013/12/12/dec-the-second\.html</loc>!
end
it "adds baseurl to robots.txt" do
content = File.read(dest_dir("robots.txt"))
expect(content).to match("Sitemap: http://example.org/bass/sitemap.xml")
end
end
context "with urls that needs URI encoding" do
let(:config) do
Jekyll.configuration(Jekyll::Utils.deep_merge_hashes(overrides, "url" => "http://ümlaut.example.org"))
end
it "performs URI encoding of site url" do
expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/</loc>!
expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/some-subfolder/this-is-a-subpage.html</loc>!
expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/2014/03/04/march-the-fourth.html</loc>!
expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/2016/04/01/%E9%94%99%E8%AF%AF.html</loc>!
expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/2016/04/02/%E9%94%99%E8%AF%AF.html</loc>!
expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/2016/04/03/%E9%94%99%E8%AF%AF.html</loc>!
end
it "does not double-escape urls" do
expect(contents).to_not match %r!%25!
end
context "readme" do
let(:contents) { File.read(dest_dir("robots.txt")) }
it "has no layout" do
expect(contents).not_to match(%r!\ATHIS IS MY LAYOUT!)
end
it "creates a robots.txt file" do
expect(File.exist?(dest_dir("robots.txt"))).to be_truthy
end
it "renders liquid" do
expect(contents).to match("Sitemap: http://xn--mlaut-jva.example.org/sitemap.xml")
end
end
end
context "with user-defined robots.txt" do
let(:fixture) { "/" }
let(:fixture_source) { robot_fixtures(fixture) }
let(:fixture_dest) { robot_fixtures(fixture, "_site") }
let(:robot_contents) { File.read(robot_fixtures(fixture, "_site", "robots.txt")).strip }
let(:overrides) do
{
"source" => fixture_source,
"destination" => fixture_dest,
"url" => "http://example.org",
}
end
before(:each) { setup_fixture(fixture) }
after(:each) { cleanup_fixture(fixture) }
context "as a static-file at source-root" do
let(:fixture) { "static-at-source-root" }
it "doesn't override the robots file" do
expect(robot_contents).to eql("Allow: /")
end
end
context "as a static-file in a subdir" do
let(:fixture) { "static-in-subdir" }
it "generates a valid robot.txt" do
expect(robot_contents).to eql("Sitemap: http://example.org/sitemap.xml")
end
end
context "as a page at root" do
let(:fixture) { "page-at-root" }
it "doesn't override the robots file" do
expect(robot_contents).to eql("Allow: http://example.org")
end
end
context "as a page with permalink in a subdir" do
let(:fixture) { "permalinked-page-in-subdir" }
it "doesn't override the robots file" do
expect(robot_contents).to eql("Allow: http://example.org")
end
end
end
end
@@ -0,0 +1,4 @@
---
---
Allow: {{ site.url }}
@@ -0,0 +1,5 @@
---
permalink: '/robots.txt'
---
Allow: {{ site.url }}
@@ -0,0 +1,40 @@
# frozen_string_literal: true
require "jekyll"
require "fileutils"
require File.expand_path("../lib/jekyll-sitemap", __dir__)
Jekyll.logger.log_level = :error
RSpec.configure do |config|
config.run_all_when_everything_filtered = true
config.filter_run :focus
config.order = "random"
SOURCE_DIR = File.expand_path("fixtures", __dir__)
DEST_DIR = File.expand_path("dest", __dir__)
ROBOT_FIXTURES = File.expand_path("robot-fixtures", __dir__)
ROBOT_FIXTURE_ITEMS = %w(_posts _layouts _config.yml index.html).freeze
def source_dir(*files)
File.join(SOURCE_DIR, *files)
end
def dest_dir(*files)
File.join(DEST_DIR, *files)
end
def robot_fixtures(*subdirs)
File.join(ROBOT_FIXTURES, *subdirs)
end
def setup_fixture(directory)
ROBOT_FIXTURE_ITEMS.each { |item| FileUtils.cp_r(source_dir(item), robot_fixtures(directory)) }
end
def cleanup_fixture(directory, dest_dirname = "_site")
(ROBOT_FIXTURE_ITEMS + [dest_dirname]).each do |item|
FileUtils.remove_entry(robot_fixtures(directory, item))
end
end
end
@@ -0,0 +1,50 @@
# frozen_string_literal: true
require "spec_helper"
describe(Jekyll::JekyllSitemap) do
let(:overrides) do
{
"source" => source_dir,
"destination" => dest_dir,
"url" => "http://example.org",
"collections" => {
"my_collection" => { "output" => true },
"other_things" => { "output" => false },
},
}
end
let(:config) do
Jekyll.configuration(overrides)
end
let(:site) { Jekyll::Site.new(config) }
let(:contents) { File.read(dest_dir("sitemap.xml")) }
before(:each) do
# simulate `last_modified_at` injection by `jekyll-last-modified-at` plugin
Jekyll::Hooks.register([:pages, :documents], :post_init) do |page|
page.data["last_modified_at"] = Time.parse("2015-01-18T00:00:00+00:00")
end
site.process
end
context "with jekyll-last-modified-at" do
it "correctly adds the modified time to the posts" do
expect(contents).to match(
%r!
<loc>http://example.org/2015/01/18/jekyll-last-modified-at.html</loc>\s+
<lastmod>2015-01-18T00:00:00\+00:00</lastmod>
!x
)
end
it "correctly adds the modified time to the pages" do
expect(contents).to match(
%r!
<loc>http://example.org/jekyll-last-modified-at/page.html</loc>\s+
<lastmod>2015-01-18T00:00:00\+00:00</lastmod>
!x
)
end
end
end