Skip to content

Commit e1f8bc4

Browse files
committed
use hosted content which is an adaptation of article type rather than defining from scratch or using article directly
1 parent 18a66c9 commit e1f8bc4

7 files changed

Lines changed: 95 additions & 36 deletions

File tree

dotcom-rendering/src/components/HostedContentPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { HostedArticleLayout } from '../layouts/HostedArticleLayout';
44
import { ArticleDesign } from '../lib/articleFormat';
55
import { rootStyles } from '../lib/rootStyles';
66
import { filterABTestSwitches } from '../model/enhance-switches';
7-
import type { Article } from '../types/article';
7+
import type { HostedContent } from '../types/hostedContent';
88
import type { RenderingTarget } from '../types/renderingTarget';
99
import { useConfig } from './ConfigContext';
1010
import { DarkModeMessage } from './DarkModeMessage';
@@ -16,7 +16,7 @@ import { SetABTests } from './SetABTests.importable';
1616
import { SkipTo } from './SkipTo';
1717

1818
interface BaseProps {
19-
hostedContent: Article;
19+
hostedContent: HostedContent;
2020
renderingTarget: RenderingTarget;
2121
}
2222

dotcom-rendering/src/frontend/feHostedContent.ts

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
1-
/** @todo Remove this? */
2-
export interface FEHostedContent {
3-
// general / shared
4-
id: string;
5-
url: string;
6-
encodedUrl: string;
7-
campaign?: HostedCampaign;
8-
title: string;
9-
mainImageUrl: string;
10-
thumbnailUrl: string;
11-
standfirst: string;
12-
cta: HostedCallToAction;
13-
name: string;
14-
owner: string;
15-
logo: HostedLogo;
16-
fontColour: Colour;
17-
// article
18-
body?: string;
19-
mainPicture?: string;
20-
mainPictureCaption?: string;
21-
// video
22-
video?: HostedVideo;
23-
// gallery
24-
images: HostedGalleryImage[];
25-
}
1+
import type { FEArticle } from './feArticle';
2+
3+
/**
4+
* This type is what we receive from `frontend`,
5+
* hence the FE prefix.
6+
*
7+
* WARNING: run `gen-schema` task if changing this to update the associated JSON
8+
* schema definition.
9+
*/
10+
export type FEHostedContent = Omit<
11+
FEArticle,
12+
'beaconURL' | 'blocks' | 'crossword'
13+
>;
14+
15+
/**
16+
// Not sure if the following types are needed:
2617
2718
type HostedCampaign = {
2819
id: string;
@@ -76,3 +67,5 @@ type Encoding = {
7667
url: string;
7768
rawFormat: string;
7869
};
70+
71+
*/

dotcom-rendering/src/layouts/HostedArticleLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { palette as sourcePalette } from '@guardian/source/foundations';
33
import { HostedContentHeader } from '../components/HostedContentHeader';
44
import { Section } from '../components/Section';
55
import { grid } from '../grid';
6-
import type { DCRHostedContent } from '../types/hostedContent';
6+
import type { HostedContent } from '../types/hostedContent';
77
import type { RenderingTarget } from '../types/renderingTarget';
88
import { Stuck } from './lib/stickiness';
99

1010
interface Props {
1111
renderingTarget: RenderingTarget;
12-
content: DCRHostedContent;
12+
content: HostedContent;
1313
}
1414

