From 9c8fec06d2b58e4e3bbe280ddc665a99fcc4878c Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Sun, 09 Mar 2025 22:33:15 +0000
Subject: [PATCH] feat: support non-singleton search

---
 quartz/util/path.ts |   32 ++++++++++++++++++++------------
 1 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/quartz/util/path.ts b/quartz/util/path.ts
index d2409e1..8f85029 100644
--- a/quartz/util/path.ts
+++ b/quartz/util/path.ts
@@ -1,9 +1,6 @@
 import { slug as slugAnchor } from "github-slugger"
 import type { Element as HastElement } from "hast"
-import rfdc from "rfdc"
-
-export const clone = rfdc()
-
+import { clone } from "./clone"
 // this file must be isomorphic so it can't use node libs (e.g. path)
 
 export const QUARTZ = "quartz"
@@ -183,15 +180,26 @@
 }
 
 export function joinSegments(...args: string[]): string {
-  return args
-    .filter((segment) => segment !== "")
-    .map((segment, index) =>
-      index === 0
-        ? // Deduplicate but not remove leading slashes for first segment
-          segment.replace(/\/+$/g, "").replace(/^\/\/+/g, "/")
-        : segment.replace(/^\/+|\/+$/g, ""),
-    )
+  if (args.length === 0) {
+    return ""
+  }
+
+  let joined = args
+    .filter((segment) => segment !== "" && segment !== "/")
+    .map((segment) => stripSlashes(segment))
     .join("/")
+
+  // if the first segment starts with a slash, add it back
+  if (args[0].startsWith("/")) {
+    joined = "/" + joined
+  }
+
+  // if the last segment is a folder, add a trailing slash
+  if (args[args.length - 1].endsWith("/")) {
+    joined = joined + "/"
+  }
+
+  return joined
 }
 
 export function getAllSegmentPrefixes(tags: string): string[] {

--
Gitblit v1.10.0