Skip to content

Commit

Permalink
EES-4781 redirect incorrect slug urls and sitemap updates
Browse files Browse the repository at this point in the history
  • Loading branch information
amyb-hiveit committed Jun 24, 2024
1 parent b714512 commit e1795ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { logEvent } from '@frontend/services/googleAnalyticsService';
import compact from 'lodash/compact';
import isEqual from 'lodash/isEqual';
import omit from 'lodash/omit';
import Head from 'next/head';
import { useRouter } from 'next/router';
import { ParsedUrlQuery } from 'querystring';

Expand Down Expand Up @@ -278,6 +279,13 @@ const DataCataloguePage: NextPage<Props> = ({ showTypeFilter }) => {
includeDefaultMetaTitle={pageTitle === defaultPageTitle}
metaTitle={pageTitle}
>
<Head>
<link
rel="canonical"
href={`${process.env.PUBLIC_URL}data-catalogue`}
key="canonical"
/>
</Head>
<NotificationBanner title="This page has changed">
Following user feedback we've made some changes to this page to make our
data sets easier to find, if you have any comments on the new design
Expand Down Expand Up @@ -664,6 +672,12 @@ export const getServerSideProps: GetServerSideProps<Props> = async context => {
},
};
}
return {
redirect: {
destination: `/data-catalogue`,
permanent: true,
},
};
}

await queryClient.prefetchQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,20 @@ import methodologyService, {
import publicationService, {
PublicationSitemapItem,
} from '@common/services/publicationService';
// TODO: Add datasets to sitemap once this work has been completed
// https://dfedigital.atlassian.net/browse/EES-5202
// import dataSetService, {
// DataSetSitemapItem,
// } from '@common/services/dataSetService';
import dataSetService, {
DataSetSitemapItem,
} from '@common/services/dataSetService';
import { ISitemapField } from 'next-sitemap';

export default async function getSitemapFields(): Promise<ISitemapField[]> {
const methodologies = await methodologyService.listSitemapItems();
const publications = await publicationService.listSitemapItems();
// TODO: Add datasets to sitemap once this work has been completed
// https://dfedigital.atlassian.net/browse/EES-5202
// const dataSets = await dataSetService.listSitemapItems();
const dataSets = await dataSetService.listSitemapItems();

const sitemapFields: ISitemapField[] = [
...buildMethodologyRoutes(methodologies),
...buildPublicationRoutes(publications),
// TODO: Add datasets to sitemap once this work has been completed
// https://dfedigital.atlassian.net/browse/EES-5202
// ...buildDataSetRoutes(dataSets),
...buildDataSetRoutes(dataSets),
];

return sitemapFields;
Expand All @@ -46,10 +40,6 @@ function buildPublicationRoutes(
publications.forEach(publication => {
fields.push(
...[
{
loc: `${process.env.PROD_PUBLIC_URL}/data-catalogue/${publication.slug}`,
lastmod: publication.lastModified,
},
// TODO: Check if data-tables should be included in the sitemap
// Add <noindex, nofollow> to the data-tables page if not
// Add to robots.txt if not
Expand Down Expand Up @@ -77,10 +67,6 @@ function buildPublicationRoutes(

fields.push(
...[
{
loc: `${process.env.PROD_PUBLIC_URL}/data-catalogue/${publication.slug}`,
lastmod: publication.lastModified,
},
// TODO: Check if data-tables should be included in the sitemap
// Add <noindex, nofollow> to the data-tables page if not
// Add to robots.txt if not
Expand Down Expand Up @@ -123,10 +109,6 @@ function buildPublicationRoutes(
lastmod: release.lastModified,
priority: 0.2,
},
{
loc: `${process.env.PROD_PUBLIC_URL}/data-catalogue/${publication.slug}/${release.slug}`,
lastmod: release.lastModified,
},
// TODO: Check if data-tables should be included in the sitemap
// Add <noindex, nofollow> to the data-tables page if not
// Add to robots.txt if not
Expand All @@ -141,13 +123,11 @@ function buildPublicationRoutes(
return fields;
}

// TODO: Add datasets to sitemap once this work has been completed
// https://dfedigital.atlassian.net/browse/EES-5202
// function buildDataSetRoutes(
// dataSets: DataSetSitemapItem[],
// ): ISitemapField[] {
// return dataSets.map(dataSet => ({
// loc: `${process.env.PROD_PUBLIC_URL}/data-catalogue/data-set/${dataSet.id}`,
// lastmod: dataSet.lastModified,
// }));
// }
function buildDataSetRoutes(dataSets: DataSetSitemapItem[]): ISitemapField[] {
return dataSets.map(dataSet => ({
loc: `${
process.env.PROD_PUBLIC_URL
}/data-catalogue/data-set/${dataSet.id.toLowerCase()}`,
lastmod: dataSet.lastModified,
}));
}

0 comments on commit e1795ea

Please sign in to comment.