Skip to content

Commit 787ab3e

Browse files
authored
fix: base path for relative path in markdown (#170 close AlistGo/alist#6419)
1 parent a2161c2 commit 787ab3e

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/components/Markdown.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import { Anchor, Box, List, ListItem } from "@hope-ui/solid"
1212
import { useParseText, useRouter } from "~/hooks"
1313
import { EncodingSelect } from "."
1414
import once from "just-once"
15-
import { pathDir, pathJoin, api } from "~/utils"
15+
import { pathDir, pathJoin, api, pathResolve } from "~/utils"
1616
import { createStorageSignal } from "@solid-primitives/storage"
1717
import { isMobile } from "~/utils/compatibility.js"
1818
import { useScrollListener } from "~/pages/home/toolbar/BackTop.jsx"
1919
import { Motion } from "@motionone/solid"
20-
import { getMainColor } from "~/store"
20+
import { getMainColor, me } from "~/store"
2121

2222
type TocItem = { indent: number; text: string; tagName: string; key: string }
2323

@@ -194,10 +194,9 @@ export function Markdown(props: {
194194
if (url.startsWith("/")) {
195195
url = `${api}/d${url}`
196196
} else {
197-
url = url.replace("./", "")
198197
url = `${api}/d${pathJoin(
199-
props.readme ? pathname() : pathDir(pathname()),
200-
url,
198+
me().base_path,
199+
pathResolve(props.readme ? pathname() : pathDir(pathname()), url),
201200
)}`
202201
}
203202
const ans = `![${name}](${url})`

src/utils/path.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export const standardizePath = (path: string, noRootSlash?: boolean) => {
1313
return path
1414
}
1515

16+
export const pathResolve = (...paths: string[]) => {
17+
return new URL(pathJoin(...paths), location.origin).pathname
18+
}
19+
1620
export const pathJoin = (...paths: string[]) => {
1721
return paths.join("/").replace(/\/{2,}/g, "/")
1822
}

0 commit comments

Comments
 (0)