Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/correctly encode ellipsis #229

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/sitemap.xml
Expand Up @@ -8,7 +8,7 @@
{% 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>
<loc>{{ doc.url | replace:'/index.html','/' | replace:'…',':ellipsis:' | absolute_url | replace:':ellipsis:','%E2%80%A6' | xml_escape }}</loc>
{% if doc.last_modified_at or doc.date %}
<lastmod>{{ doc.last_modified_at | default: doc.date | date_to_xmlschema }}</lastmod>
{% endif %}
Expand All @@ -19,7 +19,7 @@
{% 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>
<loc>{{ page.url | replace:'/index.html','/' | replace:'…',':ellipsis:' | absolute_url | replace:':ellipsis:','%E2%80%A6' | xml_escape }}</loc>
{% if page.last_modified_at %}
<lastmod>{{ page.last_modified_at | date_to_xmlschema }}</lastmod>
{% endif %}
Expand All @@ -29,7 +29,7 @@
{% 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>
<loc>{{ file.path | replace:'/index.html','/' | replace:'…',':ellipsis:' | absolute_url | replace:':ellipsis:','%E2%80%A6' | xml_escape }}</loc>
<lastmod>{{ file.modified_time | date_to_xmlschema }}</lastmod>
</url>
{% endfor %}
Expand Down
5 changes: 5 additions & 0 deletions spec/fixtures/_my_collection/this-has-an-ellipsis.md
@@ -0,0 +1,5 @@
---
permalink: this url has an ellipsis…
---

# URL contains characters that need to be URI encoded
8 changes: 6 additions & 2 deletions spec/jekyll-sitemap_spec.rb
Expand Up @@ -71,6 +71,10 @@
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

it "correctly encodes an ellipsis" do
expect(contents).to match /<loc>http:\/\/example\.org\/this%20url%20has%20an%20ellipsis%E2%80%A6<\/loc>/
end
end

it "generates the correct date for each of the posts" do
Expand Down Expand Up @@ -134,9 +138,9 @@
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
else
expect(contents.scan(%r!(?=<url>)!).count).to eql 22
end
end

Expand Down