Jacky Zhao
2023-08-11 df02ea20d7e12e8b9ffdd2968afaf5893c433488
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
@@ -98,9 +99,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(joinSegments("assets", node.properties.src)) + ext
                  dest = node.properties.src = transformLink(dest)
                  node.properties.src = dest + ext
                }
              }
            })