mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 07:33:07 +08:00
Update breadcrumbs for page numbers
This commit is contained in:
@@ -6,10 +6,17 @@ const currentUrlPath = Astro.url.pathname.replace(/\/+$/, "");
|
|||||||
// eg: /tags/tailwindcss => ['tags', 'tailwindcss']
|
// eg: /tags/tailwindcss => ['tags', 'tailwindcss']
|
||||||
const breadcrumbList = currentUrlPath.split("/").slice(1);
|
const breadcrumbList = currentUrlPath.split("/").slice(1);
|
||||||
|
|
||||||
// if breadcrumb is Home > Post > 'article-name'
|
// if breadcrumb is Home > Posts > 1 <etc>
|
||||||
// replace 'article-name' to 'current post'
|
// replace Posts with Posts (page number)
|
||||||
if (breadcrumbList[0] === "posts" && breadcrumbList.length > 1) {
|
if (
|
||||||
breadcrumbList.splice(1, 1, "current post");
|
(breadcrumbList[0] === "posts" && !isNaN(Number(breadcrumbList[1]))) ||
|
||||||
|
(breadcrumbList[0] === "posts" && breadcrumbList.length < 2)
|
||||||
|
) {
|
||||||
|
breadcrumbList.splice(
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
`Posts (page ${breadcrumbList[1] ? breadcrumbList[1] : 1})`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user