Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow provided collections to be overridden in a user’s configuration #361

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading