Skip to content

Commit

Permalink
Change variable names for clarity. See confusion at 11ty/eleventy#1153
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed May 17, 2020
1 parent e55c4bd commit d61b0ef
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions docs/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ You can use `eleventyConfig` like so:
```js
module.exports = function(eleventyConfig) {

eleventyConfig.addCollection("myCollectionName", function(collection) {
eleventyConfig.addCollection("myCollectionName", function(collectionApi) {
// get unsorted items
return collection.getAll();
return collectionApi.getAll();
});

};
Expand All @@ -291,8 +291,8 @@ Returns an array.
```js
module.exports = function(eleventyConfig) {
// Unsorted items (in whatever order they were added)
eleventyConfig.addCollection("allMyContent", function(collection) {
return collection.getAll();
eleventyConfig.addCollection("allMyContent", function(collectionApi) {
return collectionApi.getAll();
});
};
```
Expand All @@ -302,8 +302,8 @@ module.exports = function(eleventyConfig) {
```js
module.exports = function(eleventyConfig) {
// Filter using `Array.filter`
eleventyConfig.addCollection("keyMustExistInData", function(collection) {
return collection.getAll().filter(function(item) {
eleventyConfig.addCollection("keyMustExistInData", function(collectionApi) {
return collectionApi.getAll().filter(function(item) {
// Side-step tags and do your own filtering
return "myCustomDataKey" in item.data;
});
Expand All @@ -316,8 +316,8 @@ module.exports = function(eleventyConfig) {
```js
module.exports = function(eleventyConfig) {
// Sort with `Array.sort`
eleventyConfig.addCollection("myCustomSort", function(collection) {
return collection.getAll().sort(function(a, b) {
eleventyConfig.addCollection("myCustomSort", function(collectionApi) {
return collectionApi.getAll().sort(function(a, b) {
return b.date - a.date;
});
});
Expand All @@ -337,8 +337,8 @@ Returns an array.
```js
module.exports = function(eleventyConfig) {
// Use the default sorting algorithm (ascending by date, filename tiebreaker)
eleventyConfig.addCollection("allMySortedContent", function(collection) {
return collection.getAllSorted();
eleventyConfig.addCollection("allMySortedContent", function(collectionApi) {
return collectionApi.getAllSorted();
});
};
```
Expand All @@ -349,8 +349,8 @@ module.exports = function(eleventyConfig) {
module.exports = function(eleventyConfig) {
// Use the default sorting algorithm in reverse (descending dir, date, filename)
// Note that using a template engine’s `reverse` filter might be easier here
eleventyConfig.addCollection("myPostsReverse", function(collection) {
return collection.getAllSorted().reverse();
eleventyConfig.addCollection("myPostsReverse", function(collectionApi) {
return collectionApi.getAllSorted().reverse();
});
};
```
Expand All @@ -362,8 +362,8 @@ Note that while Array `.reverse()` mutates the array _in-place_, all Eleventy Co
```js
module.exports = function(eleventyConfig) {
// Filter using `Array.filter`
eleventyConfig.addCollection("onlyMarkdown", function(collection) {
return collection.getAllSorted().filter(function(item) {
eleventyConfig.addCollection("onlyMarkdown", function(collectionApi) {
return collectionApi.getAllSorted().filter(function(item) {
// Only return content that was originally a markdown file
let extension = item.inputPath.split('.').pop();
return extension === "md";
Expand All @@ -381,8 +381,8 @@ Returns an array.
```js
module.exports = function(eleventyConfig) {
// Get only content that matches a tag
eleventyConfig.addCollection("myPosts", function(collection) {
return collection.getFilteredByTag("post");
eleventyConfig.addCollection("myPosts", function(collectionApi) {
return collectionApi.getFilteredByTag("post");
});
};
```
Expand All @@ -396,8 +396,8 @@ Retrieve content that includes *all* of the tags passed in. Returns an array.
```js
module.exports = function(eleventyConfig) {
// Get only content that matches a tag
eleventyConfig.addCollection("myTravelPostsWithPhotos", function(collection) {
return collection.getFilteredByTags("post", "travel", "photo");
eleventyConfig.addCollection("myTravelPostsWithPhotos", function(collectionApi) {
return collectionApi.getFilteredByTags("post", "travel", "photo");
});
};
```
Expand All @@ -421,8 +421,8 @@ Returns an array. Will match an arbitrary glob (or an array of globs) against th
```js
module.exports = function(eleventyConfig) {
// Filter source file names using a glob
eleventyConfig.addCollection("onlyMarkdown", function(collection) {
return collection.getFilteredByGlob("**/*.md");
eleventyConfig.addCollection("onlyMarkdown", function(collectionApi) {
return collectionApi.getFilteredByGlob("**/*.md");
});
};
```
Expand All @@ -433,8 +433,8 @@ module.exports = function(eleventyConfig) {
```js
module.exports = function(eleventyConfig) {
// Filter source file names using a glob
eleventyConfig.addCollection("posts", function(collection) {
return collection.getFilteredByGlob("_posts/*.md");
eleventyConfig.addCollection("posts", function(collectionApi) {
return collectionApi.getFilteredByGlob("_posts/*.md");
});
};
```
Expand All @@ -445,9 +445,9 @@ module.exports = function(eleventyConfig) {
```js
module.exports = function(eleventyConfig) {
// Filter source file names using a glob
eleventyConfig.addCollection("posts", function(collection) {
eleventyConfig.addCollection("posts", function(collectionApi) {
// Also accepts an array of globs!
return collection.getFilteredByGlob(["posts/*.md", "notes/*.md"]);
return collectionApi.getFilteredByGlob(["posts/*.md", "notes/*.md"]);
});
};
```
Expand Down

0 comments on commit d61b0ef

Please sign in to comment.