Merge pull request #3596 from jekyll/static-files-upgrade

Merge pull request 3596
This commit is contained in:
Parker Moore 2015-04-14 12:52:36 -07:00
commit 3aaa889218
8 changed files with 78 additions and 19 deletions

View File

@ -18,7 +18,7 @@ module Jekyll
@name = name @name = name
@collection = collection @collection = collection
@relative_path = File.join(*[@dir, @name].compact) @relative_path = File.join(*[@dir, @name].compact)
@extname = File.extname(@relative_path) @extname = File.extname(@name)
end end
# Returns source file path. # Returns source file path.
@ -43,9 +43,13 @@ module Jekyll
end end
end end
def modified_time
@modified_time ||= File.stat(path).mtime
end
# Returns last modification time for this file. # Returns last modification time for this file.
def mtime def mtime
File.stat(path).mtime.to_i modified_time.to_i
end end
# Is source path modified? # Is source path modified?
@ -91,9 +95,9 @@ module Jekyll
def to_liquid def to_liquid
{ {
"path" => File.join("", relative_path), "extname" => extname,
"modified_time" => mtime.to_s, "modified_time" => modified_time,
"extname" => extname "path" => File.join("", relative_path)
} }
end end
end end

View File

@ -13,6 +13,7 @@
- posts - posts
- drafts - drafts
- pages - pages
- static-files
- variables - variables
- collections - collections
- datafiles - datafiles

View File

@ -96,9 +96,9 @@ written out to `<dest>/awesome/some_subdir/some_doc/index.html`.
<div class="note info"> <div class="note info">
<h5>Don't forget to add YAML for processing</h5> <h5>Don't forget to add YAML for processing</h5>
<p> <p>
Files in collections that do not have front matter are treated Files in collections that do not have front matter are treated as
as static files and simply copied to their output location without <a href="/docs/static-files">static files</a> and simply copied to their
processing. output location without processing.
</p> </p>
</div> </div>

View File

@ -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:
<div class="mobile-side-scroller">
<table>
<thead>
<tr>
<th>Variable</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><p><code>file.path</code></p></td>
<td><p>
The relative path to the file.
</p></td>
</tr>
<tr>
<td><p><code>file.modified_time</code></p></td>
<td><p>
The `Time` the file was last modified.
</p></td>
</tr>
<tr>
<td><p><code>file.extname</code></p></td>
<td><p>
The extension name for the file, e.g.
<code>.jpg</code> for <code>image.jpg</code>
</p></td>
</tr>
</tbody>
</table>
</div>

View File

@ -114,9 +114,10 @@ following is a reference of the available data.
<td><p><code>site.static_files</code></p></td> <td><p><code>site.static_files</code></p></td>
<td><p> <td><p>
A list of all static files (i.e. files not processed by Jekyll's A list of all <a href="/docs/static-files/">static files</a> (i.e.
converters or the Liquid renderer). Each file has three properties: files not processed by Jekyll's converters or the Liquid renderer).
<code>path</code>, <code>modified_time</code> and <code>extname</code>. Each file has three properties: <code>path</code>,
<code>modified_time</code> and <code>extname</code>.
</p></td> </p></td>
</tr> </tr>

View File

@ -1,4 +1,4 @@
--- ---
--- ---
{% for file in site.static_files %} {% 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 %}

View File

@ -44,11 +44,12 @@ class TestGeneratedSite < JekyllUnitTest
end end
should "print a nice list of static files" do should "print a nice list of static files" do
time_regexp = "\\d+:\\d+"
expected_output = Regexp.new <<-OUTPUT expected_output = Regexp.new <<-OUTPUT
- /css/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 \\d+ with extname .key - /pgp.key last edited at #{time_regexp} with extname .key
- /products.yml last edited at \\d+ with extname .yml - /products.yml last edited at #{time_regexp} with extname .yml
- /symlink-test/symlinked-dir/screen.css last edited at \\d+ with extname .css - /symlink-test/symlinked-dir/screen.css last edited at #{time_regexp} with extname .css
OUTPUT OUTPUT
assert_match expected_output, File.read(dest_dir('static_files.html')) assert_match expected_output, File.read(dest_dir('static_files.html'))
end end

View File

@ -75,9 +75,9 @@ class TestStaticFile < JekyllUnitTest
should "be able to convert to liquid" do should "be able to convert to liquid" do
expected = { expected = {
"path" => "/static_file.txt", "extname" => ".txt",
"modified_time" => @static_file.mtime.to_s, "modified_time" => @static_file.modified_time,
"extname" => ".txt" "path" => "/static_file.txt",
} }
assert_equal expected, @static_file.to_liquid assert_equal expected, @static_file.to_liquid
end end