fix: make base in astro config work

This commit is contained in:
saicaca committed 2024-04-29 17:09:52 +08:00
1 parent 9a3119cab4
commit 410902a767
11 files changed
+37 -26

No files matched your search

+3 -1
View File
@@ -8,11 +8,13 @@ interface Props {
basePath?: string
}
import { Image } from 'astro:assets';
import {url} from "../../utils/url-utils";
const {id, src, alt, basePath = '/'} = Astro.props;
const className = Astro.props.class;
const isLocal = !(src.startsWith('/') || src.startsWith('http') || src.startsWith('https') || src.startsWith('data:'));
const isPublic = src.startsWith('/');
// TODO temporary workaround for images dynamic import
// https://github.com/withastro/astro/issues/3373
@@ -27,6 +29,6 @@ if (isLocal) {
<div class:list={[className, 'overflow-hidden relative']}>
<div class="transition absolute inset-0 dark:bg-black/10 bg-opacity-50 pointer-events-none"></div>
{isLocal && <Image src={img} alt={alt || ""} class="w-full h-full object-center object-cover" />}
{!isLocal && <img src={src} alt={alt || ""} class="w-full h-full object-center object-cover" />}
{!isLocal && <img src={isPublic ? url(src) : src} alt={alt || ""} class="w-full h-full object-center object-cover" />}
</div>