From 660aae62e09ea1f5ec957149b78bfd01a85bd79f Mon Sep 17 00:00:00 2001
From: Odaimoko <934854676@qq.com>
Date: Tue, 28 Nov 2023 07:05:18 +0000
Subject: [PATCH] docs: add Imk&Cc's homepage to showcase.md (#595)
---
quartz/util/path.ts | 23 +++++++++++++++++++++--
1 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/quartz/util/path.ts b/quartz/util/path.ts
index 1557c1b..e450339 100644
--- a/quartz/util/path.ts
+++ b/quartz/util/path.ts
@@ -52,7 +52,7 @@
let slug = withoutFileExt
.split("/")
- .map((segment) => segment.replace(/\s/g, "-").replace(/%/g, "-percent")) // slugify all segments
+ .map((segment) => segment.replace(/\s/g, "-").replace(/%/g, "-percent").replace(/\?/g, "-q")) // slugify all segments
.join("/") // always use / as sep
.replace(/\/$/, "") // remove trailing slash
@@ -84,6 +84,22 @@
return res
}
+// from micromorph/src/utils.ts
+// https://github.com/natemoo-re/micromorph/blob/main/src/utils.ts#L5
+export function normalizeRelativeURLs(el: Element | Document, destination: string | URL) {
+ const rebase = (el: Element, attr: string, newBase: string | URL) => {
+ const rebased = new URL(el.getAttribute(attr)!, newBase)
+ el.setAttribute(attr, rebased.pathname + rebased.hash)
+ }
+
+ el.querySelectorAll('[href^="./"], [href^="../"]').forEach((item) =>
+ rebase(item, "href", destination),
+ )
+ el.querySelectorAll('[src^="./"], [src^="../"]').forEach((item) =>
+ rebase(item, "src", destination),
+ )
+}
+
// resolve /a/b/c to ../..
export function pathToRoot(slug: FullSlug): RelativeURL {
let rootPath = slug
@@ -123,7 +139,10 @@
}
export function joinSegments(...args: string[]): string {
- return args.filter((segment) => segment !== "").join("/")
+ return args
+ .filter((segment) => segment !== "")
+ .join("/")
+ .replace(/\/\/+/g, "/")
}
export function getAllSegmentPrefixes(tags: string): string[] {
--
Gitblit v1.10.0