forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.ts
More file actions
72 lines (65 loc) · 1.9 KB
/
Copy pathroute.ts
File metadata and controls
72 lines (65 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { source } from "@/app/source";
import { findNeighbour } from "fumadocs-core/page-tree";
import { patchPageTree } from "@/lib/patch-pagetree";
import { NextResponse } from "next/server";
export async function GET() {
const allPages = source.getPages();
const patchedTree = patchPageTree(source.pageTree);
const pagesWithNoNeighbors: Array<{
url: string;
title: string;
slugs: string[];
}> = [];
const pagesWithOneNeighbor: Array<{
url: string;
title: string;
slugs: string[];
hasPrev: boolean;
hasNext: boolean;
prevUrl?: string;
nextUrl?: string;
}> = [];
// Check each page for neighbors
for (const page of allPages) {
const { previous, next } = findNeighbour(patchedTree, page.url);
const hasPrev = !!previous;
const hasNext = !!next;
if (!hasPrev && !hasNext) {
pagesWithNoNeighbors.push({
url: page.url,
title: page.data.title || "Untitled",
slugs: Array.isArray(page.slugs) ? page.slugs : [],
});
} else if ((hasPrev && !hasNext) || (!hasPrev && hasNext)) {
pagesWithOneNeighbor.push({
url: page.url,
title: page.data.title || "Untitled",
slugs: Array.isArray(page.slugs) ? page.slugs : [],
hasPrev,
hasNext,
prevUrl: previous?.url,
nextUrl: next?.url,
});
}
}
return NextResponse.json(
{
summary: {
totalPages: allPages.length,
pagesWithNoNeighbors: pagesWithNoNeighbors.length,
pagesWithOneNeighbor: pagesWithOneNeighbor.length,
pagesWithBothNeighbors:
allPages.length -
pagesWithNoNeighbors.length -
pagesWithOneNeighbor.length,
},
pagesWithNoNeighbors,
pagesWithOneNeighbor: pagesWithOneNeighbor.slice(0, 20), // Limit to first 20 for readability
},
{
headers: {
"Content-Type": "application/json",
},
},
);
}