Files
medusa-store/www/packages/remark-rehype-plugins/src/utils/fix-link.ts
Shahed Nasser 4fe28f5a95 chore: reorganize docs apps (#7228)
* reorganize docs apps

* add README

* fix directory

* add condition for old docs
2024-05-03 17:36:38 +03:00

28 lines
643 B
TypeScript

import path from "path"
export type FixLinkOptions = {
currentPageFilePath: string
linkedPath: string
appsPath: string
}
export function fixLinkUtil({
currentPageFilePath,
linkedPath,
appsPath: basePath,
}: FixLinkOptions) {
// get absolute path of the URL
const linkedFilePath = path
.resolve(currentPageFilePath, linkedPath)
.replace(basePath, "")
// persist hash in new URL
const hash = linkedFilePath.includes("#")
? linkedFilePath.substring(linkedFilePath.indexOf("#"))
: ""
return `${linkedFilePath.substring(
0,
linkedFilePath.indexOf(`/${path.basename(linkedFilePath)}`)
)}${hash}`
}