From 76c092dcf20959bc52fcb13b28cee50cd4217e40 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Thu, 20 Jul 2023 04:59:48 +0000
Subject: [PATCH] add custom.scss

---
 quartz/path.ts |   32 +++++++++++++++++++++-----------
 1 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/quartz/path.ts b/quartz/path.ts
index 4a0bbb0..5e1feb2 100644
--- a/quartz/path.ts
+++ b/quartz/path.ts
@@ -43,8 +43,8 @@
 //                                             └────────────┤ MD File ├─────┴─────────────────┘
 //                                                          └─────────┘
 
-const STRICT_TYPE_CHECKS = true
-const HARD_EXIT_ON_FAIL = true
+const STRICT_TYPE_CHECKS = false
+const HARD_EXIT_ON_FAIL = false
 
 function conditionCheck<T>(name: string, label: 'pre' | 'post', s: T, chk: (x: any) => x is T) {
   if (STRICT_TYPE_CHECKS && !chk(s)) {
@@ -134,12 +134,17 @@
   conditionCheck(slugifyFilePath.name, 'pre', fp, isFilePath)
   fp = _stripSlashes(fp) as FilePath
   const withoutFileExt = fp.replace(new RegExp(_getFileExtension(fp) + '$'), '')
-  const slug = withoutFileExt
+  let slug = withoutFileExt
     .split('/')
     .map((segment) => segment.replace(/\s/g, '-')) // slugify all segments
     .join('/') // always use / as sep
     .replace(/\/$/, '') // remove trailing slash
 
+  // treat _index as index
+  if (_endsWith(slug, "_index")) {
+    slug = slug.replace(/_index$/, "index")
+  }
+
   conditionCheck(slugifyFilePath.name, 'post', slug, isServerSlug)
   return slug as ServerSlug
 }
@@ -156,10 +161,7 @@
   }
 
   fp = canonicalizeServer(slugifyFilePath(fp as FilePath))
-
-  if (fp.endsWith("index")) {
-    fp = fp.slice(0, -"index".length)
-  }
+  fp = _trimSuffix(fp, "index")
 
   let joined = joinSegments(_stripSlashes(prefix), _stripSlashes(fp))
   const res = _addRelativeToStart(joined) + anchor as RelativeURL
@@ -202,13 +204,21 @@
 export const QUARTZ = "quartz"
 
 function _canonicalize(fp: string): string {
-  if (fp.endsWith("index")) {
-    fp = fp.slice(0, -"index".length)
-  }
-
+  fp = _trimSuffix(fp, "index")
   return _stripSlashes(fp) 
 }
 
+function _endsWith(s: string, suffix: string): boolean {
+  return s === suffix || s.endsWith("/" + suffix) 
+}
+
+function _trimSuffix(s: string, suffix: string): string {
+  if (_endsWith(s, suffix)) {
+    s = s.slice(0, -(suffix.length))
+  }
+  return s
+}
+
 function _containsForbiddenCharacters(s: string): boolean {
   return s.includes(" ") || s.includes("#") || s.includes("?")
 }

--
Gitblit v1.10.0