Skip to content

Commit 84576c2

Browse files
committed
updated 404 search-link population to discard any hash part of url path
1 parent a1de05b commit 84576c2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/pages/404.astro

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ import Layout from "../layouts/BaseLayout.astro";
44
/**
55
* Returns the last (non-empty) segment from the slash-separated path, or ""
66
*
7+
* Discards any hash part of the URL before splitting it.
8+
*
79
* @param path string to extract the last part of
810
* @returns the last non-empty segment or an empty string
911
*
1012
* @example
11-
* an input of `/reference/p5/basematerialshader/` will return `basematerialshader`
13+
* An input of `/reference/p5/basematerialshader/` will return `basematerialshader`
14+
* An input of `/reference/p5.Vector/dist/#Examples` will return `dist`
1215
*/
1316
function getLastPathElementOrEmptyString(path: string): string {
14-
return path.split("/").filter(Boolean).pop() ?? "";
17+
//Get the part of the path before the (first) hash
18+
const preHashPath = path.split("#")[0] ?? "";
19+
//Then get the last non-empty slash-separated segment from that
20+
return preHashPath.split("/").filter(Boolean).pop() ?? "";
1521
}
1622
1723
const currentPath = Astro.url.pathname;

0 commit comments

Comments
 (0)