From e4e271995c8c56c322b9e7134ee8ec0b77a4d8a8 Mon Sep 17 00:00:00 2001 From: Tim Cosgrove Date: Wed, 11 Dec 2024 13:24:35 -0800 Subject: [PATCH] Remove Event page queries from Content Build (#2368) * Remove Event page queries. * Add debug to broken link check. * Add ignore patterns to broken link checker. * Fix botched for loop. * Refine events regex. * Remove debug logging. --- .../constants/brokenLinkIgnorePatterns.js | 26 +++++++++++++++++++ .../graphql/CountEntityTypes.graphql.js | 20 -------------- .../drupal/graphql/GetAllPages.graphql.js | 3 +-- .../stages/build/drupal/individual-queries.js | 8 ------ .../helpers/isBrokenLink.js | 11 +++++++- 5 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 src/site/constants/brokenLinkIgnorePatterns.js diff --git a/src/site/constants/brokenLinkIgnorePatterns.js b/src/site/constants/brokenLinkIgnorePatterns.js new file mode 100644 index 0000000000..756386cf65 --- /dev/null +++ b/src/site/constants/brokenLinkIgnorePatterns.js @@ -0,0 +1,26 @@ +/* + This is a set of patterns which the broken link checker should ignore when making a check. + + Given a page dog.html that contains the following three links: + - /animals/cat.html + - /animals/horse.html + - /animals/capybara.html + + If an item in IGNORE_PATTERNS contains 'capybara', it will ignore the third link. + If an item in IGNORE_PATTERNS contains 'animals', it will ignore ALL the links. + + Note that it's the target URL that checks the ignore pattern. If you included + 'dog' in the IGNORE_PATTERNS in the example above, it would still test dog.html + for broken links it contains, but block testing dog.html as a destination. + + Be very careful of unintended consequences when adding these patterns. Be + sure you are targeting what you want to ignore precisely. + + */ +const IGNORE_PATTERNS = [ + /\/events($|\/)?/, // This ignores all links to Event and Event Listing pages. +]; + +module.exports = { + IGNORE_PATTERNS, +}; diff --git a/src/site/stages/build/drupal/graphql/CountEntityTypes.graphql.js b/src/site/stages/build/drupal/graphql/CountEntityTypes.graphql.js index d3807596ba..2848cc0a1f 100644 --- a/src/site/stages/build/drupal/graphql/CountEntityTypes.graphql.js +++ b/src/site/stages/build/drupal/graphql/CountEntityTypes.graphql.js @@ -91,26 +91,6 @@ const CountEntityTypes = ` count } - eventListing: nodeQuery( - filter: { - conditions: [ - {field: "status", value: ["1"]}, - {field: "type", value: ["event_listing"]} - ]} - ) { - count - } - - event: nodeQuery( - filter: { - conditions: [ - {field: "status", value: ["1"]}, - {field: "type", value: ["event"]} - ]} - ) { - count - } - healthCareRegionDetailPage: nodeQuery( filter: { conditions: [ diff --git a/src/site/stages/build/drupal/graphql/GetAllPages.graphql.js b/src/site/stages/build/drupal/graphql/GetAllPages.graphql.js index db16a71a82..4945843eeb 100644 --- a/src/site/stages/build/drupal/graphql/GetAllPages.graphql.js +++ b/src/site/stages/build/drupal/graphql/GetAllPages.graphql.js @@ -115,8 +115,7 @@ const buildQuery = () => { ... nodeOffice ... bioPage ... benefitListingPage - ... nodeEventListing - ... nodeEvent + ... storyListingPage ... leadershipListingPage ... pressReleasesListingPage diff --git a/src/site/stages/build/drupal/individual-queries.js b/src/site/stages/build/drupal/individual-queries.js index 3006c15b28..e8084f0929 100644 --- a/src/site/stages/build/drupal/individual-queries.js +++ b/src/site/stages/build/drupal/individual-queries.js @@ -29,12 +29,6 @@ const { GetNodePressReleaseListingPages, } = require('./graphql/pressReleasesListingPage.graphql'); -const { - getNodeEventListingQueries, -} = require('./graphql/nodeEventListing.graphql'); - -const { getNodeEventQueries } = require('./graphql/nodeEvent.graphql'); - const { GetNodeStoryListingPages, } = require('./graphql/storyListingPage.graphql'); @@ -118,8 +112,6 @@ function getNodeQueries(entityCounts) { ...getNewsStoryQueries(entityCounts), ...getPressReleaseQueries(entityCounts), GetNodePressReleaseListingPages, - ...getNodeEventListingQueries(entityCounts), - ...getNodeEventQueries(entityCounts), ...getVaPoliceQueries(entityCounts), GetNodeStoryListingPages, GetNodeLocationsListingPages, diff --git a/src/site/stages/build/plugins/modify-dom/check-broken-links/helpers/isBrokenLink.js b/src/site/stages/build/plugins/modify-dom/check-broken-links/helpers/isBrokenLink.js index b88204e4e3..753c309841 100644 --- a/src/site/stages/build/plugins/modify-dom/check-broken-links/helpers/isBrokenLink.js +++ b/src/site/stages/build/plugins/modify-dom/check-broken-links/helpers/isBrokenLink.js @@ -1,5 +1,8 @@ const path = require('path'); const url = require('url'); +const { + IGNORE_PATTERNS, +} = require('../../../../../../constants/brokenLinkIgnorePatterns'); /** * Validates an HREF/SRC value @@ -24,6 +27,13 @@ function isBrokenLink(link, pagePath, allPaths) { let filePath = decodeURIComponent(parsed.pathname); + // Check for link destinations we are not testing. + for (let i = 0; i < IGNORE_PATTERNS.length; i += 1) { + if (filePath.match(IGNORE_PATTERNS[i])) { + return false; + } + } + if (path.isAbsolute(filePath)) { filePath = path.join('.', filePath); } else { @@ -33,7 +43,6 @@ function isBrokenLink(link, pagePath, allPaths) { if (!path.extname(filePath)) { filePath = path.join(filePath, 'index.html'); } - return !allPaths.has(filePath); }