Skip to content

Commit

Permalink
fix: base path for relative path in markdown (#170 close AlistGo/alis…
Browse files Browse the repository at this point in the history
  • Loading branch information
liuycy authored May 9, 2024
1 parent a2161c2 commit 787ab3e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/components/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { Anchor, Box, List, ListItem } from "@hope-ui/solid"
import { useParseText, useRouter } from "~/hooks"
import { EncodingSelect } from "."
import once from "just-once"
import { pathDir, pathJoin, api } from "~/utils"
import { pathDir, pathJoin, api, pathResolve } from "~/utils"
import { createStorageSignal } from "@solid-primitives/storage"
import { isMobile } from "~/utils/compatibility.js"
import { useScrollListener } from "~/pages/home/toolbar/BackTop.jsx"
import { Motion } from "@motionone/solid"
import { getMainColor } from "~/store"
import { getMainColor, me } from "~/store"

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

Expand Down Expand Up @@ -194,10 +194,9 @@ export function Markdown(props: {
if (url.startsWith("/")) {
url = `${api}/d${url}`
} else {
url = url.replace("./", "")
url = `${api}/d${pathJoin(
props.readme ? pathname() : pathDir(pathname()),
url,
me().base_path,
pathResolve(props.readme ? pathname() : pathDir(pathname()), url),
)}`
}
const ans = `![${name}](${url})`
Expand Down
4 changes: 4 additions & 0 deletions src/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export const standardizePath = (path: string, noRootSlash?: boolean) => {
return path
}

export const pathResolve = (...paths: string[]) => {
return new URL(pathJoin(...paths), location.origin).pathname
}

export const pathJoin = (...paths: string[]) => {
return paths.join("/").replace(/\/{2,}/g, "/")
}
Expand Down

0 comments on commit 787ab3e

Please sign in to comment.