From 2f6747b1666316e579c6e7238092ac6a65d00925 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Thu, 17 Aug 2023 05:04:15 +0000
Subject: [PATCH] fix relative path resolution in router and link crawling

---
 quartz/util/path.test.ts |   27 +++++++++++++--------------
 1 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/quartz/path.test.ts b/quartz/util/path.test.ts
similarity index 96%
rename from quartz/path.test.ts
rename to quartz/util/path.test.ts
index d86bca5..5655585 100644
--- a/quartz/path.test.ts
+++ b/quartz/util/path.test.ts
@@ -53,8 +53,6 @@
     assert(!path.isRelativeURL("abc"))
     assert(!path.isRelativeURL("/abc/def"))
     assert(!path.isRelativeURL(""))
-    assert(!path.isRelativeURL("../"))
-    assert(!path.isRelativeURL("./"))
     assert(!path.isRelativeURL("./abc/def.html"))
     assert(!path.isRelativeURL("./abc/def.md"))
   })
@@ -160,17 +158,18 @@
       [
         ["", "."],
         [".", "."],
-        ["./", "."],
-        ["./index", "."],
-        ["./index.html", "."],
-        ["./index.md", "."],
+        ["./", "./"],
+        ["./index", "./"],
+        ["./index.html", "./"],
+        ["./index.md", "./"],
         ["content", "./content"],
         ["content/test.md", "./content/test"],
         ["./content/test.md", "./content/test"],
         ["../content/test.md", "../content/test"],
-        ["tags/", "./tags"],
-        ["/tags/", "./tags"],
+        ["tags/", "./tags/"],
+        ["/tags/", "./tags/"],
         ["content/with spaces", "./content/with-spaces"],
+        ["content/with spaces/index", "./content/with-spaces/"],
         ["content/with spaces#and Anchor!", "./content/with-spaces#and-anchor"],
       ],
       path.transformInternalLink,
@@ -269,16 +268,16 @@
     test("from a/b/c", () => {
       const cur = "a/b/c" as CanonicalSlug
       assert.strictEqual(path.transformLink(cur, "d", opts), "./d")
-      assert.strictEqual(path.transformLink(cur, "index", opts), ".")
-      assert.strictEqual(path.transformLink(cur, "../../index", opts), "../..")
-      assert.strictEqual(path.transformLink(cur, "../../", opts), "../..")
+      assert.strictEqual(path.transformLink(cur, "index", opts), "./")
+      assert.strictEqual(path.transformLink(cur, "../../index", opts), "../../")
+      assert.strictEqual(path.transformLink(cur, "../../", opts), "../../")
       assert.strictEqual(path.transformLink(cur, "../../e/g/h", opts), "../../e/g/h")
     })
 
     test("from a/b/index", () => {
       const cur = "a/b" as CanonicalSlug
-      assert.strictEqual(path.transformLink(cur, "../../index", opts), "../..")
-      assert.strictEqual(path.transformLink(cur, "../../", opts), "../..")
+      assert.strictEqual(path.transformLink(cur, "../../index", opts), "../../")
+      assert.strictEqual(path.transformLink(cur, "../../", opts), "../../")
       assert.strictEqual(path.transformLink(cur, "../../e/g/h", opts), "../../e/g/h")
       assert.strictEqual(path.transformLink(cur, "c", opts), "./c")
     })
@@ -286,7 +285,7 @@
     test("from index", () => {
       const cur = "" as CanonicalSlug
       assert.strictEqual(path.transformLink(cur, "e/g/h", opts), "./e/g/h")
-      assert.strictEqual(path.transformLink(cur, "a/b/index", opts), "./a/b")
+      assert.strictEqual(path.transformLink(cur, "a/b/index", opts), "./a/b/")
     })
   })
 })

--
Gitblit v1.10.0