diff --git a/dotcom-rendering/scripts/json-schema/check-schema.js b/dotcom-rendering/scripts/json-schema/check-schema.js index 2c8bd7d7118..78433525e8d 100644 --- a/dotcom-rendering/scripts/json-schema/check-schema.js +++ b/dotcom-rendering/scripts/json-schema/check-schema.js @@ -5,7 +5,7 @@ const { getArticleSchema, getFrontSchema, getNewsletterPageSchema, - getIndexPageSchema, + getTagFrontSchema, } = require('./get-schema'); const root = path.resolve(__dirname, '..', '..'); @@ -18,7 +18,7 @@ const existingFrontSchema = fs.readFileSync( `${root}/src/model/front-schema.json`, { encoding: 'utf-8' }, ); -const existingIndexPageSchema = fs.readFileSync( +const existingTagFrontSchema = fs.readFileSync( `${root}/src/model/front-schema.json`, { encoding: 'utf-8' }, ); @@ -29,13 +29,13 @@ const existingNewsletterSchema = fs.readFileSync( const articleSchema = getArticleSchema(); const frontSchema = getFrontSchema(); -const indexPageSchema = getIndexPageSchema(); +const tagFrontSchema = getTagFrontSchema(); const newsletterSchema = getNewsletterPageSchema(); if ( existingArticleSchema !== articleSchema || existingFrontSchema !== frontSchema || - existingIndexPageSchema !== indexPageSchema || + existingTagFrontSchema !== tagFrontSchema || existingNewsletterSchema !== newsletterSchema ) { throw new Error('Schemas do not match ... please run "make gen-schema"'); diff --git a/dotcom-rendering/scripts/json-schema/gen-schema.js b/dotcom-rendering/scripts/json-schema/gen-schema.js index bf8db54d803..d3b68becce1 100644 --- a/dotcom-rendering/scripts/json-schema/gen-schema.js +++ b/dotcom-rendering/scripts/json-schema/gen-schema.js @@ -5,14 +5,14 @@ const { getArticleSchema, getFrontSchema, getNewsletterPageSchema, - getIndexPageSchema, + getTagFrontSchema, } = require('./get-schema'); const root = path.resolve(__dirname, '..', '..'); const articleSchema = getArticleSchema(); const frontSchema = getFrontSchema(); -const indexPageSchema = getIndexPageSchema(); +const tagFrontSchema = getTagFrontSchema(); const newsletterPageSchema = getNewsletterPageSchema(); fs.writeFile( @@ -38,8 +38,8 @@ fs.writeFile( ); fs.writeFile( - `${root}/src/model/index-page-schema.json`, - indexPageSchema, + `${root}/src/model/tag-front-schema.json`, + tagFrontSchema, 'utf8', (err) => { if (err) { diff --git a/dotcom-rendering/scripts/json-schema/get-schema.js b/dotcom-rendering/scripts/json-schema/get-schema.js index b9c00bb38d7..7da76b82a86 100644 --- a/dotcom-rendering/scripts/json-schema/get-schema.js +++ b/dotcom-rendering/scripts/json-schema/get-schema.js @@ -7,7 +7,7 @@ const program = TJS.getProgramFromFiles( [ path.resolve(`${root}/index.d.ts`), path.resolve(`${root}/src/types/frontend.ts`), - path.resolve(`${root}/src/types/indexPage.ts`), + path.resolve(`${root}/src/types/tagFront.ts`), path.resolve(`${root}/src/types/newslettersPage.ts`), ], { @@ -32,9 +32,9 @@ module.exports = { 4, ); }, - getIndexPageSchema: () => { + getTagFrontSchema: () => { return JSON.stringify( - TJS.generateSchema(program, 'FEIndexPageType', settings), + TJS.generateSchema(program, 'FETagFrontType', settings), null, 4, ); diff --git a/dotcom-rendering/src/model/front-schema.json b/dotcom-rendering/src/model/front-schema.json index 28c2e0ec518..74aa29b4375 100644 --- a/dotcom-rendering/src/model/front-schema.json +++ b/dotcom-rendering/src/model/front-schema.json @@ -720,6 +720,25 @@ "tagType", "webTitle" ] + }, + "pagination": { + "type": "object", + "properties": { + "currentPage": { + "type": "number" + }, + "lastPage": { + "type": "number" + }, + "totalContent": { + "type": "number" + } + }, + "required": [ + "currentPage", + "lastPage", + "totalContent" + ] } }, "required": [ @@ -1400,6 +1419,25 @@ "tagType", "webTitle" ] + }, + "pagination": { + "type": "object", + "properties": { + "currentPage": { + "type": "number" + }, + "lastPage": { + "type": "number" + }, + "totalContent": { + "type": "number" + } + }, + "required": [ + "currentPage", + "lastPage", + "totalContent" + ] } }, "required": [ @@ -2080,6 +2118,25 @@ "tagType", "webTitle" ] + }, + "pagination": { + "type": "object", + "properties": { + "currentPage": { + "type": "number" + }, + "lastPage": { + "type": "number" + }, + "totalContent": { + "type": "number" + } + }, + "required": [ + "currentPage", + "lastPage", + "totalContent" + ] } }, "required": [ diff --git a/dotcom-rendering/src/model/index-page-schema.json b/dotcom-rendering/src/model/tag-front-schema.json similarity index 91% rename from dotcom-rendering/src/model/index-page-schema.json rename to dotcom-rendering/src/model/tag-front-schema.json index 215d4c9b074..ba94321cc66 100644 --- a/dotcom-rendering/src/model/index-page-schema.json +++ b/dotcom-rendering/src/model/tag-front-schema.json @@ -255,6 +255,25 @@ "tagType", "webTitle" ] + }, + "pagination": { + "type": "object", + "properties": { + "currentPage": { + "type": "number" + }, + "lastPage": { + "type": "number" + }, + "totalContent": { + "type": "number" + } + }, + "required": [ + "currentPage", + "lastPage", + "totalContent" + ] } }, "required": [ @@ -684,6 +703,94 @@ "nav": { "$ref": "#/definitions/FENavType" }, + "tags": { + "type": "object", + "properties": { + "tags": { + "type": "array", + "items": { + "description": "This type comes from `frontend`, hence the FE prefix.", + "type": "object", + "properties": { + "properties": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "tagType": { + "type": "string" + }, + "webTitle": { + "type": "string" + }, + "bio": { + "type": "string" + }, + "bylineImageUrl": { + "type": "string" + }, + "bylineLargeImageUrl": { + "type": "string" + }, + "contributorLargeImagePath": { + "type": "string" + }, + "paidContentType": { + "type": "string" + }, + "sectionId": { + "type": "string" + }, + "sectionName": { + "type": "string" + }, + "twitterHandle": { + "type": "string" + }, + "url": { + "type": "string" + }, + "webUrl": { + "type": "string" + } + }, + "required": [ + "id", + "tagType", + "webTitle" + ] + }, + "pagination": { + "type": "object", + "properties": { + "currentPage": { + "type": "number" + }, + "lastPage": { + "type": "number" + }, + "totalContent": { + "type": "number" + } + }, + "required": [ + "currentPage", + "lastPage", + "totalContent" + ] + } + }, + "required": [ + "properties" + ] + } + } + }, + "required": [ + "tags" + ] + }, "editionId": { "$ref": "#/definitions/EditionId" }, @@ -1042,6 +1149,9 @@ }, "isAdFreeUser": { "type": "boolean" + }, + "forceDay": { + "type": "boolean" } }, "required": [ @@ -1050,11 +1160,13 @@ "contents", "editionId", "editionLongForm", + "forceDay", "guardianBaseURL", "isAdFreeUser", "nav", "pageFooter", "pageId", + "tags", "webTitle", "webURL" ], diff --git a/dotcom-rendering/src/model/validate.ts b/dotcom-rendering/src/model/validate.ts index fb10553d4f0..7725f3f6bd0 100644 --- a/dotcom-rendering/src/model/validate.ts +++ b/dotcom-rendering/src/model/validate.ts @@ -4,12 +4,12 @@ import Ajv from 'ajv'; import addFormats from 'ajv-formats'; import type { FEFrontType } from '../../src/types/front'; import type { FEArticleType } from '../types/frontend'; -import type { FEIndexPageType } from '../types/indexPage'; import type { FENewslettersPageType } from '../types/newslettersPage'; +import type { FETagFrontType } from '../types/tagFront'; import articleSchema from './article-schema.json'; import frontSchema from './front-schema.json'; -import indexPageSchema from './index-page-schema.json'; import newslettersPageSchema from './newsletter-page-schema.json'; +import tagFrontSchema from './tag-front-schema.json'; const options: Options = { verbose: false, @@ -23,7 +23,7 @@ addFormats(ajv); const validateArticle = ajv.compile(articleSchema); const validateFront = ajv.compile(frontSchema); -const validateIndexPage = ajv.compile(indexPageSchema); +const validateTagFront = ajv.compile(tagFrontSchema); const validateAllEditorialNewslettersPage = ajv.compile( newslettersPageSchema, ); @@ -52,15 +52,15 @@ export const validateAsFrontType = (data: unknown): FEFrontType => { ); }; -export const validateAsIndexPageType = (data: unknown): FEIndexPageType => { - if (validateIndexPage(data)) return data; +export const validateAsTagFrontType = (data: unknown): FETagFrontType => { + if (validateTagFront(data)) return data; const url = isObject(data) && isString(data.webURL) ? data.webURL : 'unknown url'; throw new TypeError( `Unable to validate request body for url ${url}.\n - ${JSON.stringify(validateFront.errors, null, 2)}`, + ${JSON.stringify(validateTagFront.errors, null, 2)}`, ); }; diff --git a/dotcom-rendering/src/server/dev-server.ts b/dotcom-rendering/src/server/dev-server.ts index e0ef47f8989..13efc166a1e 100644 --- a/dotcom-rendering/src/server/dev-server.ts +++ b/dotcom-rendering/src/server/dev-server.ts @@ -8,10 +8,10 @@ import { handleBlocks, handleFront, handleFrontJson, - handleIndexPage, - handleIndexPageJson, handleInteractive, handleKeyEvents, + handleTagFront, + handleTagPageJson, } from '../web/server'; /** article URLs contain a part that looks like “2022/nov/25” */ @@ -52,10 +52,10 @@ export const devServer = (): Handler => { return handleFront(req, res, next); case 'FrontJSON': return handleFrontJson(req, res, next); - case 'IndexPage': - return handleIndexPage(req, res, next); - case 'IndexPageJSON': - return handleIndexPageJson(req, res, next); + case 'TagFront': + return handleTagFront(req, res, next); + case 'TagFrontJSON': + return handleTagPageJson(req, res, next); case 'EmailNewsletters': return handleAllEditorialNewslettersPage(req, res, next); case 'AppsArticle': diff --git a/dotcom-rendering/src/server/prod-server.ts b/dotcom-rendering/src/server/prod-server.ts index 1d80efb2f0f..bb681d7b979 100644 --- a/dotcom-rendering/src/server/prod-server.ts +++ b/dotcom-rendering/src/server/prod-server.ts @@ -16,10 +16,10 @@ import { handleBlocks, handleFront, handleFrontJson, - handleIndexPage, - handleIndexPageJson, handleInteractive, handleKeyEvents, + handleTagFront, + handleTagPageJson, } from '../web/server'; import { recordBaselineCloudWatchMetrics } from './lib/aws/metrics-baseline'; import { getContentFromURLMiddleware } from './lib/get-content-from-url'; @@ -65,8 +65,8 @@ export const prodServer = (): void => { app.post('/KeyEvents', logRenderTime, handleKeyEvents); app.post('/Front', logRenderTime, handleFront); app.post('/FrontJSON', logRenderTime, handleFrontJson); - app.post('/IndexPage', logRenderTime, handleIndexPage); - app.post('/IndexPageJSON', logRenderTime, handleIndexPageJson); + app.post('/TagFront', logRenderTime, handleTagFront); + app.post('/TagFrontJSON', logRenderTime, handleTagPageJson); app.post( '/EmailNewsletters', logRenderTime, @@ -104,16 +104,16 @@ export const prodServer = (): void => { ); app.get( - '/IndexPage/*', + '/TagFront/*', logRenderTime, getContentFromURLMiddleware, - handleIndexPage, + handleTagFront, ); app.get( - '/IndexPageJSON/*', + '/TagFrontJSON/*', logRenderTime, getContentFromURLMiddleware, - handleIndexPageJson, + handleTagPageJson, ); app.get( diff --git a/dotcom-rendering/src/types/indexPage.ts b/dotcom-rendering/src/types/tagFront.ts similarity index 91% rename from dotcom-rendering/src/types/indexPage.ts rename to dotcom-rendering/src/types/tagFront.ts index f1aae9fc6b7..d9c0e76b756 100644 --- a/dotcom-rendering/src/types/indexPage.ts +++ b/dotcom-rendering/src/types/tagFront.ts @@ -4,11 +4,10 @@ import type { FooterType } from './footer'; import type { FEFrontCard, FEFrontConfigType } from './front'; import type { FETagType } from './tag'; -export interface FEIndexPageType { +export interface FETagFrontType { contents: FEFrontCard[]; nav: FENavType; tags: { - // TODO: Why does Frontend do this? tags: FETagType[]; }; editionId: EditionId; @@ -24,7 +23,7 @@ export interface FEIndexPageType { forceDay: boolean; } -export interface DCRIndexPageType { +export interface DCRTagFrontType { groupedTrails: GroupedTrails[]; nav: FENavType; tags: FETagType[]; diff --git a/dotcom-rendering/src/web/components/FrontSection.tsx b/dotcom-rendering/src/web/components/FrontSection.tsx index b1879251444..9f2da19536a 100644 --- a/dotcom-rendering/src/web/components/FrontSection.tsx +++ b/dotcom-rendering/src/web/components/FrontSection.tsx @@ -3,7 +3,7 @@ import type { EmotionJSX } from '@emotion/react/types/jsx-namespace'; import { from, neutral, space, until } from '@guardian/source-foundations'; import { Hide } from '@guardian/source-react-components'; import type { DCRContainerPalette, TreatType } from '../../types/front'; -import type { DCRFrontPagination } from '../../types/indexPage'; +import type { DCRFrontPagination } from '../../types/tagFront'; import { decideContainerOverrides } from '../lib/decideContainerOverrides'; import type { EditionId } from '../lib/edition'; import { ContainerTitle } from './ContainerTitle'; diff --git a/dotcom-rendering/src/web/components/IndexPagePage.tsx b/dotcom-rendering/src/web/components/TagFrontPage.tsx similarity index 83% rename from dotcom-rendering/src/web/components/IndexPagePage.tsx rename to dotcom-rendering/src/web/components/TagFrontPage.tsx index 00640a9f01e..f728017876d 100644 --- a/dotcom-rendering/src/web/components/IndexPagePage.tsx +++ b/dotcom-rendering/src/web/components/TagFrontPage.tsx @@ -3,8 +3,8 @@ import { brandAlt, focusHalo, neutral } from '@guardian/source-foundations'; import { StrictMode } from 'react'; import { filterABTestSwitches } from '../../model/enhance-switches'; import type { NavType } from '../../model/extract-nav'; -import type { DCRIndexPageType } from '../../types/indexPage'; -import { IndexPageLayout } from '../layouts/IndexPageLayout'; +import type { DCRTagFrontType } from '../../types/tagFront'; +import { TagFrontLayout } from '../layouts/TagFrontLayout'; import { AlreadyVisited } from './AlreadyVisited.importable'; import { AnimatePulsingDots } from './AnimatePulsingDots.importable'; import { FetchCommentCounts } from './FetchCommentCounts.importable'; @@ -16,7 +16,7 @@ import { ShowHideContainers } from './ShowHideContainers.importable'; import { SkipTo } from './SkipTo'; type Props = { - indexPage: DCRIndexPageType; + tagFront: DCRTagFrontType; NAV: NavType; }; @@ -28,7 +28,7 @@ type Props = { * @param {DCRFrontType} props.front - The article JSON data * @param {NAVType} props.NAV - The article JSON data * */ -export const IndexPagePage = ({ indexPage, NAV }: Props) => { +export const TagFrontPage = ({ tagFront, NAV }: Props) => { return ( { @@ -71,13 +71,13 @@ export const IndexPagePage = ({ indexPage, NAV }: Props) => { - + ); }; diff --git a/dotcom-rendering/src/web/layouts/IndexPageLayout.tsx b/dotcom-rendering/src/web/layouts/TagFrontLayout.tsx similarity index 81% rename from dotcom-rendering/src/web/layouts/IndexPageLayout.tsx rename to dotcom-rendering/src/web/layouts/TagFrontLayout.tsx index c5e1b138cfa..6f4ec586a2b 100644 --- a/dotcom-rendering/src/web/layouts/IndexPageLayout.tsx +++ b/dotcom-rendering/src/web/layouts/TagFrontLayout.tsx @@ -8,7 +8,7 @@ import { } from '@guardian/source-foundations'; import { StraightLines } from '@guardian/source-react-components-development-kitchen'; import type { NavType } from '../../model/extract-nav'; -import type { DCRIndexPageType } from '../../types/indexPage'; +import type { DCRTagFrontType } from '../../types/tagFront'; import { AdSlot } from '../components/AdSlot'; import { DecideContainerByTrails } from '../components/DecideContainerByTrails'; import { Footer } from '../components/Footer'; @@ -26,7 +26,7 @@ import { getEditionFromId } from '../lib/edition'; import { Stuck } from './lib/stickiness'; interface Props { - indexPage: DCRIndexPageType; + tagFront: DCRTagFrontType; NAV: NavType; } @@ -70,13 +70,13 @@ interface Props { // return null; // }; -export const IndexPageLayout = ({ indexPage, NAV }: Props) => { +export const TagFrontLayout = ({ tagFront, NAV }: Props) => { // const { // config: { isPaidContent }, - // } = indexPage; + // } = tagFront; const isInEuropeTest = - indexPage.config.abTests.europeNetworkFrontVariant === 'variant'; + tagFront.config.abTests.europeNetworkFrontVariant === 'variant'; const format = { display: ArticleDisplay.Standard, @@ -87,17 +87,17 @@ export const IndexPageLayout = ({ indexPage, NAV }: Props) => { const palette = decidePalette(format); // const merchHighPosition = getMerchHighPosition( - // indexPage.pressedPage.collections.length, - // indexPage.isNetworkFront, + // tagFront.pressedPage.collections.length, + // tagFront.isNetworkFront, // ); /** * This property currently only applies to the header and merchandising slots */ - const renderAds = canRenderAds(indexPage); + const renderAds = canRenderAds(tagFront); // const mobileAdPositions = renderAds - // ? getMobileAdPositions(indexPage.pressedPage.collections, merchHighPosition) + // ? getMobileAdPositions(tagFront.pressedPage.collections, merchHighPosition) // : []; return ( @@ -128,19 +128,19 @@ export const IndexPageLayout = ({ indexPage, NAV }: Props) => { element="header" >
@@ -157,12 +157,11 @@ export const IndexPageLayout = ({ indexPage, NAV }: Props) => { nav={NAV} format={format} subscribeUrl={ - indexPage.nav.readerRevenueLinks.header - .subscribe + tagFront.nav.readerRevenueLinks.header.subscribe } - editionId={indexPage.editionId} + editionId={tagFront.editionId} headerTopBarSwitch={ - !!indexPage.config.switches.headerTopNav + !!tagFront.config.switches.headerTopNav } isInEuropeTest={isInEuropeTest} /> @@ -203,11 +202,11 @@ export const IndexPageLayout = ({ indexPage, NAV }: Props) => {
- {indexPage.webTitle ? ( - + {tagFront.webTitle ? ( + ) : undefined} - {indexPage.groupedTrails.map((groupedTrails, index) => { - const locale = getEditionFromId(indexPage.editionId).locale; + {tagFront.groupedTrails.map((groupedTrails, index) => { + const locale = getEditionFromId(tagFront.editionId).locale; const date = new Date( groupedTrails.year, groupedTrails.month, @@ -216,7 +215,7 @@ export const IndexPageLayout = ({ indexPage, NAV }: Props) => { const url = groupedTrails.day !== undefined - ? `/${indexPage.pageId}/${groupedTrails.year}/${date + ? `/${tagFront.pageId}/${groupedTrails.year}/${date .toLocaleDateString(locale, { month: 'long', }) @@ -247,19 +246,19 @@ export const IndexPageLayout = ({ indexPage, NAV }: Props) => { containerName={'test'} toggleable={false} sectionId={'test'} - pageId={indexPage.pageId} - editionId={indexPage.editionId} + pageId={tagFront.pageId} + editionId={tagFront.editionId} canShowMore={false} - ajaxUrl={indexPage.config.ajaxUrl} + ajaxUrl={tagFront.config.ajaxUrl} pagination={ - index === indexPage.groupedTrails.length - 1 - ? indexPage.pagination + index === tagFront.groupedTrails.length - 1 + ? tagFront.pagination : undefined } > ); @@ -270,7 +269,7 @@ export const IndexPageLayout = ({ indexPage, NAV }: Props) => { showTopBorder={false} data-component="trending-topics" > - +
{ element="footer" >
diff --git a/dotcom-rendering/src/web/lib/canRenderAds.ts b/dotcom-rendering/src/web/lib/canRenderAds.ts index 0949913febb..5448850f2f4 100644 --- a/dotcom-rendering/src/web/lib/canRenderAds.ts +++ b/dotcom-rendering/src/web/lib/canRenderAds.ts @@ -1,13 +1,13 @@ import type { DCRFrontType } from '../../types/front'; import type { FEArticleType } from '../../types/frontend'; -import type { DCRIndexPageType } from '../../types/indexPage'; +import type { DCRTagFrontType } from '../../types/tagFront'; /** * Checks the page for a number of conditions that should * prevent ads from being displayed. */ export const canRenderAds = ( - pageData: FEArticleType | DCRFrontType | DCRIndexPageType, + pageData: FEArticleType | DCRFrontType | DCRTagFrontType, ): boolean => { if (pageData.isAdFreeUser) { return false; diff --git a/dotcom-rendering/src/web/server/index.ts b/dotcom-rendering/src/web/server/index.ts index d5ebae01aec..2770c5975ca 100644 --- a/dotcom-rendering/src/web/server/index.ts +++ b/dotcom-rendering/src/web/server/index.ts @@ -16,20 +16,20 @@ import { validateAsAllEditorialNewslettersPageType, validateAsArticleType, validateAsFrontType, - validateAsIndexPageType, + validateAsTagFrontType, } from '../../model/validate'; import { recordTypeAndPlatform } from '../../server/lib/logging-store'; import type { DCRFrontType, FEFrontType } from '../../types/front'; import type { FEArticleType } from '../../types/frontend'; -import type { DCRIndexPageType, FEIndexPageType } from '../../types/indexPage'; import type { DCRNewslettersPageType } from '../../types/newslettersPage'; +import type { DCRTagFrontType, FETagFrontType } from '../../types/tagFront'; import { decideTrail } from '../lib/decideTrail'; import { allEditorialNewslettersPageToHtml } from './allEditorialNewslettersPageToHtml'; import { articleToHtml } from './articleToHtml'; import { blocksToHtml } from './blocksToHtml'; import { frontToHtml } from './frontToHtml'; -import { indexPageToHtml } from './indexPageToHtml'; import { keyEventsToHtml } from './keyEventsToHtml'; +import { tagFrontToHtml } from './tagFrontToHtml'; function enhancePinnedPost(format: FEFormat, block?: Block) { return block ? enhanceBlocks([block], format)[0] : block; @@ -85,8 +85,8 @@ const enhanceFront = (body: unknown): DCRFrontType => { }; }; -const enhanceIndexPage = (body: unknown): DCRIndexPageType => { - const data: FEIndexPageType = validateAsIndexPageType(body); +const enhanceTagFront = (body: unknown): DCRTagFrontType => { + const data: FETagFrontType = validateAsTagFrontType(body); const enhancedCards = enhanceCards(data.contents); const speed = getSpeedFromTrails(data.contents); @@ -242,12 +242,12 @@ export const handleFrontJson: RequestHandler = ({ body }, res) => { res.json(enhanceFront(body)); }; -export const handleIndexPage: RequestHandler = ({ body }, res) => { - recordTypeAndPlatform('indexPAge'); +export const handleTagFront: RequestHandler = ({ body }, res) => { + recordTypeAndPlatform('tagFront'); try { - const indexPage = enhanceIndexPage(body); - const html = indexPageToHtml({ - indexPage, + const tagFront = enhanceTagFront(body); + const html = tagFrontToHtml({ + tagFront, }); res.status(200).send(html); } catch (e) { @@ -255,8 +255,8 @@ export const handleIndexPage: RequestHandler = ({ body }, res) => { } }; -export const handleIndexPageJson: RequestHandler = ({ body }, res) => { - res.json(enhanceIndexPage(body)); +export const handleTagPageJson: RequestHandler = ({ body }, res) => { + res.json(enhanceTagFront(body)); }; const enhanceAllEditorialNewslettersPage = ( diff --git a/dotcom-rendering/src/web/server/indexPageToHtml.tsx b/dotcom-rendering/src/web/server/tagFrontToHtml.tsx similarity index 65% rename from dotcom-rendering/src/web/server/indexPageToHtml.tsx rename to dotcom-rendering/src/web/server/tagFrontToHtml.tsx index 4f05d05bfc6..6c73596b345 100644 --- a/dotcom-rendering/src/web/server/indexPageToHtml.tsx +++ b/dotcom-rendering/src/web/server/tagFrontToHtml.tsx @@ -7,34 +7,34 @@ import { generateScriptTags, getScriptsFromManifest } from '../../lib/assets'; import { escapeData } from '../../lib/escapeData'; import { extractNAV } from '../../model/extract-nav'; import { makeWindowGuardian } from '../../model/window-guardian'; -import type { DCRIndexPageType } from '../../types/indexPage'; -import { IndexPagePage } from '../components/IndexPagePage'; +import type { DCRTagFrontType } from '../../types/tagFront'; +import { TagFrontPage } from '../components/TagFrontPage'; import { renderToStringWithEmotion } from '../lib/emotion'; import { getHttp3Url } from '../lib/getHttp3Url'; import { pageTemplate } from './pageTemplate'; interface Props { - indexPage: DCRIndexPageType; + tagFront: DCRTagFrontType; } -export const indexPageToHtml = ({ indexPage }: Props): string => { - const title = indexPage.webTitle; - const NAV = extractNAV(indexPage.nav); +export const tagFrontToHtml = ({ tagFront }: Props): string => { + const title = tagFront.webTitle; + const NAV = extractNAV(tagFront.nav); const { html, extractedCss } = renderToStringWithEmotion( - , + , ); // Evaluating the performance of HTTP3 over HTTP2 // See: https://github.com/guardian/dotcom-rendering/pull/5394 - const { offerHttp3 = false } = indexPage.config.switches; + const { offerHttp3 = false } = tagFront.config.switches; const polyfillIO = 'https://assets.guim.co.uk/polyfill.io/v3/polyfill.min.js?rum=0&features=es6,es7,es2017,es2018,es2019,default-3.6,HTMLPictureElement,IntersectionObserver,IntersectionObserverEntry,URLSearchParams,fetch,NodeList.prototype.forEach,navigator.sendBeacon,performance.now,Promise.allSettled&flags=gated&callback=guardianPolyfilled&unknown=polyfill&cacheClear=1'; const shouldServeVariantBundle: boolean = [ BUILD_VARIANT, - indexPage.config.abTests[dcrJavascriptBundle('Variant')] === 'variant', + tagFront.config.abTests[dcrJavascriptBundle('Variant')] === 'variant', ].every(Boolean); /** @@ -61,7 +61,7 @@ export const indexPageToHtml = ({ indexPage }: Props): string => { ...getScriptArrayFromFile('frameworks.js'), ...getScriptArrayFromFile('index.js'), process.env.COMMERCIAL_BUNDLE_URL ?? - indexPage.config.commercialBundleUrl, + tagFront.config.commercialBundleUrl, ] .filter(isString) .map((script) => (offerHttp3 ? getHttp3Url(script) : script)), @@ -74,28 +74,28 @@ export const indexPageToHtml = ({ indexPage }: Props): string => { const windowGuardian = escapeData( JSON.stringify( makeWindowGuardian({ - editionId: indexPage.editionId, - stage: indexPage.config.stage, - frontendAssetsFullURL: indexPage.config.frontendAssetsFullURL, - revisionNumber: indexPage.config.revisionNumber, - sentryPublicApiKey: indexPage.config.sentryPublicApiKey, - sentryHost: indexPage.config.sentryHost, - keywordIds: indexPage.config.keywordIds, - dfpAccountId: indexPage.config.dfpAccountId, - adUnit: indexPage.config.adUnit, - ajaxUrl: indexPage.config.ajaxUrl, - googletagUrl: indexPage.config.googletagUrl, - switches: indexPage.config.switches, - abTests: indexPage.config.abTests, - brazeApiKey: indexPage.config.brazeApiKey, + editionId: tagFront.editionId, + stage: tagFront.config.stage, + frontendAssetsFullURL: tagFront.config.frontendAssetsFullURL, + revisionNumber: tagFront.config.revisionNumber, + sentryPublicApiKey: tagFront.config.sentryPublicApiKey, + sentryHost: tagFront.config.sentryHost, + keywordIds: tagFront.config.keywordIds, + dfpAccountId: tagFront.config.dfpAccountId, + adUnit: tagFront.config.adUnit, + ajaxUrl: tagFront.config.ajaxUrl, + googletagUrl: tagFront.config.googletagUrl, + switches: tagFront.config.switches, + abTests: tagFront.config.abTests, + brazeApiKey: tagFront.config.brazeApiKey, // Until we understand exactly what config we need to make available client-side, // add everything we haven't explicitly typed as unknown config - unknownConfig: indexPage.config, + unknownConfig: tagFront.config, }), ), ); - const keywords = indexPage.config.keywords; + const keywords = tagFront.config.keywords; return pageTemplate({ scriptTags, @@ -107,7 +107,7 @@ export const indexPageToHtml = ({ indexPage }: Props): string => { keywords, offerHttp3, renderingTarget: 'Web', - borkFCP: indexPage.config.abTests.borkFcpVariant === 'variant', - borkFID: indexPage.config.abTests.borkFidVariant === 'variant', + borkFCP: tagFront.config.abTests.borkFcpVariant === 'variant', + borkFID: tagFront.config.abTests.borkFidVariant === 'variant', }); };