From a72706ace6059ab9290de566b548f85a445e7a6c Mon Sep 17 00:00:00 2001 From: Chris Frederick Date: Tue, 26 Aug 2014 11:46:01 +0900 Subject: [PATCH] Add Document#slug --- lib/jekyll/document.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index a4bc6412..db471c32 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -45,6 +45,15 @@ module Jekyll File.basename(path, suffix) end + # The sluggified base filename of the document. + # + # Returns the base filename of the document in lowercase, with every + # sequence of spaces and non-alphanumeric characters replaced with a + # hyphen. + def slug + File.basename(path, ".*").downcase.gsub(/[\W\s]+/, '-') + end + # The extension name of the document. # # Returns the extension name of the document. @@ -129,7 +138,7 @@ module Jekyll collection: collection.label, path: cleaned_relative_path, output_ext: Jekyll::Renderer.new(site, self).output_ext, - name: basename(".*") + name: slug } end