From 8fd496bbef4bc62315f3a0893177da730d8c4262 Mon Sep 17 00:00:00 2001
From: Sohaib <98542228+sohaibology@users.noreply.github.com>
Date: Sat, 12 Aug 2023 20:52:16 +0000
Subject: [PATCH] Update hosting.md (#368)

---
 quartz/plugins/transformers/links.ts |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/quartz/plugins/transformers/links.ts b/quartz/plugins/transformers/links.ts
index 7e8a278..5b15725 100644
--- a/quartz/plugins/transformers/links.ts
+++ b/quartz/plugins/transformers/links.ts
@@ -2,6 +2,7 @@
 import {
   CanonicalSlug,
   RelativeURL,
+  _stripSlashes,
   canonicalizeServer,
   joinSegments,
   pathToRoot,
@@ -35,7 +36,7 @@
           return (tree, file) => {
             const curSlug = canonicalizeServer(file.data.slug!)
             const transformLink = (target: string): RelativeURL => {
-              const targetSlug = transformInternalLink(target).slice("./".length)
+              const targetSlug = _stripSlashes(transformInternalLink(target).slice(".".length))
               let [targetCanonical, targetAnchor] = splitAnchor(targetSlug)
               if (opts.markdownLinkResolution === "relative") {
                 return targetSlug as RelativeURL
@@ -47,6 +48,7 @@
                   return targetCanonical === fileName
                 })
 
+                // only match, just use it
                 if (matchingFileNames.length === 1) {
                   const targetSlug = canonicalizeServer(matchingFileNames[0])
                   return (resolveRelative(curSlug, targetSlug) + targetAnchor) as RelativeURL
@@ -75,7 +77,7 @@
                 // don't process external links or intra-document anchors
                 if (!(isAbsoluteUrl(dest) || dest.startsWith("#"))) {
                   dest = node.properties.href = transformLink(dest)
-                  const canonicalDest = path.normalize(joinSegments(curSlug, dest))
+                  const canonicalDest = path.posix.normalize(joinSegments(curSlug, dest))
                   const [destCanonical, _destAnchor] = splitAnchor(canonicalDest)
                   outgoing.add(destCanonical as CanonicalSlug)
                 }
@@ -84,7 +86,8 @@
                 if (
                   opts.prettyLinks &&
                   node.children.length === 1 &&
-                  node.children[0].type === "text"
+                  node.children[0].type === "text" &&
+                  !node.children[0].value.startsWith("#")
                 ) {
                   node.children[0].value = path.basename(node.children[0].value)
                 }
@@ -97,9 +100,10 @@
                 typeof node.properties.src === "string"
               ) {
                 if (!isAbsoluteUrl(node.properties.src)) {
+                  let dest = node.properties.src as RelativeURL
                   const ext = path.extname(node.properties.src)
-                  node.properties.src =
-                    transformLink(path.join("assets", node.properties.src)) + ext
+                  dest = node.properties.src = transformLink(dest)
+                  node.properties.src = dest + ext
                 }
               }
             })

--
Gitblit v1.10.0