1515
interface WebProps extends Props {

dotcom-rendering/src/server/handler.hostedContent.apps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { RequestHandler } from 'express';
22
import { validateAsFEHostedContent } from '../model/validate';
3-
import { enhanceHostedContentType } from '../types/hostedContent';
3+
import { enhanceHostedContent } from '../types/hostedContent';
44
import { makePrefetchHeader } from './lib/header';
55
import { renderHtml } from './render.hostedContent.web';
66

77
export const handleAppsHostedContent: RequestHandler = ({ body }, res) => {
88
const frontendData = validateAsFEHostedContent(body);
9-
const hostedContent = enhanceHostedContentType(frontendData);
9+
const hostedContent = enhanceHostedContent(frontendData);
1010
const { html, prefetchScripts } = renderHtml({
1111
hostedContent,
1212
});

dotcom-rendering/src/server/handler.hostedContent.web.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { RequestHandler } from 'express';
22
import { validateAsFEHostedContent } from '../model/validate';
3-
import { enhanceHostedContentType } from '../types/hostedContent';
3+
import { enhanceHostedContent } from '../types/hostedContent';
44
import { makePrefetchHeader } from './lib/header';
55
import { renderHtml } from './render.hostedContent.web';
66

77
export const handleHostedContent: RequestHandler = ({ body }, res) => {
88
const frontendData = validateAsFEHostedContent(body);
9-
const hostedContent = enhanceHostedContentType(frontendData);
9+
const hostedContent = enhanceHostedContent(frontendData);
1010
const { html, prefetchScripts } = renderHtml({
1111
hostedContent,
1212
});

dotcom-rendering/src/server/render.hostedContent.web.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import {
1010
import { renderToStringWithEmotion } from '../lib/emotion';
1111
import { polyfillIO } from '../lib/polyfill.io';
1212
import { createGuardian } from '../model/guardian';
13-
import type { Article } from '../types/article';
1413
import type { Config } from '../types/configContext';
14+
import type { HostedContent } from '../types/hostedContent';
1515
import { htmlPageTemplate } from './htmlPageTemplate';
1616

1717
type Props = {
18-
hostedContent: Article;
18+
hostedContent: HostedContent;
1919
};
2020

2121
export const renderHtml = ({ hostedContent }: Props) => {
Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,69 @@
1+
import type { FEHostedContent } from '../frontend/feHostedContent';
2+
import {
3+
ArticleDesign,
4+
ArticleDisplay,
5+
ArticleSpecial,
6+
} from '../lib/articleFormat';
7+
import { enhanceMainMedia } from '../model/enhanceBlocks';
8+
import { enhanceCommercialProperties } from '../model/enhanceCommercialProperties';
9+
import { enhanceStandfirst } from '../model/enhanceStandfirst';
110
import type { Article } from './article';
211

3-
export type DCRHostedContent = Article;
12+
export type HostedContent = Article;
13+
14+
export const enhanceHostedContent = (data: FEHostedContent): HostedContent => {
15+
// Temporarily hard coded
16+
const format = {
17+
display: ArticleDisplay.Standard,
18+
design: ArticleDesign.HostedArticle,
19+
theme: ArticleSpecial.Labs,
20+
};
21+
22+
const serverTime = Date.now();
23+
24+
/** @todo implement blocks */
25+
// const enhancedBlocks = enhanceBlocks(data.blocks, format, {
26+
// renderingTarget,
27+
// promotedNewsletter: data.promotedNewsletter,
28+
// imagesForLightbox: [],
29+
// hasAffiliateLinksDisclaimer: !!data.affiliateLinksDisclaimer,
30+
// audioArticleImage: data.audioArticleImage,
31+
// tags: data.tags,
32+
// shouldHideAds: data.shouldHideAds,
33+
// pageId: data.pageId,
34+
// });
35+
36+
const mainMediaElements = enhanceMainMedia(
37+
format,
38+
[], //imagesForLightbox
39+
true,
40+
data.main,
41+
)(data.mainMediaElements);
42+
43+
/** @ts-expect-error -- @todo fix this! */
44+
return {
45+
design: format.design,
46+
display: format.display,
47+
theme: format.theme,
48+
serverTime,
49+
storyPackage: undefined,
50+
frontendData: {
51+
...data,
52+
beaconURL: '',
53+
mainMediaElements,
54+
blocks: [],
55+
standfirst: enhanceStandfirst(data.standfirst),
56+
commercialProperties: enhanceCommercialProperties(
57+
data.commercialProperties,
58+
),
59+
/**
60+
* This function needs to run at a higher level to most other enhancers
61+
* because it needs both mainMediaElements and blocks in scope
62+
* @todo implement for Hosted Content pages
63+
*/
64+
imagesForLightbox: [],
65+
/** @todo implement for Hosted Content pages */
66+
imagesForAppsLightbox: [],
67+
},
68+
};
69+
};

0 commit comments

Comments
 (0)