Skip to content

Commit c830a93

Browse files
Merge pull request #13570 from guardian/improve-dev
Fix url regex and optimise clipboard on dev server
2 parents 5993924 + 5f213ff commit c830a93

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

dotcom-rendering/src/server/dev-index.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,9 +647,14 @@ <h2>Test Articles By Element (Missing)</h2>
647647
const getPageType = (url) => {
648648
// All interactive pages include this in the URL
649649
if (url.includes('/ng-interactive/')) return 'Interactive';
650-
// We're looking for the date string, e.g /2022/jul/30
651-
else if (url.match(/[0-9]{4}\/[a-z]{3}\/[0-9]{2}\/.+/))
650+
else if (
651+
url.match(/\/\d{4}\/[a-z]{3}\/\d{2}\//) || // Standard article date format e.g /2022/jul/30
652+
url.match(/\/[a-z-]+\/\d+$/) // Crossword format e.g /crosswords/quick/17117
653+
)
652654
return 'Article';
655+
// This is imperfect, but covers some cases of tag pages, consider expanding in the future
656+
else if (url.match(/\/(tone|series|profile)\/[a-z-]+/))
657+
return 'TagPage';
653658
// Fall back to fronts for all other page types
654659
else return 'Front';
655660
};

dotcom-rendering/src/server/server.dev.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import {
2222
} from './handler.front.web';
2323

2424
/** article URLs contain a part that looks like “2022/nov/25” */
25-
const ARTICLE_URL = /\/\d{4}\/[a-z]{3}\/\d{2}\//;
25+
const ARTICLE_URL = /(\/\d{4}\/[a-z]{3}\/\d{2}\/)/;
26+
/** Crossword URLs end with e.g /crosswords/quick/17117 */
27+
const CROSSWORD_URL = /(\/[a-z-]+\/\d+$)/;
2628
/** fronts are a series of lowercase strings, dashes and forward slashes */
2729
const FRONT_URL = /^\/[a-z-/]+(?<!\.css)$/;
2830
/** This is imperfect, but covers *some* cases of tag pages, consider expanding in the future */
@@ -98,7 +100,10 @@ export const devServer = (): Handler => {
98100
// Do not redirect assets urls
99101
if (req.url.match(ASSETS_URL)) return next();
100102

101-
if (req.url.match(ARTICLE_URL)) {
103+
if (
104+
req.url.match(ARTICLE_URL) ??
105+
req.url.match(CROSSWORD_URL)
106+
) {
102107
const url = new URL(
103108
req.url,
104109
'https://www.theguardian.com/',

0 commit comments

Comments
 (0)