Skip to content

Commit

Permalink
hotfix(sitemap): update to field-translated dynamic pages and custome…
Browse files Browse the repository at this point in the history
…r cases
  • Loading branch information
mathiazom committed Oct 28, 2024
1 parent 7bfeca0 commit 2bd7b5c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
47 changes: 26 additions & 21 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { client } from "studio/lib/client";
import {
DocumentTranslatedSitemapData,
FieldTranslatedSitemapData,
SingleTranslationSitemapData,
SitemapBaseData,
UntranslatedSitemapData,
} from "studio/lib/interfaces/sitemap";
import { LanguageObject } from "studio/lib/interfaces/supportedLanguages";
import { LEGAL_DOCUMENTS_SITEMAP_QUERY } from "studio/lib/queries/admin";
Expand Down Expand Up @@ -73,43 +73,48 @@ async function compensationsPageSitemap(): Promise<RelativeSiteMap> {
}

async function dynamicPagesSitemap(): Promise<RelativeSiteMap> {
const pages = await clientWithToken.fetch<UntranslatedSitemapData[] | null>(
PAGES_SITEMAP_QUERY,
);
const pages = await clientWithToken.fetch<
FieldTranslatedSitemapData[] | null
>(PAGES_SITEMAP_QUERY);
if (pages !== null) {
return pages.map((page) => ({
relativeUrl: page.slug.current,
lastModified: new Date(page._updatedAt),
}));
return pages.flatMap((page) =>
page.slug.map((slug) => ({
relativeUrl: `${slug._key}/${slug.value}`,
lastModified: new Date(page._updatedAt),
})),
);
}
return [];
}

async function customerCasesSitemap(): Promise<RelativeSiteMap> {
const page = await clientWithToken.fetch<UntranslatedSitemapData | null>(
const page = await clientWithToken.fetch<FieldTranslatedSitemapData | null>(
CUSTOMER_CASES_PAGE_SITEMAP_QUERY,
);
if (page !== null) {
const siteMap = [
{
relativeUrl: page.slug.current,
lastModified: new Date(page._updatedAt),
},
];
if (page?.slug === undefined) {
return [];
}
const siteMap = [];
for (const slug of page.slug) {
siteMap.push({
relativeUrl: `${slug._key}/${slug.value}`,
lastModified: new Date(page._updatedAt),
});
const cases = await sharedClientWithToken.fetch<
DocumentTranslatedSitemapData[] | null
>(CUSTOMER_CASES_SITEMAP_QUERY);
SingleTranslationSitemapData[] | null
>(CUSTOMER_CASES_SITEMAP_QUERY, {
language: slug._key,
});
if (cases !== null) {
siteMap.push(
...cases.map((customerCase) => ({
relativeUrl: `${customerCase.language}/${page.slug.current}/${customerCase.slug.current}`,
relativeUrl: `${slug._key}/${slug.value}/${customerCase.slug}`,
lastModified: new Date(customerCase._updatedAt),
})),
);
}
return siteMap;
}
return [];
return siteMap;
}

async function legalDocumentsSitemap(): Promise<RelativeSiteMap> {
Expand Down
4 changes: 4 additions & 0 deletions studio/lib/interfaces/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export interface FieldTranslatedSitemapData extends SitemapBaseData {
slug: InternationalizedString;
}

export interface SingleTranslationSitemapData extends SitemapBaseData {
slug: string;
}

export interface UntranslatedSitemapData extends SitemapBaseData {
slug: Slug;
}
Expand Down
3 changes: 1 addition & 2 deletions studioShared/lib/queries/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export const CUSTOMER_CASE_QUERY = groq`
export const CUSTOMER_CASES_SITEMAP_QUERY = groq`
*[_type == "customerCase"] {
_updatedAt,
language,
slug
"slug": ${translatedFieldFragment("slug")}
}
`;

0 comments on commit 2bd7b5c

Please sign in to comment.