File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff 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 */
1316function 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
1723const currentPath = Astro .url .pathname ;
You can’t perform that action at this time.
0 commit comments