Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webapp",
"version": "2.31.3",
"version": "2.31.4",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
52 changes: 52 additions & 0 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { MetadataRoute } from 'next';

import { fetchSitemapJobs } from '@/features/jobs/server/data';
import { fetchPillarSitemapSlugs } from '@/features/pillar/server/data';
import { clientEnv } from '@/lib/env/client';

export const revalidate = 3600;

const FRONTEND_URL = clientEnv.FRONTEND_URL;
const PILLAR_CHUNK_SIZE = 3000;

export async function generateSitemaps() {
const slugs = await fetchPillarSitemapSlugs();
const numChunks = Math.ceil(slugs.length / PILLAR_CHUNK_SIZE);

return [
{ id: 'static' },
...Array.from({ length: numChunks }, (_, i) => ({ id: `pillar-${i}` })),
{ id: 'jobs' },
];
}

export default async function sitemap({
id,
}: {
id: Promise<string>;
}): Promise<MetadataRoute.Sitemap> {
const resolvedId = await id;

if (resolvedId === 'static') {
return [{ url: FRONTEND_URL }];
}

if (resolvedId === 'jobs') {
const jobs = await fetchSitemapJobs();
return jobs.map(({ href, lastModified }) => ({
url: `${FRONTEND_URL}${href}`,
lastModified,
}));
}

// pillar-0, pillar-1, pillar-2, ...
const chunkIndex = Number(resolvedId.split('-')[1]);
const slugs = await fetchPillarSitemapSlugs();
const start = chunkIndex * PILLAR_CHUNK_SIZE;
const chunk = slugs.slice(start, start + PILLAR_CHUNK_SIZE);

return chunk.map(({ slug, lastModified }) => ({
url: `${FRONTEND_URL}/${slug}`,
lastModified: new Date(lastModified),
}));
}
22 changes: 17 additions & 5 deletions src/app/sitemap.xml/route.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import { fetchPillarSitemapSlugs } from '@/features/pillar/server/data';
import { clientEnv } from '@/lib/env/client';

export const dynamic = 'force-static';
export const revalidate = 3600;

const FRONTEND_URL = clientEnv.FRONTEND_URL;
const PILLAR_CHUNK_SIZE = 3000;

export async function GET() {
const slugs = await fetchPillarSitemapSlugs();
const numChunks = Math.ceil(slugs.length / PILLAR_CHUNK_SIZE);

const sitemaps = [
`${FRONTEND_URL}/sitemap/static.xml`,
...Array.from(
{ length: numChunks },
(_, i) => `${FRONTEND_URL}/sitemap/pillar-${i}.xml`,
),
`${FRONTEND_URL}/sitemap/jobs.xml`,
];

export function GET() {
const xml = [
'<?xml version="1.0" encoding="UTF-8"?>',
'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
` <sitemap><loc>${FRONTEND_URL}/sitemap1.xml</loc></sitemap>`,
` <sitemap><loc>${FRONTEND_URL}/sitemap2.xml</loc></sitemap>`,
` <sitemap><loc>${FRONTEND_URL}/sitemap3.xml</loc></sitemap>`,
...sitemaps.map((loc) => ` <sitemap><loc>${loc}</loc></sitemap>`),
'</sitemapindex>',
].join('\n');

Expand Down
18 changes: 0 additions & 18 deletions src/app/sitemap1.xml/route.ts

This file was deleted.

35 changes: 0 additions & 35 deletions src/app/sitemap2.xml/route.ts

This file was deleted.

35 changes: 0 additions & 35 deletions src/app/sitemap3.xml/route.ts

This file was deleted.

Loading