Skip to content

Commit

Permalink
Removed tech debt related to path prefix usages (#334)
Browse files Browse the repository at this point in the history
* Removed path prefix usages

* Removed test path prefix for e2e workflow

* Removed tag page logic used to work around path prefix issue
  • Loading branch information
keithkennedyHO authored Nov 7, 2023
1 parent 7809ac2 commit 9527809
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 76 deletions.
28 changes: 6 additions & 22 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"});
Expand All @@ -19,7 +17,7 @@ module.exports = function(eleventyConfig) {
opengraphImageUrl: '/assets/logos/ho-opengraph-image.png',
homeKey: 'Home',
header: {
organisationLogo: '<img src="' + _customPathPrefix + '/assets/logos/ho_logo.svg" height="34px" alt="Home Office Logo">',
organisationLogo: '<img src="/assets/logos/ho_logo.svg" height="34px" alt="Home Office Logo">',
organisationName: 'Home Office',
productName: 'Engineering Guidance and Standards',
search: {
Expand All @@ -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'
},
{
Expand All @@ -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) => {
Expand Down Expand Up @@ -142,11 +128,10 @@ module.exports = function(eleventyConfig) {
tag: {
text: "Alpha"
},
html: 'This is a new service – your <a class="govuk-link" target="_blank" href="' + _customPathPrefix + '/provide-feedback/">feedback (opens in a new tab)</a> will help us to improve it.'
html: 'This is a new service – your <a class="govuk-link" target="_blank" href="/provide-feedback/">feedback (opens in a new tab)</a> will help us to improve it.'
}
});

eleventyConfig.addGlobalData('pathPrefix', _customPathPrefix);
eleventyConfig.addGlobalData('siteRoot', _siteRoot);

return {
Expand All @@ -158,7 +143,6 @@ module.exports = function(eleventyConfig) {
layouts: '../_includes/layouts',
includes: '../_includes',
input: 'docs'
},
pathPrefix: _customPathPrefix
}
}
};
5 changes: 1 addition & 4 deletions .github/workflows/e2e-tests-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:
env:
TEST_URL: localhost
TEST_PORT: 8080
TEST_PATH_PREFIX: '/test/'

jobs:
e2e-test:
Expand All @@ -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 }}
38 changes: 0 additions & 38 deletions _data/eleventyComputed.js
Original file line number Diff line number Diff line change
@@ -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;
}
}

2 changes: 1 addition & 1 deletion _includes/layouts/collection.njk
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
next: {
href: pagination.href.next
},
items: pagination | itemsFromPaginationWithPathPrefix
items: pagination | itemsFromPagination
}) if pagination.pages.length > 1 }}
</section>

Expand Down
10 changes: 1 addition & 9 deletions _includes/layouts/tags.njk
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,7 @@

<ul class="govuk-list govuk-list--bullet">
{% 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 %}
<li>
<a href="{{ tagUrl }}">{{ tag }}</a>
</li>
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9527809

Please sign in to comment.