Move Document#sluggify to Utils#slugify

This commit is contained in:
Chris Frederick 2014-09-02 13:26:48 +09:00
parent 05d65f0341
commit 3ca1245027
2 changed files with 17 additions and 17 deletions

View File

@ -45,21 +45,6 @@ module Jekyll
File.basename(path, suffix)
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.
#
# Returns the extension name of the document.
@ -144,8 +129,8 @@ module Jekyll
collection: collection.label,
path: cleaned_relative_path,
output_ext: Jekyll::Renderer.new(site, self).output_ext,
name: sluggify(basename(".*")),
title: sluggify(data['title']) || sluggify(basename(".*"))
name: Utils.slugify(basename(".*")),
title: Utils.slugify(data['title']) || Utils.slugify(basename(".*"))
}
end

View File

@ -102,5 +102,20 @@ module Jekyll
!!(File.open(file, 'rb') { |f| f.read(5) } =~ /\A---\r?\n/)
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