From d61b0ef9089bcc478ac5d689f314658edeb77828 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Sat, 16 May 2020 19:53:52 -0500 Subject: [PATCH] Change variable names for clarity. See confusion at https://github.com/11ty/eleventy/issues/1153 --- docs/collections.md | 48 ++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/collections.md b/docs/collections.md index 09c5b0274f..1edc8c2fb7 100644 --- a/docs/collections.md +++ b/docs/collections.md @@ -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(); }); }; @@ -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(); }); }; ``` @@ -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; }); @@ -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; }); }); @@ -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(); }); }; ``` @@ -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(); }); }; ``` @@ -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"; @@ -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"); }); }; ``` @@ -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"); }); }; ``` @@ -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"); }); }; ``` @@ -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"); }); }; ``` @@ -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"]); }); }; ```