diff --git a/features/collections.feature b/features/collections.feature
index 5c75677f..4f69e8b9 100644
--- a/features/collections.feature
+++ b/features/collections.feature
@@ -29,6 +29,20 @@ Feature: Collections
And I should see "Methods metadata: bar" in "_site/collection_metadata.html"
And I should see "
Whatever: foo.bar
" in "_site/methods/configuration.html"
+ Scenario: Rendered collection at a custom URL
+ Given I have an "index.html" page that contains "Collections: {{ site.collections }}"
+ And I have fixture collections
+ And I have a "_config.yml" file with content:
+ """
+ collections:
+ methods:
+ output: true
+ permalink: /:collection/:path/
+ """
+ When I run jekyll build
+ Then the _site directory should exist
+ And I should see "Whatever: foo.bar
" in "_site/methods/configuration/index.html"
+
Scenario: Rendered document in a layout
Given I have an "index.html" page that contains "Collections: {{ site.collections }}"
And I have a default layout that contains "Tom Preston-Werner
{{content}}"
diff --git a/lib/jekyll/collection.rb b/lib/jekyll/collection.rb
index dcb7b50d..03474582 100644
--- a/lib/jekyll/collection.rb
+++ b/lib/jekyll/collection.rb
@@ -132,6 +132,13 @@ module Jekyll
!!metadata['output']
end
+ # The URL template to render collection's documents at.
+ #
+ # Returns the URL template to render collection's documents at.
+ def url_template
+ metadata.fetch('permalink', "/:collection/:path:output_ext")
+ end
+
# Extract options for this collection from the site configuration.
#
# Returns the metadata for this collection
diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb
index be4ead20..50aeaa14 100644
--- a/lib/jekyll/document.rb
+++ b/lib/jekyll/document.rb
@@ -92,7 +92,7 @@ module Jekyll
#
# Returns the URL template for the document.
def url_template
- "/:collection/:path:output_ext"
+ collection.url_template
end
# Construct a Hash of key-value pairs which contain a mapping between
diff --git a/site/docs/collections.md b/site/docs/collections.md
index 1cbd5d02..1d3a14e5 100644
--- a/site/docs/collections.md
+++ b/site/docs/collections.md
@@ -56,6 +56,54 @@ For example, if you have `_my_collection/some_subdir/some_doc.md`,
it will be rendered using Liquid and the Markdown converter of your
choice and written out to `/my_collection/some_subdir/some_doc.html`.
+As for posts with [Permalinks](../Permalinks/), document URL can be customized by setting a `permalink` metadata to the collection:
+
+{% highlight yaml %}
+collections:
+ my_collection:
+ output: true
+ permalink: /awesome/:path/
+{% endhighlight %}
+
+For example, if you have `_my_collection/some_subdir/some_doc.md`, it will be written out to `/awesome/some_subdir/some_doc/index.html`.
+
+
+
## Liquid Attributes
### Collections
diff --git a/test/test_collections.rb b/test/test_collections.rb
index eb8a7e32..6cdb3184 100644
--- a/test/test_collections.rb
+++ b/test/test_collections.rb
@@ -38,6 +38,10 @@ class TestCollections < Test::Unit::TestCase
assert_equal @collection.label, "methods"
end
+ should "have default url template" do
+ assert_equal @collection.url_template, "/:collection/:path:output_ext"
+ end
+
should "contain no docs when initialized" do
assert_empty @collection.docs
end
@@ -91,6 +95,24 @@ class TestCollections < Test::Unit::TestCase
end
end
+ context "a collection with permalink" do
+ setup do
+ @site = fixture_site({
+ "collections" => {
+ "methods" => {
+ "permalink" => "/awesome/:path/"
+ }
+ }
+ })
+ @site.process
+ @collection = @site.collections["methods"]
+ end
+
+ should "have custom url template" do
+ assert_equal @collection.url_template, "/awesome/:path/"
+ end
+ end
+
context "with a collection" do
setup do
@site = fixture_site({