import { resolve } from "$app/paths"; // rest params arrive decoded, re-encode per segment or `#`/`?`/`%` corrupt // the url export const encodePathSegments = (path: string): string => path.split("/").map(encodeURIComponent).join("/"); export const baseName = (path: string): string => path.split("/").pop() ?? path; export const rawBlobHref = (ownerHandle: string, repoName: string, ref: string, path: string) => resolve( `/${ownerHandle}/${repoName}/raw/${encodeURIComponent(ref)}/${encodePathSegments(path)}` as "/" ); export const blobHref = (ownerHandle: string, repoName: string, ref: string, path: string) => resolve( `/${ownerHandle}/${repoName}/blob/${encodeURIComponent(ref)}/${encodePathSegments(path)}` as "/" ); export const fileHistoryHref = (ownerHandle: string, repoName: string, ref: string, path: string) => resolve( `/${ownerHandle}/${repoName}/history/${encodeURIComponent(ref)}/${encodePathSegments(path)}` as "/" );