Skip to content

Commit d2e2fba

Browse files
authored
fix(markdown): images src with baseURL (#1833)
1 parent cb4fa76 commit d2e2fba

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/runtime/components/Prose/ProseImg.vue

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<template>
2-
<img :src="src" :alt="alt" :width="width" :height="height">
2+
<img :src="refinedSrc" :alt="alt" :width="width" :height="height">
33
</template>
44

55
<script setup lang="ts">
6-
defineProps({
6+
import { withBase } from 'ufo'
7+
import { useRuntimeConfig, computed } from '#imports'
8+
9+
const props = defineProps({
710
src: {
811
type: String,
912
default: ''
@@ -21,4 +24,11 @@ defineProps({
2124
default: undefined
2225
}
2326
})
27+
28+
const refinedSrc = computed(() => {
29+
if (props.src?.startsWith('/') && !props.src.startsWith('//')) {
30+
return withBase(props.src, useRuntimeConfig().app.baseURL)
31+
}
32+
return props.src
33+
})
2434
</script>

0 commit comments

Comments
 (0)