Allow the user to set collections_dir to put all collections under one subdirectory (#6331)

Merge pull request 6331
This commit is contained in:
Parker Moore 2017-09-24 11:50:55 -04:00 committed by jekyllbot
parent 6f3d7a0034
commit 0331fb41ad
4 changed files with 32 additions and 15 deletions

View File

@ -46,6 +46,17 @@ defaults:
layout: page 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} ### Step 2: Add your content {#step2}
Create a corresponding folder (e.g. `<source>/_my_collection`) and add Create a corresponding folder (e.g. `<source>/_my_collection`) and add

View File

@ -602,12 +602,13 @@ file or on the command-line.
```yaml ```yaml
# Where things are # Where things are
source: . source: .
destination: ./_site destination: ./_site
plugins_dir: _plugins collections_dir: .
layouts_dir: _layouts plugins_dir: _plugins
data_dir: _data layouts_dir: _layouts
includes_dir: _includes data_dir: _data
includes_dir: _includes
collections: collections:
posts: posts:
output: true output: true

View File

@ -100,7 +100,9 @@ module Jekyll
# Returns a String containing the directory name where the collection # Returns a String containing the directory name where the collection
# is stored on the filesystem. # is stored on the filesystem.
def relative_directory def relative_directory
@relative_directory ||= "_#{label}" @relative_directory ||= Pathname.new(directory).relative_path_from(
Pathname.new(site.source)
).to_s
end end
# The full path to the directory containing the collection. # 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 # Returns a String containing th directory name where the collection
# is stored on the filesystem. # is stored on the filesystem.
def directory def directory
@directory ||= site.in_source_dir(relative_directory) @directory ||= site.in_source_dir(
File.join(site.config["collections_dir"], "_#{label}")
)
end end
# The full path to the directory containing the collection, with # The full path to the directory containing the collection, with

View File

@ -8,6 +8,7 @@ module Jekyll
# Where things are # Where things are
"source" => Dir.pwd, "source" => Dir.pwd,
"destination" => File.join(Dir.pwd, "_site"), "destination" => File.join(Dir.pwd, "_site"),
"collections_dir" => "",
"plugins_dir" => "_plugins", "plugins_dir" => "_plugins",
"layouts_dir" => "_layouts", "layouts_dir" => "_layouts",
"data_dir" => "_data", "data_dir" => "_data",