Skip to content

Commit b19f319

Browse files
authored
Repo image path bug fix (#988)
* feat(resolveContent): update path resolution logic - Add currentFilePath parameter - Use pathWithoutFilename for prefix - Adjust function calls to include new param * fix(resolveContent): correct file path resolution - Update prefix to replace '/blob/' with '/resolve/' - Ensure proper handling of content paths * feat(resolveContent): improve path resolution logic - Update function parameters for clarity - Adjust prefix logic for repo summary page - Use pathname instead of pathWithoutFilename
1 parent 8117cb1 commit b19f319

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

frontend/src/packs/resolveContent.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import { atob_utf8 } from './utils'
22

3-
const relativePathToResolvePath = (repoType, content, namespacePath, currentBranch, currentFilePath) => {
3+
const relativePathToResolvePath = (repoType, content, namespacePath, currentBranch, requestPath) => {
44
if (!content) return content
55

6-
// const prefix = `/${repoType}/${namespacePath}/resolve/${currentBranch}/`
7-
const prefix = currentFilePath.replace('/blob/', '/resolve/')
6+
const repoBasePath = `/${repoType}/${namespacePath}`
7+
8+
let prefix = `/${repoType}/${namespacePath}/resolve/${currentBranch}/`
9+
10+
// requestPath === repoBasePath means accessing repo summary page
11+
// requestPath !== repoBasePath means accessing a file
12+
if (requestPath !== repoBasePath) {
13+
const lastSlashIndex = requestPath.lastIndexOf('/')
14+
const pathWithoutFilename = requestPath.substring(0, lastSlashIndex + 1)
15+
prefix = pathWithoutFilename.replace('/blob/', '/resolve/')
16+
}
817

918
// Handle markdown format image
1019
content = content.replace(
@@ -35,8 +44,6 @@ const resolveContent = (repoType, encodedContent, namespacePath, currentBranch)
3544
const fileExtension = requestUrl.pathname.split('.').pop()
3645

3746
const pathname = requestUrl.pathname
38-
const lastSlashIndex = pathname.lastIndexOf('/')
39-
const pathWithoutFilename = pathname.substring(0, lastSlashIndex + 1)
4047

4148
let content
4249

@@ -50,7 +57,7 @@ const resolveContent = (repoType, encodedContent, namespacePath, currentBranch)
5057
parsedBlobContent,
5158
namespacePath,
5259
currentBranch,
53-
pathWithoutFilename
60+
pathname
5461
)
5562
} catch (error) {
5663
console.log(error)

0 commit comments

Comments
 (0)