From b8c011410d6bcd6837f4efd6a3948196a0f7aeea Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Sat, 10 Jun 2023 06:06:02 +0000
Subject: [PATCH] toc

---
 quartz/path.ts |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/quartz/path.ts b/quartz/path.ts
index 4f3bfa7..bece770 100644
--- a/quartz/path.ts
+++ b/quartz/path.ts
@@ -1,7 +1,7 @@
 import path from 'path'
 import SlugAnchor from 'github-slugger'
 
-const slugAnchor = new SlugAnchor()
+export const slugAnchor = new SlugAnchor()
 
 function slugSegment(s: string): string {
   return s.replace(/\s/g, '-')
@@ -22,11 +22,15 @@
 // resolve /a/b/c to ../../
 export function resolveToRoot(slug: string): string {
   let fp = slug
-  if (fp.endsWith("/index")) {
-    fp = fp.slice(0, -"/index".length)
+  if (fp.endsWith("index")) {
+    fp = fp.slice(0, -"index".length)
   }
 
-  return fp
+  if (fp === "") {
+    return "."
+  }
+
+  return "./" + fp
     .split('/')
     .filter(x => x !== '')
     .map(_ => '..')

--
Gitblit v1.10.0