From 06ee73e006fedef64d326aae8909bcc4ca5b243a Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Mon, 05 Feb 2024 05:22:57 +0000
Subject: [PATCH] fix(path): properly path encode &

---
 quartz/util/path.test.ts |    3 ++-
 quartz/util/path.ts      |    7 ++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/quartz/util/path.test.ts b/quartz/util/path.test.ts
index 6a8aa3d..7e9c4c8 100644
--- a/quartz/util/path.test.ts
+++ b/quartz/util/path.test.ts
@@ -106,8 +106,9 @@
         ["test.mp4", "test.mp4"],
         ["note with spaces.md", "note-with-spaces"],
         ["notes.with.dots.md", "notes.with.dots"],
-        ["test/special chars?.md", "test/special-chars-q"],
+        ["test/special chars?.md", "test/special-chars"],
         ["test/special chars #3.md", "test/special-chars-3"],
+        ["cool/what about r&d?.md", "cool/what-about-r-and-d"],
       ],
       path.slugifyFilePath,
       path.isFilePath,
diff --git a/quartz/util/path.ts b/quartz/util/path.ts
index 07f25a5..5cd79ba 100644
--- a/quartz/util/path.ts
+++ b/quartz/util/path.ts
@@ -51,7 +51,12 @@
   return s
     .split("/")
     .map((segment) =>
-      segment.replace(/\s/g, "-").replace(/%/g, "-percent").replace(/\?/g, "-q").replace(/#/g, ""),
+      segment
+        .replace(/\s/g, "-")
+        .replace(/&/g, "-and-")
+        .replace(/%/g, "-percent")
+        .replace(/\?/g, "")
+        .replace(/#/g, ""),
     )
     .join("/") // always use / as sep
     .replace(/\/$/, "")

--
Gitblit v1.10.0