Update breadcrumbs for page numbers

This commit is contained in:
Sat Naing
2022-09-20 22:20:20 +06:30
parent e5b2f04f9a
commit fc8ce30a9d
+11 -4
View File
@@ -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})`
);
} }
--- ---