diff --git a/docs/_docs/collections.md b/docs/_docs/collections.md index 39bd99eb..f0fed8ab 100644 --- a/docs/_docs/collections.md +++ b/docs/_docs/collections.md @@ -46,6 +46,17 @@ defaults: layout: page ``` +**New**: You can optionally specify a directory if you want to store all your collections +in the same place: + +```yaml +collections: + collections_dir: my_collections +``` + +Then Jekyll will look in `my_collections/_books` for the `books` collection, and +in `my_collections/_recipes` for the `recipes` collection. + ### Step 2: Add your content {#step2} Create a corresponding folder (e.g. `/_my_collection`) and add @@ -111,7 +122,7 @@ _my_collection/ each of the following `permalink` configurations will produce the document structure shown below it. -* **Default** +* **Default** Same as `permalink: /:collection/:path`. ``` @@ -121,7 +132,7 @@ each of the following `permalink` configurations will produce the document struc │   └── some_doc.html ... ``` -* `permalink: pretty` +* `permalink: pretty` Same as `permalink: /:collection/:path/`. ``` @@ -225,7 +236,7 @@ each of the following `permalink` configurations will produce the document struc Each collection is accessible as a field on the `site` variable. For example, if you want to access the `albums` collection found in `_albums`, you'd use -`site.albums`. +`site.albums`. Each collection is itself an array of documents (e.g., `site.albums` is an array of documents, much like `site.pages` and `site.posts`). See the table below for how to access attributes of those documents. @@ -310,10 +321,10 @@ you specified in your `_config.yml` (if present) and the following information:
A Hard-Coded Collection
-

In addition to any collections you create yourself, the - posts collection is hard-coded into Jekyll. It exists whether - you have a _posts directory or not. This is something to note - when iterating through site.collections as you may need to +

In addition to any collections you create yourself, the + posts collection is hard-coded into Jekyll. It exists whether + you have a _posts directory or not. This is something to note + when iterating through site.collections as you may need to filter it out.

You may wish to use filters to find your collection: {% raw %}{{ site.collections | where: "label", "myCollection" | first }}{% endraw %}

diff --git a/docs/_docs/configuration.md b/docs/_docs/configuration.md index 6d74fdbb..0d9c8f72 100644 --- a/docs/_docs/configuration.md +++ b/docs/_docs/configuration.md @@ -602,12 +602,13 @@ file or on the command-line. ```yaml # Where things are -source: . -destination: ./_site -plugins_dir: _plugins -layouts_dir: _layouts -data_dir: _data -includes_dir: _includes +source: . +destination: ./_site +collections_dir: . +plugins_dir: _plugins +layouts_dir: _layouts +data_dir: _data +includes_dir: _includes collections: posts: output: true diff --git a/lib/jekyll/collection.rb b/lib/jekyll/collection.rb index ebafea38..4a3a70f6 100644 --- a/lib/jekyll/collection.rb +++ b/lib/jekyll/collection.rb @@ -100,7 +100,9 @@ module Jekyll # Returns a String containing the directory name where the collection # is stored on the filesystem. def relative_directory - @relative_directory ||= "_#{label}" + @relative_directory ||= Pathname.new(directory).relative_path_from( + Pathname.new(site.source) + ).to_s end # The full path to the directory containing the collection. @@ -108,7 +110,9 @@ module Jekyll # Returns a String containing th directory name where the collection # is stored on the filesystem. def directory - @directory ||= site.in_source_dir(relative_directory) + @directory ||= site.in_source_dir( + File.join(site.config["collections_dir"], "_#{label}") + ) end # The full path to the directory containing the collection, with diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 7fbe15cf..5c502d68 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -8,6 +8,7 @@ module Jekyll # Where things are "source" => Dir.pwd, "destination" => File.join(Dir.pwd, "_site"), + "collections_dir" => "", "plugins_dir" => "_plugins", "layouts_dir" => "_layouts", "data_dir" => "_data",