Path: blob/master/src/packages/next/lib/share/url-transform.ts
1449 views
import { join } from "path";1import rawURL from "./raw-url";23interface Options {4id: string;5path: string;6relativePath: string;7}89// NOTE: there is a similar function in frontend/project/page/url-transform.ts10export default function getUrlTransform({11id,12path,13relativePath, // relative path of the directory containing the file we are rendering.14}: Options): (href: string, tag: string) => string | undefined {15return (href: string, tag: string) => {16if (href.startsWith("data:")) return; // never change data: urls in any way.17if (tag == "a" || href.includes("://")) {18// Don't modify anything non-local, i.e., like https://...19// Also don't modify a tags at all.20return;21}22return rawURL({ id, path, relativePath: join(relativePath, href) });23};24}252627