| | |
| | | import { |
| | | CanonicalSlug, |
| | | RelativeURL, |
| | | _stripSlashes, |
| | | canonicalizeServer, |
| | | joinSegments, |
| | | pathToRoot, |
| | |
| | | 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 |
| | |
| | | // 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) |
| | | } |
| | |
| | | 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) |
| | | } |
| | |
| | | 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 |
| | | } |
| | | } |
| | | }) |