Skip to content

Commit 44f893e

Browse files
fix: Corrected blog navigation links
1 parent 50d6991 commit 44f893e

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/components/Layout/getRouteMeta.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export interface RouteItem {
3737
sectionHeader?: string;
3838
/** Whether it should be omitted in breadcrumbs */
3939
skipBreadcrumb?: boolean;
40+
41+
/** Optional fields used only for blog routes */
42+
icon?: string;
43+
date?: string;
4044
}
4145

4246
export interface Routes {
@@ -63,6 +67,21 @@ type TraversalContext = RouteMeta & {
6367
};
6468

6569
export function getRouteMeta(cleanedPath: string, routeTree: RouteItem) {
70+
// Locate the '/blog' route from the top-level route tree.
71+
// This is needed so we can sort the individual blog post routes by date.
72+
const blogRoute = routeTree.routes?.find((r) => r.path === '/blog');
73+
74+
// The blog route contains multiple blog posts.
75+
// We sort them by date (oldest to newest) to ensure that
76+
// getRouteMeta can correctly determine previous/next blog posts.
77+
if (blogRoute && Array.isArray(blogRoute.routes)) {
78+
blogRoute.routes = blogRoute.routes
79+
.filter((r) => r.icon === 'blog' && r.date)
80+
.sort(
81+
(a, b) => new Date(a.date!).getTime() - new Date(b.date!).getTime()
82+
);
83+
}
84+
6685
const breadcrumbs = getBreadcrumbs(cleanedPath, routeTree);
6786
const ctx: TraversalContext = {
6887
currentIndex: 0,
@@ -75,7 +94,6 @@ export function getRouteMeta(cleanedPath: string, routeTree: RouteItem) {
7594
};
7695
}
7796

78-
// Performs a depth-first search to find the current route and its previous/next route
7997
function buildRouteMeta(
8098
searchPath: string,
8199
currentRoute: RouteItem,

0 commit comments

Comments
 (0)