Skip to content

Commit

Permalink
props @DirtyF: handle static files in a collection
Browse files Browse the repository at this point in the history
Static files within a collection inside a custom collections_dir needs
to output to the same path as when the collection is at the root of the
source directory.
  • Loading branch information
ashmaroli committed Jan 15, 2018
1 parent 39d0bad commit 2af6834
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions features/collections_dir.feature
Expand Up @@ -144,6 +144,9 @@ Feature: Collections Directory
collections_dir: gathering
"""
And I have a "gathering/_puppies/static_file.txt" file that contains "Static content."
And I have a gathering/_puppies/nested directory
And I have a "gathering/_puppies/nested/static_file.txt" file that contains "Nested Static content."
When I run jekyll build --drafts
Then I should get a zero exit status
And the _site directory should exist
Expand All @@ -152,5 +155,7 @@ Feature: Collections Directory
And the "_site/2009/03/27/draft-in-gathering.html" file should exist
And the "_site/2009/03/27/draft-at-root.html" file should not exist
And the "_site/puppies/rover-at-root.html" file should not exist
And I should see exactly "Static content." in "_site/puppies/static_file.txt"
And I should see exactly "Nested Static content." in "_site/puppies/nested/static_file.txt"
And the _site/gathering directory should not exist
And the _site/_posts directory should not exist
7 changes: 6 additions & 1 deletion lib/jekyll/static_file.rb
Expand Up @@ -40,7 +40,12 @@ def initialize(site, base, dir, name, collection = nil)

# Returns source file path.
def path
File.join(*[@base, @dir, @name].compact)
# Static file is from a collection inside custom collections directory
if !@collection.nil? && !@site.config["collections_dir"].empty?
File.join(*[@base, @site.config["collections_dir"], @dir, @name].compact)
else
File.join(*[@base, @dir, @name].compact)
end
end

# Obtain destination path.
Expand Down

0 comments on commit 2af6834

Please sign in to comment.