Skip to content

Commit 8e99e04

Browse files
#RI-2674-fix worbench images path (#541)
* #RI-2674-fix worbench images path
1 parent c282ec1 commit 8e99e04

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

redisinsight/ui/src/pages/workbench/components/enablement-area/EnablementArea/utils/formatter/MarkdownToJsxString.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class MarkdownToJsxString implements IFormatter {
1717
.use(remarkParse)
1818
.use(remarkGfm) // support GitHub Flavored Markdown
1919
.use(remarkRedisCode) // Add custom component for Redis code block
20-
.use(remarkImage) // Add custom component for Redis code block
20+
.use(remarkImage, config ? { history: config.history } : undefined) // Add custom component for Redis code block
2121
.use(remarkRehype, { allowDangerousHtml: true }) // Pass raw HTML strings through.
2222
.use(rehypeLinks, config ? { history: config.history } : undefined) // Customise links
2323
.use(MarkdownToJsxString.rehypeWrapSymbols) // Wrap special symbols inside curly braces for JSX parse
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
import { visit } from 'unist-util-visit'
22
import { IS_ABSOLUTE_PATH } from 'uiSrc/constants/regex'
33
import { RESOURCES_BASE_URL } from 'uiSrc/services/resourcesService'
4+
import { ApiEndpoints } from 'uiSrc/constants'
5+
import { IFormatterConfig } from './formatter/formatter.interfaces'
46

5-
export const remarkImage = (): (tree: Node) => void => (tree: any) => {
7+
const getSourcelPath = (search?: string) => {
8+
switch (true) {
9+
case search?.indexOf(ApiEndpoints.GUIDES_PATH) !== -1:
10+
return 'static/guides/'
11+
case search?.indexOf(ApiEndpoints.TUTORIALS_PATH) !== -1:
12+
return 'static/tutorials/'
13+
default:
14+
return ''
15+
}
16+
}
17+
18+
const updateUrl = (url: string) => url.replace(/^\//, '')
19+
20+
export const remarkImage = (config?: IFormatterConfig): (tree: Node) => void => (tree: any) => {
21+
const sourcePath = getSourcelPath(config?.history?.location?.search)
622
// Find img node in syntax tree
723
visit(tree, 'image', (node) => {
8-
node.url = IS_ABSOLUTE_PATH.test(node.url || '') ? node.url : `${RESOURCES_BASE_URL}${node.url.replace(/^\//, '')}`
24+
node.url = IS_ABSOLUTE_PATH.test(node.url || '') ? node.url : `${RESOURCES_BASE_URL}${sourcePath}${updateUrl(node.url)}`
925
})
1026
}

0 commit comments

Comments
 (0)