-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use breadcrumb generator for read-more links
Signed-off-by: ZTL-UwU <zhangtianli2006@163.com>
- Loading branch information
Showing
3 changed files
with
28 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
interface BreadcrumbItem { | ||
title: string; | ||
href: string; | ||
} | ||
|
||
export function useBreadcrumb(url: string): BreadcrumbItem[] { | ||
const { navigation } = useContent(); | ||
|
||
const breadcrumbItems: BreadcrumbItem[] = []; | ||
// Remove empty segments | ||
const segments = url.split('/').filter(segment => segment !== ''); | ||
|
||
// Construct breadcrumb for each segment | ||
let href = ''; | ||
let nav = navigation.value; | ||
for (let i = 0; i < segments.length; i++) { | ||
const segment = segments[i].replace('.html', ''); | ||
href += `/${segment}`; | ||
const page = nav.find(x => (x._path as string) === href); | ||
nav = page?.children; | ||
breadcrumbItems.push({ title: page?.title ?? segment, href }); | ||
} | ||
return breadcrumbItems; | ||
} |