Skip to content

Commit

Permalink
Allow provided collections to be overridden in user config
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Jan 2, 2025
1 parent a2ccd9e commit 46c8c6b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
13 changes: 3 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { EleventyHtmlBasePlugin } = require('@11ty/eleventy')

const addCollections = require('./lib/collections/index.js')

module.exports = function (eleventyConfig, pluginOptions = {}) {
const { pathPrefix } = eleventyConfig

Expand All @@ -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'))
Expand Down
2 changes: 1 addition & 1 deletion layouts/sub-navigation.njk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-one-quarter-from-desktop">
{{ 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 })
}) }}
</div>
<div class="govuk-grid-column-three-quarters-from-desktop">
Expand Down
17 changes: 17 additions & 0 deletions lib/collections/index.js
Original file line number Diff line number Diff line change
@@ -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'))
}
}
File renamed without changes.

0 comments on commit 46c8c6b

Please sign in to comment.