From d2f52549955ff7600cc5897e67806df4ebf85f91 Mon Sep 17 00:00:00 2001
From: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
Date: Wed, 23 Aug 2023 16:05:01 +0000
Subject: [PATCH] fix(esbuild): conflict with esbuild-sass-plugin (#402)
---
quartz/plugins/transformers/links.ts | 36 +++++++++++++++++++++++++++---------
1 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/quartz/plugins/transformers/links.ts b/quartz/plugins/transformers/links.ts
index d867039..f8da36c 100644
--- a/quartz/plugins/transformers/links.ts
+++ b/quartz/plugins/transformers/links.ts
@@ -1,11 +1,12 @@
import { QuartzTransformerPlugin } from "../types"
import {
- CanonicalSlug,
+ FullSlug,
RelativeURL,
+ SimpleSlug,
TransformOptions,
_stripSlashes,
- canonicalizeServer,
joinSegments,
+ simplifySlug,
splitAnchor,
transformLink,
} from "../../util/path"
@@ -33,8 +34,8 @@
return [
() => {
return (tree, file) => {
- const curSlug = canonicalizeServer(file.data.slug!)
- const outgoing: Set<CanonicalSlug> = new Set()
+ const curSlug = simplifySlug(file.data.slug!)
+ const outgoing: Set<SimpleSlug> = new Set()
const transformOptions: TransformOptions = {
strategy: opts.markdownLinkResolution,
@@ -54,10 +55,23 @@
// don't process external links or intra-document anchors
if (!(isAbsoluteUrl(dest) || dest.startsWith("#"))) {
- dest = node.properties.href = transformLink(curSlug, dest, transformOptions)
- const canonicalDest = path.posix.normalize(joinSegments(curSlug, dest))
+ dest = node.properties.href = transformLink(
+ file.data.slug!,
+ dest,
+ transformOptions,
+ )
+
+ // url.resolve is considered legacy
+ // WHATWG equivalent https://nodejs.dev/en/api/v18/url/#urlresolvefrom-to
+ const url = new URL(dest, `resolve://${curSlug}`)
+ const canonicalDest = url.pathname
const [destCanonical, _destAnchor] = splitAnchor(canonicalDest)
- outgoing.add(destCanonical as CanonicalSlug)
+
+ // need to decodeURIComponent here as WHATWG URL percent-encodes everything
+ const simple = decodeURIComponent(
+ simplifySlug(destCanonical as FullSlug),
+ ) as SimpleSlug
+ outgoing.add(simple)
}
// rewrite link internals if prettylinks is on
@@ -79,7 +93,11 @@
) {
if (!isAbsoluteUrl(node.properties.src)) {
let dest = node.properties.src as RelativeURL
- dest = node.properties.src = transformLink(curSlug, dest, transformOptions)
+ dest = node.properties.src = transformLink(
+ file.data.slug!,
+ dest,
+ transformOptions,
+ )
node.properties.src = dest
}
}
@@ -95,6 +113,6 @@
declare module "vfile" {
interface DataMap {
- links: CanonicalSlug[]
+ links: SimpleSlug[]
}
}
--
Gitblit v1.10.0