diff --git a/lib/jekyll/static_file.rb b/lib/jekyll/static_file.rb index e11d6689..927a9b47 100644 --- a/lib/jekyll/static_file.rb +++ b/lib/jekyll/static_file.rb @@ -1,6 +1,6 @@ module Jekyll class StaticFile - attr_reader :relative_path, :extname + attr_reader :relative_path, :extname, :name class << self # The cache of last modification times [path] -> mtime. @@ -97,6 +97,8 @@ module Jekyll def to_liquid { + "basename" => File.basename(name, extname), + "name" => name, "extname" => extname, "modified_time" => modified_time, "path" => File.join("", relative_path) diff --git a/site/_docs/static_files.md b/site/_docs/static_files.md index 00afbaec..19d45089 100644 --- a/site/_docs/static_files.md +++ b/site/_docs/static_files.md @@ -26,7 +26,7 @@ following metadata:

file.path

- The relative path to the file. + The relative path to the file, e.g /assets/img/image.jpg

@@ -34,7 +34,23 @@ following metadata:

file.modified_time

- The `Time` the file was last modified. + The `Time` the file was last modified, e.g 2016-04-01 16:35:26 +0200 + +

+ + +

file.name

+

+ + The string name of the file e.g. image.jpg for image.jpg + +

+ + +

file.basename

+

+ + The string basename of the file e.g. image for image.jpg

diff --git a/test/test_static_file.rb b/test/test_static_file.rb index 71b3f31c..bad40431 100644 --- a/test/test_static_file.rb +++ b/test/test_static_file.rb @@ -142,6 +142,8 @@ class TestStaticFile < JekyllUnitTest should "be able to convert to liquid" do expected = { + "basename" => "static_file", + "name" => "static_file.txt", "extname" => ".txt", "modified_time" => @static_file.modified_time, "path" => "/static_file.txt"