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

Stop landing pages from rendering at the dynamic route #11354

Merged
merged 7 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions common/services/prismic/link-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ type Props = {
type: string;
siteSection?: SiteSection;
};

// Untransformed data
type DataProps = {
uid?: string;
type: string;
Expand All @@ -20,7 +22,8 @@ type DataProps = {
};

function linkResolver(doc: Props | DataProps): string {
// this is mostly useful for scenarios like rendering in Page Builder
// This is mostly useful for scenarios like rendering in Page Builder
// which doesn't necessarily have access to all data
if (!doc) return '/';

const { uid, type } = doc;
Expand Down Expand Up @@ -52,18 +55,20 @@ function linkResolver(doc: Props | DataProps): string {
}

if (type === 'pages') {
if ('siteSection' in doc) {
return `${doc.siteSection}/${uid}`;
} else if ('tags' in doc) {
// Needed for Prismic previews
const docSiteSection = doc.tags.find(t => isSiteSection(t));
let siteSection: SiteSection | undefined;

const isLandingPage = docSiteSection === uid;
if (isLandingPage) return `/${uid}`;
if ('siteSection' in doc) {
siteSection = doc.siteSection;
}

return `${docSiteSection ? '/' + docSiteSection : ''}/${uid}`;
// Prismic previews come through here.
if ('tags' in doc) {
Copy link
Contributor

Choose a reason for hiding this comment

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

does this mean that if there is a sitesection tag, it would take precedence over doc.siteSection – and if so is that ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess so yes, and if so it should still be the correct siteSection, so I'd say it's ok!

siteSection = doc.tags.find(t => isSiteSection(t));
}
return `/${uid}`;

const isLandingPage = siteSection === uid;

return isLandingPage || !siteSection ? `/${uid}` : `/${siteSection}/${uid}`;
}

if (isContentType(type)) {
Expand Down
13 changes: 5 additions & 8 deletions content/webapp/pages/events/[eventId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,11 @@ const EventPage: NextPage<EventProps> = ({
url: '/events',
text: 'Events',
},
...event.series.map(series => {
console.log(series);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just removed this log (I could see some logs in Kibana, unsure which ones they are but thought I'd remove the ones we don't need).

return {
url: linkResolver(series),
text: series.title || '',
prefix: 'Part of',
};
}),
...event.series.map(series => ({
url: linkResolver(series),
text: series.title || '',
prefix: 'Part of',
})),
scheduledIn
? {
url: linkResolver(scheduledIn),
Expand Down
6 changes: 5 additions & 1 deletion content/webapp/pages/pages/[pageId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ export const getServerSideProps: GetServerSideProps<
const { pageId } = context.query;
const siteSection = toMaybeString(context.params?.siteSection);

if (!looksLikePrismicId(pageId)) {
const isLandingPageRenderingAsSubPage =
pageId === siteSection &&
context.resolvedUrl === `/${siteSection}/${pageId}`;

if (!looksLikePrismicId(pageId) || isLandingPageRenderingAsSubPage) {
return { notFound: true };
}
rcantin-w marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ describe('transformExhibitionGuide', () => {
it('returns a set of components', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const exhibition = transformExhibitionGuide(exhibitionGuidesDoc as any);
console.log(exhibition.components.length, 'the exhibition');
expect(exhibition.components.length).toBe(2);
});
});
Expand Down