Optimize more URL#sanitize_url
This commit is contained in:
parent
3227c4ecea
commit
1395d5686b
|
@ -52,19 +52,19 @@ module Jekyll
|
|||
|
||||
# Returns a sanitized String URL
|
||||
def sanitize_url(in_url)
|
||||
url = in_url
|
||||
# Remove all double slashes
|
||||
.tr('//', '/') \
|
||||
|
||||
# Remove all double slashes
|
||||
url = in_url.gsub(/\/\//, "/")
|
||||
# Remove every URL segment that consists solely of dots
|
||||
.split('/').reject{ |part| part =~ /^\.+$/ }.join('/') \
|
||||
|
||||
# Remove every URL segment that consists solely of dots
|
||||
url = url.split('/').reject{ |part| part =~ /^\.+$/ }.join('/')
|
||||
# Always add a leading slash
|
||||
.gsub(/\A([^\/])/, '/\1')
|
||||
|
||||
# Append a trailing slash to the URL if the unsanitized URL had one
|
||||
url += "/" if in_url =~ /\/$/
|
||||
|
||||
# Always add a leading slash
|
||||
url.gsub!(/\A([^\/])/, '/\1')
|
||||
|
||||
url
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue