Move Document#sluggify to Utils#slugify
This commit is contained in:
parent
05d65f0341
commit
3ca1245027
|
@ -45,21 +45,6 @@ module Jekyll
|
||||||
File.basename(path, suffix)
|
File.basename(path, suffix)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sluggify a filename or title.
|
|
||||||
#
|
|
||||||
# name - the filename or title to sluggify
|
|
||||||
#
|
|
||||||
# Returns the given filename or title in lowercase, with every
|
|
||||||
# sequence of spaces and non-alphanumeric characters replaced with a
|
|
||||||
# hyphen.
|
|
||||||
def sluggify(name)
|
|
||||||
if name.nil?
|
|
||||||
nil
|
|
||||||
else
|
|
||||||
name.downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# The extension name of the document.
|
# The extension name of the document.
|
||||||
#
|
#
|
||||||
# Returns the extension name of the document.
|
# Returns the extension name of the document.
|
||||||
|
@ -144,8 +129,8 @@ module Jekyll
|
||||||
collection: collection.label,
|
collection: collection.label,
|
||||||
path: cleaned_relative_path,
|
path: cleaned_relative_path,
|
||||||
output_ext: Jekyll::Renderer.new(site, self).output_ext,
|
output_ext: Jekyll::Renderer.new(site, self).output_ext,
|
||||||
name: sluggify(basename(".*")),
|
name: Utils.slugify(basename(".*")),
|
||||||
title: sluggify(data['title']) || sluggify(basename(".*"))
|
title: Utils.slugify(data['title']) || Utils.slugify(basename(".*"))
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -102,5 +102,20 @@ module Jekyll
|
||||||
!!(File.open(file, 'rb') { |f| f.read(5) } =~ /\A---\r?\n/)
|
!!(File.open(file, 'rb') { |f| f.read(5) } =~ /\A---\r?\n/)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Slugify a filename or title.
|
||||||
|
#
|
||||||
|
# name - the filename or title to slugify
|
||||||
|
#
|
||||||
|
# Returns the given filename or title in lowercase, with every
|
||||||
|
# sequence of spaces and non-alphanumeric characters replaced with a
|
||||||
|
# hyphen.
|
||||||
|
def slugify(name)
|
||||||
|
if name.nil?
|
||||||
|
nil
|
||||||
|
else
|
||||||
|
name.downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue