Merge pull request #3596 from jekyll/static-files-upgrade
Merge pull request 3596
This commit is contained in:
commit
3aaa889218
|
@ -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
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
- posts
|
||||
- drafts
|
||||
- pages
|
||||
- static-files
|
||||
- variables
|
||||
- collections
|
||||
- datafiles
|
||||
|
|
|
@ -96,9 +96,9 @@ written out to `<dest>/awesome/some_subdir/some_doc/index.html`.
|
|||
<div class="note info">
|
||||
<h5>Don't forget to add YAML for processing</h5>
|
||||
<p>
|
||||
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
|
||||
<a href="/docs/static-files">static files</a> and simply copied to their
|
||||
output location without processing.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -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>
|
|
@ -114,9 +114,10 @@ following is a reference of the available data.
|
|||
<td><p><code>site.static_files</code></p></td>
|
||||
<td><p>
|
||||
|
||||
A list of all static files (i.e. files not processed by Jekyll's
|
||||
converters or the Liquid renderer). Each file has three properties:
|
||||
<code>path</code>, <code>modified_time</code> and <code>extname</code>.
|
||||
A list of all <a href="/docs/static-files/">static files</a> (i.e.
|
||||
files not processed by Jekyll's converters or the Liquid renderer).
|
||||
Each file has three properties: <code>path</code>,
|
||||
<code>modified_time</code> and <code>extname</code>.
|
||||
|
||||
</p></td>
|
||||
</tr>
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue