Revise Utils#slugify with inspiration from Rails
This commit is contained in:
parent
702b39dec5
commit
4adc35aaf3
|
@ -110,10 +110,12 @@ module Jekyll
|
||||||
# sequence of spaces and non-alphanumeric characters replaced with a
|
# sequence of spaces and non-alphanumeric characters replaced with a
|
||||||
# hyphen.
|
# hyphen.
|
||||||
def slugify(string)
|
def slugify(string)
|
||||||
if string.nil?
|
unless string.nil?
|
||||||
nil
|
# Replace each non-alphanumeric character sequence with a hyphen
|
||||||
else
|
slug = string.gsub(/[^a-z0-9]+/i, '-')
|
||||||
string.downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-')
|
# Remove leading/trailing hyphen
|
||||||
|
slug.gsub!(/^\-|\-$/i, '')
|
||||||
|
slug.downcase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue