Skip to content

Commit f6bacea

Browse files
authored
Skip hidden pages in sitemap.xml (#2388)
1 parent ba2a523 commit f6bacea

File tree

1 file changed

+6
-3
lines changed
  • src/app/(space)/(core)/sitemap.xml

1 file changed

+6
-3
lines changed

src/app/(space)/(core)/sitemap.xml/route.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const runtime = 'edge';
1515
*/
1616
export async function GET(req: NextRequest) {
1717
const { pages: rootPages } = await getSpaceContentData(getContentPointer());
18-
const pages = flattenPages(rootPages);
18+
const pages = flattenPages(rootPages, (page) => !page.hidden);
1919
const urls = pages.map(({ page, depth }) => {
2020
// Decay priority with depth
2121
const priority = Math.pow(2, -0.25 * depth);
@@ -66,13 +66,16 @@ export async function GET(req: NextRequest) {
6666

6767
type FlatPageEntry = { page: RevisionPageDocument; depth: number };
6868

69-
function flattenPages(rootPags: RevisionPage[]): FlatPageEntry[] {
69+
function flattenPages(
70+
rootPags: RevisionPage[],
71+
filter: (page: RevisionPageDocument) => boolean,
72+
): FlatPageEntry[] {
7073
const flattenPage = (
7174
page: RevisionPageDocument | RevisionPageGroup,
7275
depth: number,
7376
): FlatPageEntry[] => {
7477
return [
75-
...(page.type === 'document' ? [{ page, depth }] : []),
78+
...(page.type === 'document' && filter(page) ? [{ page, depth }] : []),
7679
...page.pages.flatMap((child) =>
7780
child.type === 'link' ? [] : flattenPage(child, depth + 1),
7881
),

0 commit comments

Comments
 (0)