Enhance detection of conflicting destination URLs (#8459)

Merge pull request 8459
This commit is contained in:
Ashwin Maroli 2020-11-08 21:45:17 +05:30 committed by GitHub
parent bcbc451a26
commit ce441d32ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 20 deletions

View File

@ -143,14 +143,40 @@ Feature: Fancy permalinks
And I should see "I am PHP" in "_site/2016/i-am-php.php" And I should see "I am PHP" in "_site/2016/i-am-php.php"
And I should see "I am also PHP" in "_site/i-am-also-php.php" And I should see "I am also PHP" in "_site/i-am-also-php.php"
Scenario: Use the same permalink twice Scenario: Using the same permalink twice
Given I have a "cool.md" page with permalink "/amazing.html" that contains "I am cool" Given I have a "cool.md" page with permalink "/amazing.html" that contains "I am cool"
And I have an "awesome.md" page with permalink "/amazing.html" that contains "I am also awesome" And I have an "awesome.md" page with permalink "/amazing.html" that contains "I am also awesome"
And I have an "amazing.html" file with content:
"""
Hello World
I'm a static file
"""
And I have a "_config.yml" file with content:
"""
collections:
puppies:
output: true
permalink: /:collection/:year/:month/:day/:title:output_ext
"""
And I have a _puppies directory
And I have the following documents under the puppies collection:
| title | date | content |
| Rover | 2009-03-27 | content for Rover. |
And I have a _posts directory
And I have the following post:
| title | date | layout | category | content |
| Rover | 2009-03-27 | none | puppies | Luke, I am your father. |
When I run jekyll build When I run jekyll build
Then I should get a zero exit status Then I should get a zero exit status
And the _site directory should exist And the _site directory should exist
And I should see "Conflict: The URL '" in the build output And I should see "Conflict: The following destination is shared by multiple files." in the build output
And I should see "amazing.html' is the destination for the following pages: awesome.md, cool.md" in the build output And I should see "_site/amazing.html" in the build output
And I should see "awesome.md" in the build output
And I should see "cool.md" in the build output
And I should see "amazing.html" in the build output
And I should see "_site/puppies/2009/03/27/rover.html" in the build output
And I should see "_posts/2009-03-27-rover.markdown" in the build output
And I should see "_puppies/rover.md" in the build output
Scenario: Redirecting from an existing permalink Scenario: Redirecting from an existing permalink
Given I have a configuration file with "plugins" set to "[jekyll-redirect-from]" Given I have a configuration file with "plugins" set to "[jekyll-redirect-from]"
@ -166,5 +192,7 @@ Feature: Fancy permalinks
When I run jekyll build When I run jekyll build
Then I should get a zero exit status Then I should get a zero exit status
And the _site directory should exist And the _site directory should exist
And I should not see "Conflict: The URL '" in the build output And I should not see "Conflict: The following destination is shared by multiple files." in the build output
And I should not see "offers/index.html' is the destination for the following pages: offers.html, redirect.html" in the build output And I should not see "_site/offers/index.html" in the build output
And I should not see "offers.html" in the build output
And I should not see "redirect.html" in the build output

View File

@ -67,15 +67,16 @@ module Jekyll
def conflicting_urls(site) def conflicting_urls(site)
conflicting_urls = false conflicting_urls = false
urls = {} destination_map(site).each do |dest, paths|
urls = collect_urls(urls, site.pages, site.dest)
urls = collect_urls(urls, site.posts.docs, site.dest)
urls.each do |url, paths|
next unless paths.size > 1 next unless paths.size > 1
conflicting_urls = true conflicting_urls = true
Jekyll.logger.warn "Conflict:", "The URL '#{url}' is the destination" \ Jekyll.logger.warn "Conflict:",
" for the following pages: #{paths.join(", ")}" "The following destination is shared by multiple files."
Jekyll.logger.warn "", "The written file may end up with unexpected contents."
Jekyll.logger.warn "", dest.to_s.cyan
paths.each { |path| Jekyll.logger.warn "", " - #{path}" }
Jekyll.logger.warn ""
end end
conflicting_urls conflicting_urls
end end
@ -122,18 +123,15 @@ module Jekyll
private private
def collect_urls(urls, things, destination) def destination_map(site)
things.each do |thing| {}.tap do |result|
next if allow_used_permalink?(thing) site.each_site_file do |thing|
next if allow_used_permalink?(thing)
dest = thing.destination(destination) dest_path = thing.destination(site.dest)
if urls[dest] (result[dest_path] ||= []) << thing.path
urls[dest] << thing.path
else
urls[dest] = [thing.path]
end end
end end
urls
end end
def allow_used_permalink?(item) def allow_used_permalink?(item)