Skip to content

Commit b81205b

Browse files
committed
fix: support relative image paths in ContributorHeader component
1 parent abc1d8a commit b81205b

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed
Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,51 @@
11
<script setup lang="ts">
2+
import { computed } from "vue";
3+
24
const props = defineProps<{
3-
name: string
4-
avatar?: string
5-
size?: number
5+
name: string;
6+
avatar?: string;
7+
size?: number;
68
}>();
9+
10+
const avatarSrc = computed(() => {
11+
if (!props.avatar) {
12+
return "";
13+
}
14+
15+
if (props.avatar.startsWith("/")) {
16+
return props.avatar;
17+
}
18+
19+
const images = (import.meta as any).glob(
20+
"/images/contribute/**/*.{png,jpg,jpeg,webp,avif,gif,svg}",
21+
{ eager: true, import: "default" }
22+
);
23+
24+
const fileName = props.avatar.split("/").pop();
25+
const matchedEntry = Object.entries(images).find(([path]) =>
26+
path.endsWith(fileName ?? "")
27+
);
28+
29+
if (matchedEntry) {
30+
const [_, buildURL] = matchedEntry;
31+
return buildURL;
32+
}
33+
34+
return props.avatar;
35+
});
736
</script>
837

938
<template>
10-
<div style="display:flex; align-items:center; gap:12px; margin:8px 0 24px;">
39+
<div
40+
style="display: flex; align-items: center; gap: 12px; margin: 8px 0 24px"
41+
>
1142
<img
12-
:src="avatar || ''"
13-
:width="size || 40"
14-
:height="size || 40"
43+
:src="avatarSrc"
44+
:width="size ?? 40"
45+
:height="size ?? 40"
1546
:alt="name"
16-
style="border-radius:50%; object-fit:cover;"
47+
style="border-radius: 50%; object-fit: cover"
1748
/>
1849
<strong>{{ name }}</strong>
1950
</div>
20-
</template>
51+
</template>

0 commit comments

Comments
 (0)