From 43b5523eddf1b20d28f5ae5e605d1e0aa13c5415 Mon Sep 17 00:00:00 2001 From: Keith Kennedy Date: Fri, 3 Nov 2023 10:47:00 +0000 Subject: [PATCH 1/3] Removed path prefix usages --- .eleventy.js | 28 +++++------------------ _data/eleventyComputed.js | 38 -------------------------------- _includes/layouts/collection.njk | 2 +- cypress/e2e/spec.cy.js | 4 ++-- 4 files changed, 9 insertions(+), 63 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index f44afb8c..114be522 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -2,8 +2,6 @@ const govukEleventyPlugin = require('@x-govuk/govuk-eleventy-plugin') const { DateTime } = require("luxon"); module.exports = function(eleventyConfig) { - // Set custom variable to decide the path prefix as it is used in a couple of places. - const _customPathPrefix = process.env.PATH_PREFIX ?? ''; const _siteRoot = process.env.SITE_ROOT ?? 'http://localhost/'; // Pass assets through to final build directory eleventyConfig.addPassthroughCopy({ "docs/assets/logos": "assets/logos"}); @@ -19,7 +17,7 @@ module.exports = function(eleventyConfig) { opengraphImageUrl: '/assets/logos/ho-opengraph-image.png', homeKey: 'Home', header: { - organisationLogo: 'Home Office Logo', + organisationLogo: 'Home Office Logo', organisationName: 'Home Office', productName: 'Engineering Guidance and Standards', search: { @@ -35,15 +33,15 @@ module.exports = function(eleventyConfig) { meta: { items: [ { - href: _customPathPrefix + '/about/', + href: '/about/', text: 'About' }, { - href: _customPathPrefix + '/cookies/', + href: '/cookies/', text: 'Cookies' }, { - href: _customPathPrefix + '/accessibility-statement/', + href: '/accessibility-statement/', text: 'Accessibility' }, { @@ -65,18 +63,6 @@ module.exports = function(eleventyConfig) { md.use(require('./lib/markdown/dl-as-govuk-summary-list')); eleventyConfig.setLibrary('md', md); - }) - - eleventyConfig.addFilter("itemsFromPaginationWithPathPrefix", (pagination) => { - const items = [] - pagination.pages.forEach((item, index) => { - items.push({ - current: index === pagination.pageNumber, - number: index + 1, - href: _customPathPrefix + pagination.hrefs[index] - }) - }) - return items; }); eleventyConfig.addFilter("postDate", (dateObj) => { @@ -142,11 +128,10 @@ module.exports = function(eleventyConfig) { tag: { text: "Alpha" }, - html: 'This is a new service – your feedback (opens in a new tab) will help us to improve it.' + html: 'This is a new service – your feedback (opens in a new tab) will help us to improve it.' } }); - eleventyConfig.addGlobalData('pathPrefix', _customPathPrefix); eleventyConfig.addGlobalData('siteRoot', _siteRoot); return { @@ -158,7 +143,6 @@ module.exports = function(eleventyConfig) { layouts: '../_includes/layouts', includes: '../_includes', input: 'docs' - }, - pathPrefix: _customPathPrefix + } } }; diff --git a/_data/eleventyComputed.js b/_data/eleventyComputed.js index 109532a3..1501828e 100644 --- a/_data/eleventyComputed.js +++ b/_data/eleventyComputed.js @@ -1,44 +1,6 @@ -// noinspection JSUnusedGlobalSymbols -const { applyBaseToUrl } = require('@11ty/eleventy/src/Plugins/HtmlBasePlugin') - -function mapRelatedSections(sections, pathPrefix) { - return sections.map( - section => ({ - ...section, - items: (section.items ?? []).map(item => ({ - ...item, - href: applyBaseToUrl(item.href, pathPrefix, {pathPrefix}), - })), - subsections: mapRelatedSections(section.subsections ?? [], pathPrefix), - }) - ); -} - module.exports = { eleventyExcludeFromCollections: ({page, eleventyExcludeFromCollections}) => { return eleventyExcludeFromCollections || page.templateSyntax === 'scss'; - }, - // the path prefix isn't applied to related link urls by xGovukRelatedNavigation - so map them here - pagination: ({pagination, pathPrefix}) => { - if (!pagination || Object.keys(pagination).length === 0) { - return pagination; - } - if (pagination.href.previous) { - pagination.href.previous = applyBaseToUrl(pagination.href.previous, pathPrefix, {pathPrefix}); - } - if (pagination.href.next) { - pagination.href.next = applyBaseToUrl(pagination.href.next, pathPrefix, {pathPrefix}); - } - return pagination; - }, - related: ({related, pathPrefix}) => { - if (!related) { - return related; - } - - related.sections = mapRelatedSections(related.sections ?? [related], pathPrefix); - - return related; } } diff --git a/_includes/layouts/collection.njk b/_includes/layouts/collection.njk index aab2d6a5..332204e4 100644 --- a/_includes/layouts/collection.njk +++ b/_includes/layouts/collection.njk @@ -50,7 +50,7 @@ next: { href: pagination.href.next }, - items: pagination | itemsFromPaginationWithPathPrefix + items: pagination | itemsFromPagination }) if pagination.pages.length > 1 }} diff --git a/cypress/e2e/spec.cy.js b/cypress/e2e/spec.cy.js index b4f2b0d0..67d96b7e 100644 --- a/cypress/e2e/spec.cy.js +++ b/cypress/e2e/spec.cy.js @@ -114,7 +114,7 @@ describe('Cookies page links from footer test', () => { }) }) -describe('Related links respect path prefix', () => { +describe('Related links', () => { it('finds the correct related link and follows it to a valid page', () => { cy.visit(testing_params.TEST_ROOT_URL) // Click through to standard page that has a related link @@ -126,7 +126,7 @@ describe('Related links respect path prefix', () => { }) }) -describe('Pagination links respect path prefix', () => { +describe('Pagination links', () => { it('finds the pagination links and follows them to valid pages', () => { cy.visit(testing_params.TEST_ROOT_URL) // Click to standards page that has a related link From 46bdcc4daa83c764aa7da30f1b1e34129ea07f7c Mon Sep 17 00:00:00 2001 From: Keith Kennedy Date: Fri, 3 Nov 2023 11:06:46 +0000 Subject: [PATCH 2/3] Removed test path prefix for e2e workflow --- .github/workflows/e2e-tests-on-pr.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/e2e-tests-on-pr.yml b/.github/workflows/e2e-tests-on-pr.yml index 9ad95d1f..8e4e1919 100644 --- a/.github/workflows/e2e-tests-on-pr.yml +++ b/.github/workflows/e2e-tests-on-pr.yml @@ -9,7 +9,6 @@ on: env: TEST_URL: localhost TEST_PORT: 8080 - TEST_PATH_PREFIX: '/test/' jobs: e2e-test: @@ -29,10 +28,8 @@ jobs: browser: chrome build: npm run build start: npm run serve -- --port ${{ env.TEST_PORT }} - wait-on: 'http://${{ env.TEST_URL }}:${{ env.TEST_PORT }}${{ env.TEST_PATH_PREFIX }}' + wait-on: 'http://${{ env.TEST_URL }}:${{ env.TEST_PORT }}' config: 'video=false,screenshotOnRunFailure=false' env: CYPRESS_TEST_URL: ${{ env.TEST_URL }} CYPRESS_TEST_PORT: ${{ env.TEST_PORT }} - CYPRESS_TEST_PATH_PREFIX: ${{ env.TEST_PATH_PREFIX }} - PATH_PREFIX: ${{ env.TEST_PATH_PREFIX }} From 7a7ae1dac63542b4655df09fd4479899bcdc5077 Mon Sep 17 00:00:00 2001 From: Keith Kennedy Date: Fri, 3 Nov 2023 14:09:19 +0000 Subject: [PATCH 3/3] Removed tag page logic used to work around path prefix issue --- _includes/layouts/tags.njk | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/_includes/layouts/tags.njk b/_includes/layouts/tags.njk index b2c6ac8a..5d7a0689 100644 --- a/_includes/layouts/tags.njk +++ b/_includes/layouts/tags.njk @@ -22,15 +22,7 @@
    {% for tag in collections.all | getAllTags | filterTagList %} - {% if tag == "Patterns" %} - {%- set tagUrl %}{{ "/patterns/" | url }}/{% endset %} - {% elseif tag == "Principles" %} - {%- set tagUrl %}{{ "/principles/" | url }}/{% endset %} - {% elseif tag == "Standards" %} - {%- set tagUrl %}{{ "/standards" | url }}/{% endset %} - {% else %} - {%- set tagUrl %}{{ "/tags/" | url }}{{ tag | slugify }}/{% endset %} - {% endif %} + {%- set tagUrl %}{{ "/tags/" | url }}{{ tag | slugify }}/{% endset %}
  • {{ tag }}