From 1406ee0f05dc688e1b7635d3ce14e63d1c42a973 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Sun, 04 Jun 2023 17:37:43 +0000
Subject: [PATCH] update spinners
---
quartz/path.ts | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/quartz/path.ts b/quartz/path.ts
index 4127fc0..aa3870b 100644
--- a/quartz/path.ts
+++ b/quartz/path.ts
@@ -1,4 +1,7 @@
import path from 'path'
+import SlugAnchor from 'github-slugger'
+
+const slugAnchor = new SlugAnchor()
function slugSegment(s: string): string {
return s.replace(/\s/g, '-')
@@ -6,7 +9,7 @@
export function slugify(s: string): string {
const [fp, anchor] = s.split("#", 2)
- const sluggedAnchor = anchor === undefined ? "" : "#" + slugSegment(anchor)
+ const sluggedAnchor = anchor === undefined ? "" : "#" + slugAnchor.slug(anchor)
const withoutFileExt = fp.replace(new RegExp(path.extname(fp) + '$'), '')
const rawSlugSegments = withoutFileExt.split(path.sep)
const slugParts: string = rawSlugSegments
@@ -19,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