| File was renamed from quartz/path.ts |
| | |
| | | export type RelativeURL = SlugLike<"relative"> |
| | | export function isRelativeURL(s: string): s is RelativeURL { |
| | | const validStart = /^\.{1,2}/.test(s) |
| | | const validEnding = !(s.endsWith("/") || s.endsWith("/index") || s === "index") |
| | | const validEnding = !(s.endsWith("/index") || s === "index") |
| | | return validStart && validEnding && !_hasFileExtension(s) |
| | | } |
| | | |
| | |
| | | |
| | | export function transformInternalLink(link: string): RelativeURL { |
| | | let [fplike, anchor] = splitAnchor(decodeURI(link)) |
| | | |
| | | const folderPath = |
| | | fplike.endsWith("index") || |
| | | fplike.endsWith("index.md") || |
| | | fplike.endsWith("index.html") || |
| | | fplike.endsWith("/") |
| | | let segments = fplike.split("/").filter((x) => x.length > 0) |
| | | let prefix = segments.filter(_isRelativeSegment).join("/") |
| | | let fp = segments.filter((seg) => !_isRelativeSegment(seg)).join("/") |
| | |
| | | } |
| | | |
| | | fp = canonicalizeServer(slugifyFilePath(fp as FilePath)) |
| | | fp = _trimSuffix(fp, "index") |
| | | |
| | | let joined = joinSegments(_stripSlashes(prefix), _stripSlashes(fp)) |
| | | const res = (_addRelativeToStart(joined) + anchor) as RelativeURL |
| | | const joined = joinSegments(_stripSlashes(prefix), _stripSlashes(fp)) |
| | | const trail = folderPath ? "/" : "" |
| | | const res = (_addRelativeToStart(joined) + anchor + trail) as RelativeURL |
| | | return res |
| | | } |
| | | |
| | | // resolve /a/b/c to ../../ |
| | | // resolve /a/b/c to ../../.. |
| | | export function pathToRoot(slug: CanonicalSlug): RelativeURL { |
| | | let rootPath = slug |
| | | .split("/") |