diff --git a/eleventy.config.js b/eleventy.config.js index d758415d..9a655c48 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -1,4 +1,5 @@ const process = require('node:process') + const rssPlugin = require('@11ty/eleventy-plugin-rss') module.exports = function (eleventyConfig) { diff --git a/lib/collections/ordered.js b/lib/collections/ordered.js index c4189946..2674dbe3 100644 --- a/lib/collections/ordered.js +++ b/lib/collections/ordered.js @@ -9,10 +9,14 @@ module.exports = (collection) => ) { // Sort by order value, if given return (a.data.order || 0) - (b.data.order || 0) - } else { - // Sort by title - if (a.data.title < b.data.title) return -1 - else if (a.data.title > b.data.title) return 1 - else return 0 } + + // Sort by title + if (a.data.title < b.data.title) { + return -1 + } else if (a.data.title > b.data.title) { + return 1 + } + + return 0 }) diff --git a/lib/collections/tags.js b/lib/collections/tags.js index ec34e9ae..d0493e87 100644 --- a/lib/collections/tags.js +++ b/lib/collections/tags.js @@ -7,22 +7,20 @@ module.exports = (collection) => { // Add any new tags from the post to the array for (const tag of item.data.tags) { // Skip if tag already added - if (tags.includes(tag)) { - continue - } - - // Check there’s not a matching tag, except for capitalisation - const existingTag = tags.find( - (existingTag) => existingTag.toLowerCase() === tag.toLowerCase() - ) - if (existingTag) { - throw new Error( - `The post ‘${item.data.title}’ contains tag ‘${tag}’ which matches ‘${existingTag}’, but the capitalisation is different.` + if (!tags.includes(tag)) { + // Check there’s not a matching tag, except for capitalisation + const existingTag = tags.find( + (existingTag) => existingTag.toLowerCase() === tag.toLowerCase() ) - } + if (existingTag) { + throw new Error( + `The post ‘${item.data.title}’ contains tag ‘${tag}’ which matches ‘${existingTag}’, but the capitalisation is different.` + ) + } - // Otherwise add new tag - tags.push(tag) + // Otherwise add new tag + tags.push(tag) + } } } } diff --git a/lib/data/eleventy-computed.js b/lib/data/eleventy-computed.js index 51e98c9e..30ad2bc5 100644 --- a/lib/data/eleventy-computed.js +++ b/lib/data/eleventy-computed.js @@ -1,6 +1,7 @@ /** * Get navigation key for page - * @param {object} data Page data + * + * @param {object} data - Page data * @returns {string|undefined} Page navigation key */ const getKey = (data) => { @@ -17,7 +18,8 @@ const getKey = (data) => { /** * Get navigation parent for page - * @param {object} data Page data + * + * @param {object} data - Page data * @returns {string|undefined} Parent page key */ const getParent = (data) => { @@ -34,6 +36,7 @@ const getParent = (data) => { /** * Set sensible defaults for eleventyNavigation + * * @see {@link https://www.11ty.dev/docs/plugins/navigation/} */ module.exports = { diff --git a/lib/data/options.js b/lib/data/options.js index 761754ee..2de23479 100644 --- a/lib/data/options.js +++ b/lib/data/options.js @@ -2,6 +2,7 @@ const deepmerge = require('deepmerge') /** * Default option values + * * @see {@link https://x-govuk.github.io/govuk-eleventy-plugin/options/} */ const defaultOptions = { diff --git a/lib/events/generate-govuk-assets.js b/lib/events/generate-govuk-assets.js index 42f01630..d2ede1d7 100644 --- a/lib/events/generate-govuk-assets.js +++ b/lib/events/generate-govuk-assets.js @@ -1,13 +1,16 @@ -const path = require('node:path') const fs = require('node:fs/promises') -const sass = require('sass') -const rollup = require('rollup') +const path = require('node:path') + const commonJs = require('@rollup/plugin-commonjs') const { nodeResolve } = require('@rollup/plugin-node-resolve') +const rollup = require('rollup') +const sass = require('sass') + const { getScssSettings } = require('../utils.js') /** * Generate GOV.UK Frontend assets + * * @param {object} dir - Project directories * @param {object} pathPrefix - Path prefix * @param {object} options - Plugin options diff --git a/lib/extensions/scss.js b/lib/extensions/scss.js index fe826294..ae31ddf2 100644 --- a/lib/extensions/scss.js +++ b/lib/extensions/scss.js @@ -1,4 +1,5 @@ const path = require('node:path') + const sass = require('sass') module.exports = { diff --git a/lib/filters/canonical-url.js b/lib/filters/canonical-url.js index c9a242ee..cdcd67be 100644 --- a/lib/filters/canonical-url.js +++ b/lib/filters/canonical-url.js @@ -2,6 +2,7 @@ const path = require('node:path') /** * Get canonical site URL with resolved path + * * @param {string} string - Path to resolve * @returns {string} Canonical site URL with resolved path */ diff --git a/lib/filters/current-page.js b/lib/filters/current-page.js index 90d1fa63..f261a3ae 100644 --- a/lib/filters/current-page.js +++ b/lib/filters/current-page.js @@ -1,5 +1,6 @@ /** * Indicate which is the current item in navigation items + * * @param {Array} array - Navigation items * @param {string} pageUrl - URL of current page * @returns {Array} Navigation items diff --git a/lib/filters/date.js b/lib/filters/date.js index fd3110ff..e4896629 100644 --- a/lib/filters/date.js +++ b/lib/filters/date.js @@ -2,6 +2,7 @@ const { DateTime } = require('luxon') /** * Format a data using tokens + * * @param {string} string - Date to convert * @param {string} [format] - Optional token-based formatting * @returns {string} Formatted date diff --git a/lib/filters/includes.js b/lib/filters/includes.js index b44f3766..42ed2ef2 100644 --- a/lib/filters/includes.js +++ b/lib/filters/includes.js @@ -1,8 +1,9 @@ /** * Select objects in array whose key includes a value - * @param {Array} array Array to filter - * @param {string} keyPath Key to inspect - * @param {string} value Value key needs to include + * + * @param {Array} array - Array to filter + * @param {string} keyPath - Key to inspect + * @param {string} value - Value key needs to include * @returns {Array} Filtered array */ module.exports = (array, keyPath, value) => diff --git a/lib/filters/items-from-collection.js b/lib/filters/items-from-collection.js index e9dcea20..1f305958 100644 --- a/lib/filters/items-from-collection.js +++ b/lib/filters/items-from-collection.js @@ -3,6 +3,7 @@ const smart = require('./smart.js') /** * Transform list of posts in a collection to `items` array that can be * consumed by GOV.UK Frontend components + * * @param {Array} array - Eleventy collection data * @returns {Array} `items` array */ diff --git a/lib/filters/items-from-navigation.js b/lib/filters/items-from-navigation.js index 957ac7cb..73d3930f 100644 --- a/lib/filters/items-from-navigation.js +++ b/lib/filters/items-from-navigation.js @@ -3,6 +3,7 @@ const smart = require('./smart.js') /** * Transform Eleventy navigation data to `items` array that can be * consumed by GOV.UK Frontend `govukBreadcrumb` component + * * @param {Array} eleventyNavigation - Eleventy navigation data * @param {string} [pageUrl] - URL of current page * @param {object} [options] - Plugin options diff --git a/lib/filters/items-from-pagination.js b/lib/filters/items-from-pagination.js index f982ae3c..282bca78 100644 --- a/lib/filters/items-from-pagination.js +++ b/lib/filters/items-from-pagination.js @@ -1,6 +1,7 @@ /** * Transform Eleventy pagination data to `items` array that can be * consumed by GOV.UK Frontend `govukPagination` component + * * @param {Array} pagination - Eleventy pagination data * @returns {Array} `items` array */ diff --git a/lib/filters/markdown.js b/lib/filters/markdown.js index 6377594c..1e8ab3d0 100644 --- a/lib/filters/markdown.js +++ b/lib/filters/markdown.js @@ -3,6 +3,7 @@ const { normalise } = require('../utils.js') /** * Convert Markdown into GOV.UK Frontend-compliant HTML + * * @param {string} string - Markdown string * @param {string} value - If `inline`, renders HTML without paragraph tags * @returns {string} HTML diff --git a/lib/filters/no-orphans.js b/lib/filters/no-orphans.js index 0259612c..5c68fa37 100644 --- a/lib/filters/no-orphans.js +++ b/lib/filters/no-orphans.js @@ -3,6 +3,7 @@ const { normalise } = require('../utils.js') /** * Insert non-breaking space between last two words of a string. This prevents * an orphaned word appearing by itself at the end of a paragraph. + * * @param {string} string - Value to transform * @returns {string} `string` with non-breaking space inserted * @example diff --git a/lib/filters/pretty.js b/lib/filters/pretty.js index a05dc729..0915037f 100644 --- a/lib/filters/pretty.js +++ b/lib/filters/pretty.js @@ -1,5 +1,6 @@ /** * Remove (index).html from a string + * * @see {@link https://www.w3.org/Provider/Style/URI.html} * @param {string} string - URL, i.e. /page/index.html * @returns {string} Permalink URL, i.e. /page/ diff --git a/lib/filters/smart.js b/lib/filters/smart.js index 7d7f1bbb..cbdc42fb 100644 --- a/lib/filters/smart.js +++ b/lib/filters/smart.js @@ -1,8 +1,10 @@ -const { normalise } = require('../utils.js') const smartypants = require('smartypants') +const { normalise } = require('../utils.js') + /** * Convert ASCII punctuation characters into ‘smart’ typographic equivalents + * * @param {string} string - Value to transform * @returns {string} `string` with smart typographic punctuation * @example diff --git a/lib/filters/tokenize.js b/lib/filters/tokenize.js index c999de8f..66b1b7fa 100644 --- a/lib/filters/tokenize.js +++ b/lib/filters/tokenize.js @@ -1,5 +1,6 @@ /** * Reduce size of a string by removing duplicate and common words + * * @see {@link https://www.hawksworx.com/blog/adding-search-to-a-jamstack-site} * @param {string} string - Original string * @returns {string} Tokenised string diff --git a/lib/govuk.js b/lib/govuk.js index dcba2f33..be928e61 100644 --- a/lib/govuk.js +++ b/lib/govuk.js @@ -1,4 +1,5 @@ import { initAll as GOVUKFrontend } from 'govuk-frontend' + import { SiteSearchElement } from '../components/site-search/site-search.js' // Initiate custom elements diff --git a/lib/markdown-it.js b/lib/markdown-it.js index 798d4f6b..3c70499e 100644 --- a/lib/markdown-it.js +++ b/lib/markdown-it.js @@ -3,6 +3,7 @@ const anchor = require('markdown-it-anchor') /** * Configure markdown-it + * * @see {@link https://markdown-it.github.io/markdown-it/} * @param {object} [options] - Plugin options * @returns {Function} markdown-it instance diff --git a/lib/markdown-it/deflist.js b/lib/markdown-it/deflist.js index 7a335196..74ef2e83 100644 --- a/lib/markdown-it/deflist.js +++ b/lib/markdown-it/deflist.js @@ -1,5 +1,6 @@ /** * Render a definition list + * * @param {Function} md - markdown-it instance */ module.exports = function defList(md) { diff --git a/lib/markdown-it/footnote.js b/lib/markdown-it/footnote.js index e8b44807..2bead987 100644 --- a/lib/markdown-it/footnote.js +++ b/lib/markdown-it/footnote.js @@ -1,5 +1,6 @@ /** * Render footnotes + * * @param {Function} md - markdown-it instance */ module.exports = function footnotes(md) { diff --git a/lib/markdown-it/table-of-contents.js b/lib/markdown-it/table-of-contents.js index 66102cc9..8a6045e5 100644 --- a/lib/markdown-it/table-of-contents.js +++ b/lib/markdown-it/table-of-contents.js @@ -1,5 +1,6 @@ /** * Render a table of contents + * * @param {Function} md - markdown-it instance */ module.exports = function contentsList(md) { diff --git a/lib/markdown-it/table.js b/lib/markdown-it/table.js index 99c22741..e4ac52e3 100644 --- a/lib/markdown-it/table.js +++ b/lib/markdown-it/table.js @@ -1,5 +1,6 @@ /** * Render a table with `tabindex` to enable keyboard scrolling + * * @param {Function} md - markdown-it instance */ module.exports = function table(md) { diff --git a/lib/nunjucks.js b/lib/nunjucks.js index b6cd15b7..af6e8799 100644 --- a/lib/nunjucks.js +++ b/lib/nunjucks.js @@ -1,11 +1,13 @@ const fs = require('node:fs') const path = require('node:path') + const Nunjucks = require('nunjucks') /** * If there is a version conflict between a govuk-eleventy-plugin dependency * and the host project's dependencies, npm will include the expected version * in a nested node_modules folder. + * * @param {string} module - Module name * @returns {string} Path to module */ @@ -16,6 +18,7 @@ const resolveNpmModule = (module) => { /** * Configure Nunjucks environment + * * @see {@link https://mozilla.github.io/nunjucks/api.html#environment} * @param {object} eleventyConfig - Eleventy config * @returns {Function} Nunjucks environment @@ -36,6 +39,7 @@ module.exports = (eleventyConfig) => { /** * Set default options, but respect `nunjucksEnvironmentOptions` + * * @see {@link https://www.11ty.dev/docs/languages/nunjucks/#optional-use-your-nunjucks-environment-options} */ const options = { diff --git a/lib/utils.js b/lib/utils.js index d62a858d..ac753b41 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,8 +1,9 @@ -const path = require('node:path') const fs = require('node:fs/promises') +const path = require('node:path') /** * Read contents of SCSS settings file + * * @param {object} dir - Eleventy directories * @param {object} options - Plugin options * @returns {Promise} SCSS file contents @@ -30,6 +31,7 @@ const getScssSettings = async (dir, options) => { /** * Normalise value provided to a filter. Checks that a given value exists * before performing a transformation. + * * @param {*} value - Input value * @param {*} defaultValue - Value to fallback to if no value given * @returns {*} defaultValue diff --git a/test/lib/filters/canonical-url.js b/test/lib/filters/canonical-url.js index 405aef9d..f4106338 100644 --- a/test/lib/filters/canonical-url.js +++ b/test/lib/filters/canonical-url.js @@ -1,6 +1,8 @@ -const assert = require('assert/strict') +const assert = require('node:assert/strict') const { describe, it } = require('node:test') + const nunjucks = require('nunjucks') + const canonicalUrl = require('../../../lib/filters/canonical-url.js') describe('canonicalUrl filter', () => { diff --git a/test/lib/filters/current-page.js b/test/lib/filters/current-page.js index 565c9e91..cd70e346 100644 --- a/test/lib/filters/current-page.js +++ b/test/lib/filters/current-page.js @@ -1,5 +1,6 @@ -const assert = require('assert/strict') +const assert = require('node:assert/strict') const { describe, it } = require('node:test') + const currentPage = require('../../../lib/filters/current-page.js') const navigationData = [ diff --git a/test/lib/filters/date.js b/test/lib/filters/date.js index e11d24c5..101f765a 100644 --- a/test/lib/filters/date.js +++ b/test/lib/filters/date.js @@ -1,5 +1,6 @@ -const assert = require('assert/strict') +const assert = require('node:assert/strict') const { describe, it } = require('node:test') + const date = require('../../../lib/filters/date.js') describe('Date filter', () => { diff --git a/test/lib/filters/items-from-collection.js b/test/lib/filters/items-from-collection.js index 69679c48..a5cc0a85 100644 --- a/test/lib/filters/items-from-collection.js +++ b/test/lib/filters/items-from-collection.js @@ -1,5 +1,6 @@ -const assert = require('assert/strict') +const assert = require('node:assert/strict') const { describe, it } = require('node:test') + const itemsFromCollection = require('../../../lib/filters/items-from-collection.js') const collectionData = [ diff --git a/test/lib/filters/items-from-navigation.js b/test/lib/filters/items-from-navigation.js index 7f013bbc..9425c08c 100644 --- a/test/lib/filters/items-from-navigation.js +++ b/test/lib/filters/items-from-navigation.js @@ -1,5 +1,6 @@ -const assert = require('assert/strict') +const assert = require('node:assert/strict') const { describe, it } = require('node:test') + const itemsFromNavigation = require('../../../lib/filters/items-from-navigation.js') const eleventyNavigationBreadcrumb = [ diff --git a/test/lib/filters/markdown.js b/test/lib/filters/markdown.js index 3dd97f4f..bb2fdebf 100644 --- a/test/lib/filters/markdown.js +++ b/test/lib/filters/markdown.js @@ -1,5 +1,6 @@ -const assert = require('assert/strict') +const assert = require('node:assert/strict') const { describe, it } = require('node:test') + const markdown = require('../../../lib/filters/markdown.js') describe('markdown filter', () => { diff --git a/test/lib/filters/no-orphans.js b/test/lib/filters/no-orphans.js index 820c5c8f..0683d4a5 100644 --- a/test/lib/filters/no-orphans.js +++ b/test/lib/filters/no-orphans.js @@ -1,5 +1,6 @@ -const assert = require('assert/strict') +const assert = require('node:assert/strict') const { describe, it } = require('node:test') + const noOrphans = require('../../../lib/filters/no-orphans.js') describe('noOrphans filter', () => { diff --git a/test/lib/filters/pretty.js b/test/lib/filters/pretty.js index 55560814..d44a06bf 100644 --- a/test/lib/filters/pretty.js +++ b/test/lib/filters/pretty.js @@ -1,5 +1,6 @@ -const assert = require('assert/strict') +const assert = require('node:assert/strict') const { describe, it } = require('node:test') + const pretty = require('../../../lib/filters/pretty.js') describe('pretty filter', () => { diff --git a/test/lib/filters/smart.js b/test/lib/filters/smart.js index 5134e0ac..e38f37b3 100644 --- a/test/lib/filters/smart.js +++ b/test/lib/filters/smart.js @@ -1,5 +1,6 @@ -const assert = require('assert/strict') +const assert = require('node:assert/strict') const { describe, it } = require('node:test') + const smart = require('../../../lib/filters/smart.js') describe('smart filter', () => { diff --git a/test/lib/filters/tokenize.js b/test/lib/filters/tokenize.js index cbf55e8f..14130517 100644 --- a/test/lib/filters/tokenize.js +++ b/test/lib/filters/tokenize.js @@ -1,5 +1,6 @@ -const assert = require('assert/strict') +const assert = require('node:assert/strict') const { describe, it } = require('node:test') + const tokenize = require('../../../lib/filters/tokenize.js') describe('tokenize filter', () => { diff --git a/test/lib/markdown-it.js b/test/lib/markdown-it.js index 814e6a20..3faf0ad4 100644 --- a/test/lib/markdown-it.js +++ b/test/lib/markdown-it.js @@ -1,5 +1,6 @@ -const assert = require('assert/strict') +const assert = require('node:assert/strict') const { describe, it } = require('node:test') + const md = require('../../lib/markdown-it.js') describe('markdown-it', () => { diff --git a/test/lib/utils.js b/test/lib/utils.js index d1a35ef4..a9d3f34e 100644 --- a/test/lib/utils.js +++ b/test/lib/utils.js @@ -1,5 +1,6 @@ -const assert = require('assert/strict') +const assert = require('node:assert/strict') const { describe, it } = require('node:test') + const { normalise } = require('../../lib/utils.js') describe('Utility', () => {