Skip to content

Commit

Permalink
Jul 1, 2024, 10:08 AM
Browse files Browse the repository at this point in the history
  • Loading branch information
freenandes committed Jul 1, 2024
1 parent 9b55296 commit 1d9031a
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions quartz/plugins/transformers/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
RelativeURL,
SimpleSlug,
TransformOptions,
_stripSlashes,
simplifySlug,
splitAnchor,
transformLink,
Expand Down Expand Up @@ -60,13 +61,13 @@ export const CrawlLinks: QuartzTransformerPlugin<Partial<Options> | undefined> =
transformOptions,
)

// Use new URL to ensure correct path resolution
const baseURL = new URL(curSlug, 'https://base.com')
const resolvedURL = new URL(dest, baseURL)
const relativePath = resolvedURL.pathname + resolvedURL.search + resolvedURL.hash
dest = node.properties.href = relativePath as RelativeURL
// url.resolve is considered legacy
// WHATWG equivalent https://nodejs.dev/en/api/v18/url/#urlresolvefrom-to
const url = new URL(dest, `https://base.com/${curSlug}`)
const canonicalDest = url.pathname
const [destCanonical, _destAnchor] = splitAnchor(canonicalDest)

const [destCanonical, _destAnchor] = splitAnchor(dest)
// need to decodeURIComponent here as WHATWG URL percent-encodes everything
const simple = decodeURIComponent(
simplifySlug(destCanonical as FullSlug),
) as SimpleSlug
Expand Down Expand Up @@ -99,12 +100,7 @@ export const CrawlLinks: QuartzTransformerPlugin<Partial<Options> | undefined> =
dest,
transformOptions,
)

// Use new URL to ensure correct path resolution
const baseURL = new URL(curSlug, 'https://base.com')
const resolvedURL = new URL(dest, baseURL)
const relativePath = resolvedURL.pathname + resolvedURL.search + resolvedURL.hash
node.properties.src = relativePath as RelativeURL
node.properties.src = dest
}
}
})
Expand Down

0 comments on commit 1d9031a

Please sign in to comment.