diff --git a/lib/jekyll/static_file.rb b/lib/jekyll/static_file.rb index 0ab88cbd..454f1247 100644 --- a/lib/jekyll/static_file.rb +++ b/lib/jekyll/static_file.rb @@ -18,7 +18,7 @@ module Jekyll @name = name @collection = collection @relative_path = File.join(*[@dir, @name].compact) - @extname = File.extname(@relative_path) + @extname = File.extname(@name) end # Returns source file path. @@ -43,9 +43,13 @@ module Jekyll end end + def modified_time + @modified_time ||= File.stat(path).mtime + end + # Returns last modification time for this file. def mtime - File.stat(path).mtime.to_i + modified_time.to_i end # Is source path modified? @@ -91,9 +95,9 @@ module Jekyll def to_liquid { - "path" => File.join("", relative_path), - "modified_time" => mtime.to_s, - "extname" => extname + "extname" => extname, + "modified_time" => modified_time, + "path" => File.join("", relative_path) } end end diff --git a/site/_data/docs.yml b/site/_data/docs.yml index 474f73fa..bcdf352d 100644 --- a/site/_data/docs.yml +++ b/site/_data/docs.yml @@ -13,6 +13,7 @@ - posts - drafts - pages + - static-files - variables - collections - datafiles diff --git a/site/_docs/collections.md b/site/_docs/collections.md index 9f7c6be5..e55378af 100644 --- a/site/_docs/collections.md +++ b/site/_docs/collections.md @@ -96,9 +96,9 @@ written out to `/awesome/some_subdir/some_doc/index.html`.
Don't forget to add YAML for processing

-Files in collections that do not have front matter are treated -as static files and simply copied to their output location without -processing. + Files in collections that do not have front matter are treated as + static files and simply copied to their + output location without processing.

diff --git a/site/_docs/static_files.md b/site/_docs/static_files.md new file mode 100644 index 00000000..00afbaec --- /dev/null +++ b/site/_docs/static_files.md @@ -0,0 +1,52 @@ +--- +layout: docs +title: Static Files +permalink: /docs/static-files/ +--- + +In addition to renderable and convertible content, we also have **static +files**. + +A static file is a file that does not contain any YAML front matter. These +include images, PDFs, and other un-rendered content. + +They're accessible in Liquid via `site.static_files` and contain the +following metadata: + +
+ + + + + + + + + + + + + + + + + + + + + +
VariableDescription

file.path

+ + The relative path to the file. + +

file.modified_time

+ + The `Time` the file was last modified. + +

file.extname

+ + The extension name for the file, e.g. + .jpg for image.jpg + +

+
diff --git a/site/_docs/variables.md b/site/_docs/variables.md index 11ff633b..d3c5d946 100644 --- a/site/_docs/variables.md +++ b/site/_docs/variables.md @@ -114,9 +114,10 @@ following is a reference of the available data.

site.static_files

- A list of all static files (i.e. files not processed by Jekyll's - converters or the Liquid renderer). Each file has three properties: - path, modified_time and extname. + A list of all static files (i.e. + files not processed by Jekyll's converters or the Liquid renderer). + Each file has three properties: path, + modified_time and extname.

diff --git a/test/source/static_files.html b/test/source/static_files.html index 878b7ebe..fb0786a7 100644 --- a/test/source/static_files.html +++ b/test/source/static_files.html @@ -1,4 +1,4 @@ --- --- {% for file in site.static_files %} -- {{ file.path }} last edited at {{ file.modified_time }} with extname {{ file.extname }}{% endfor %} +- {{ file.path }} last edited at {{ file.modified_time | date:"%H:%m" }} with extname {{ file.extname }}{% endfor %} diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index b3fe811f..88e0fe9e 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -44,11 +44,12 @@ class TestGeneratedSite < JekyllUnitTest end should "print a nice list of static files" do + time_regexp = "\\d+:\\d+" expected_output = Regexp.new <<-OUTPUT -- /css/screen.css last edited at \\d+ with extname .css -- /pgp.key last edited at \\d+ with extname .key -- /products.yml last edited at \\d+ with extname .yml -- /symlink-test/symlinked-dir/screen.css last edited at \\d+ with extname .css +- /css/screen.css last edited at #{time_regexp} with extname .css +- /pgp.key last edited at #{time_regexp} with extname .key +- /products.yml last edited at #{time_regexp} with extname .yml +- /symlink-test/symlinked-dir/screen.css last edited at #{time_regexp} with extname .css OUTPUT assert_match expected_output, File.read(dest_dir('static_files.html')) end diff --git a/test/test_static_file.rb b/test/test_static_file.rb index 97206263..3285f952 100644 --- a/test/test_static_file.rb +++ b/test/test_static_file.rb @@ -75,9 +75,9 @@ class TestStaticFile < JekyllUnitTest should "be able to convert to liquid" do expected = { - "path" => "/static_file.txt", - "modified_time" => @static_file.mtime.to_s, - "extname" => ".txt" + "extname" => ".txt", + "modified_time" => @static_file.modified_time, + "path" => "/static_file.txt", } assert_equal expected, @static_file.to_liquid end