Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle crossword articles #12925

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions dotcom-rendering/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@guardian/libs": "19.2.1",
"@guardian/ophan-tracker-js": "2.2.5",
"@guardian/react-crossword": "2.0.2",
"@guardian/react-crossword-next": "npm:@guardian/[email protected]",
Copy link
Contributor

@JamieB-gu JamieB-gu Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the plan to merge this PR with the preview version of the dependency in use?

"@guardian/shimport": "1.0.2",
"@guardian/source": "8.0.0",
"@guardian/source-development-kitchen": "12.0.0",
Expand Down
22 changes: 18 additions & 4 deletions dotcom-rendering/scripts/env/check-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@ if (pkg.devDependencies) {
process.exit(1);
}

const mismatches = Object.entries(pkg.dependencies).filter(
([, version]) =>
!semver.valid(version) && !version.startsWith('workspace:'),
);
/**
* We don't check packages that are not semver-compatible
* @type {RegExp[]}
*/
const exceptions = /** @type {const} */ ([
/npm:@guardian\/[email protected]/,
]);

const mismatches = Object.entries(pkg.dependencies)
.filter(
([, version]) =>
!exceptions.some((exception) => exception.test(version)),
)

.filter(
([, version]) =>
!semver.valid(version) && !version.startsWith('workspace:'),
);

if (mismatches.length !== 0) {
warn('dotcom-rendering dependencies should be pinned.');
Expand Down
6 changes: 6 additions & 0 deletions dotcom-rendering/src/components/Crossword.importable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Crossword as ReactCrossword } from '@guardian/react-crossword-next';
import type { CrosswordProps } from '@guardian/react-crossword-next';

export const Crossword = (data: CrosswordProps['data']) => (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you considering data to be the "props" to this component? So that each property in the data object is a separate prop that can be passed individually?

<ReactCrossword data={data} clueMinWidth={150} />
);
7 changes: 7 additions & 0 deletions dotcom-rendering/src/lib/renderElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CartoonComponent } from '../components/CartoonComponent';
import { ChartAtom } from '../components/ChartAtom.importable';
import { CodeBlockComponent } from '../components/CodeBlockComponent';
import { CommentBlockComponent } from '../components/CommentBlockComponent';
import { Crossword } from '../components/Crossword.importable';
import { DividerBlockComponent } from '../components/DividerBlockComponent';
import { DocumentBlockComponent } from '../components/DocumentBlockComponent.importable';
import { EmailSignUpWrapper } from '../components/EmailSignUpWrapper';
Expand Down Expand Up @@ -841,6 +842,12 @@ export const renderElement = ({
case 'model.dotcomrendering.pageElements.DisclaimerBlockElement': {
return <AffiliateDisclaimerInline />;
}
case 'model.dotcomrendering.pageElements.CrosswordElement':
return (
<Island priority="critical" defer={{ until: 'visible' }}>
<Crossword {...element.crossword} />
</Island>
);
case 'model.dotcomrendering.pageElements.AudioBlockElement':
case 'model.dotcomrendering.pageElements.ContentAtomBlockElement':
case 'model.dotcomrendering.pageElements.GenericAtomBlockElement':
Expand Down
Loading
Loading