Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection relative paths #3723

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/jekyll/collection.rb
Expand Up @@ -81,7 +81,7 @@ def filtered_entries
# Returns a String containing the directory name where the collection
# is stored on the filesystem.
def relative_directory
@relative_directory ||= "_#{label}"
@relative_directory ||= (metadata['relative_directory'] && site.in_source_dir(metadata['relative_directory']) || "_#{label}")
end

# The full path to the directory containing the collection.
Expand Down
12 changes: 12 additions & 0 deletions site/_docs/collections.md
Expand Up @@ -63,6 +63,18 @@ your <code>_config.yml</code> file, with the addition of the preceding <code>_</
</p>
</div>

Alternatively, you can place your collection folder wherever you like, and specify the path to this folder in the collection's metadata under `relative_directory`:

{% highlight yaml %}
collections:
my_collection:
relative_directory: path/to/my/collection
{% endhighlight %}

In the above example, the collection would be located at `<source>/path/to/my/collection` instead of `<source>/_my_collection`.
Note that even though the collection folder is named `collection`, the name of the collection is still that provided in the metadata (`my_collection`).
The files of the collection are still written out to `<dest>/my_collection/` as before.

### Step 3: Optionally render your collection's documents into independent files

If you'd like Jekyll to create a public-facing, rendered version of each
Expand Down
31 changes: 31 additions & 0 deletions test/test_collections.rb
@@ -1,6 +1,37 @@
require 'helper'

class TestCollections < JekyllUnitTest
context "a collection in a subfolder" do
setup do
@site = fixture_site({
"collections" => {
"methods" => {
"relative_directory" => "_methods/site"
}
}
})
@site.process
@collection = @site.collections["methods"]

should "create a collection with label 'methods'" do
refute_nil @site.collections["methods"]
assert_equal @site.collections["methods"].label, "methods"
end
should "have a relative path equal to that in the metadata" do
assert_equal @collection.relative_directory, "_methods/site"
end
should "be a collection of the files in the relative directory" do
assert_equal 2, @collection.docs.size
@site.collections["methods"].docs.each do |doc|
assert_includes %w[
_methods/site/generate.md
_methods/site/initialize.md
], doc.relative_path
end
end
end
end

context "an evil collection" do
setup do
@collection = Jekyll::Collection.new(fixture_site, "../../etc/password")
Expand Down