Use select and find instead of conditional loop
This commit is contained in:
parent
0eae36aec2
commit
8223ebd861
|
@ -51,13 +51,11 @@ module Jekyll
|
||||||
urls = {}
|
urls = {}
|
||||||
urls = collect_urls(urls, site.pages, site.dest)
|
urls = collect_urls(urls, site.pages, site.dest)
|
||||||
urls = collect_urls(urls, site.posts.docs, site.dest)
|
urls = collect_urls(urls, site.posts.docs, site.dest)
|
||||||
urls.each do |url, paths|
|
urls.select { |_, p| p.size > 1 }.each do |url, paths|
|
||||||
if paths.size > 1
|
|
||||||
conflicting_urls = true
|
conflicting_urls = true
|
||||||
Jekyll.logger.warn "Conflict:", "The URL '#{url}' is the destination" \
|
Jekyll.logger.warn "Conflict:", "The URL '#{url}' is the destination" \
|
||||||
" for the following pages: #{paths.join(", ")}"
|
" for the following pages: #{paths.join(", ")}"
|
||||||
end
|
end
|
||||||
end
|
|
||||||
conflicting_urls
|
conflicting_urls
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -80,14 +78,12 @@ module Jekyll
|
||||||
def urls_only_differ_by_case(site)
|
def urls_only_differ_by_case(site)
|
||||||
urls_only_differ_by_case = false
|
urls_only_differ_by_case = false
|
||||||
urls = case_insensitive_urls(site.pages + site.docs_to_write, site.dest)
|
urls = case_insensitive_urls(site.pages + site.docs_to_write, site.dest)
|
||||||
urls.each do |case_insensitive_url, real_urls|
|
urls.select { |_, p| p.size > 1 }.each do |_, real_urls|
|
||||||
if real_urls.uniq.size > 1
|
|
||||||
urls_only_differ_by_case = true
|
urls_only_differ_by_case = true
|
||||||
Jekyll.logger.warn "Warning:", "The following URLs only differ" \
|
Jekyll.logger.warn "Warning:", "The following URLs only differ" \
|
||||||
" by case. On a case-insensitive file system one of the URLs" \
|
" by case. On a case-insensitive file system one of the URLs" \
|
||||||
" will be overwritten by the other: #{real_urls.join(", ")}"
|
" will be overwritten by the other: #{real_urls.join(", ")}"
|
||||||
end
|
end
|
||||||
end
|
|
||||||
urls_only_differ_by_case
|
urls_only_differ_by_case
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -59,23 +59,21 @@ eos
|
||||||
def render(context)
|
def render(context)
|
||||||
site = context.registers[:site]
|
site = context.registers[:site]
|
||||||
|
|
||||||
site.posts.docs.each do |p|
|
post = site.posts.docs.find { |p| @post == p }
|
||||||
if @post == p
|
if post
|
||||||
return p.url
|
return post.url
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# New matching method did not match, fall back to old method
|
# New matching method did not match, fall back to old method
|
||||||
# with deprecation warning if this matches
|
# with deprecation warning if this matches
|
||||||
|
|
||||||
site.posts.docs.each do |p|
|
post = site.posts.docs.find { |p| @post.deprecated_equality p }
|
||||||
if @post.deprecated_equality p
|
if post
|
||||||
Jekyll::Deprecator.deprecation_message "A call to '{{ post_url #{@post.name} }}' did not match " \
|
Jekyll::Deprecator.deprecation_message "A call to '{{ post_url #{@post.name} }}' did not match " \
|
||||||
"a post using the new matching method of checking name " \
|
"a post using the new matching method of checking name " \
|
||||||
"(path-date-slug) equality. Please make sure that you " \
|
"(path-date-slug) equality. Please make sure that you " \
|
||||||
"change this tag to match the post's name exactly."
|
"change this tag to match the post's name exactly."
|
||||||
return p.url
|
return post.url
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
raise ArgumentError.new <<-eos
|
raise ArgumentError.new <<-eos
|
||||||
|
|
Loading…
Reference in New Issue