diff --git a/index.js b/index.js index c7ecd5c..df07487 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,7 @@ const { EleventyHtmlBasePlugin } = require('@11ty/eleventy') +const addCollections = require('./lib/collections/index.js') + module.exports = function (eleventyConfig, pluginOptions = {}) { const { pathPrefix } = eleventyConfig @@ -11,16 +13,7 @@ module.exports = function (eleventyConfig, pluginOptions = {}) { eleventyConfig.setLibrary('njk', require('./lib/nunjucks.js')(eleventyConfig)) // Collections - eleventyConfig.addCollection('all', require('./lib/collections/all.js')) - eleventyConfig.addCollection( - 'ordered', - require('./lib/collections/ordered.js') - ) - eleventyConfig.addCollection( - 'sitemap', - require('./lib/collections/sitemap.js') - ) - eleventyConfig.addCollection('tags', require('./lib/collections/tags.js')) + addCollections(eleventyConfig) // Extensions and template formats eleventyConfig.addExtension('scss', require('./lib/extensions/scss.js')) diff --git a/layouts/sub-navigation.njk b/layouts/sub-navigation.njk index 5fd2567..2462ed9 100644 --- a/layouts/sub-navigation.njk +++ b/layouts/sub-navigation.njk @@ -11,7 +11,7 @@
{{ xGovukSubNavigation({ - items: collections.ordered | eleventyNavigation(sectionKey or options.homeKey) | itemsFromNavigation(page.url, { pathPrefix: options.pathPrefix }) + items: collections.navigation | eleventyNavigation(sectionKey or options.homeKey) | itemsFromNavigation(page.url, { pathPrefix: options.pathPrefix }) }) }}
diff --git a/lib/collections/index.js b/lib/collections/index.js new file mode 100644 index 0000000..c379518 --- /dev/null +++ b/lib/collections/index.js @@ -0,0 +1,17 @@ +module.exports = function (eleventyConfig) { + if (!eleventyConfig.collections.all) { + eleventyConfig.addCollection('all', require('./all.js')) + } + + if (!eleventyConfig.collections.navigation) { + eleventyConfig.addCollection('navigation', require('./navigation.js')) + } + + if (!eleventyConfig.collections.sitemap) { + eleventyConfig.addCollection('sitemap', require('./sitemap.js')) + } + + if (!eleventyConfig.collections.tag) { + eleventyConfig.addCollection('tags', require('./tags.js')) + } +} diff --git a/lib/collections/ordered.js b/lib/collections/navigation.js similarity index 100% rename from lib/collections/ordered.js rename to lib/collections/navigation.js