feat: add option `position` for banner image (#106)
This commit is contained in:
parent
ce36ba37c5
commit
5868cddcb6
|
@ -5,12 +5,13 @@ interface Props {
|
||||||
src: string;
|
src: string;
|
||||||
class?: string;
|
class?: string;
|
||||||
alt?: string
|
alt?: string
|
||||||
|
position?: string;
|
||||||
basePath?: string
|
basePath?: string
|
||||||
}
|
}
|
||||||
import { Image } from 'astro:assets';
|
import { Image } from 'astro:assets';
|
||||||
import {url} from "../../utils/url-utils";
|
import { url } from "../../utils/url-utils";
|
||||||
|
|
||||||
const {id, src, alt, basePath = '/'} = Astro.props;
|
const {id, src, alt, position = 'center', basePath = '/'} = Astro.props;
|
||||||
const className = Astro.props.class;
|
const className = Astro.props.class;
|
||||||
|
|
||||||
const isLocal = !(src.startsWith('/') || src.startsWith('http') || src.startsWith('https') || src.startsWith('data:'));
|
const isLocal = !(src.startsWith('/') || src.startsWith('http') || src.startsWith('https') || src.startsWith('data:'));
|
||||||
|
@ -25,10 +26,12 @@ if (isLocal) {
|
||||||
img = await (files[normalizedPath])();
|
img = await (files[normalizedPath])();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const imageClass = 'w-full h-full object-cover';
|
||||||
|
const imageStyle = `object-position: ${position}`
|
||||||
---
|
---
|
||||||
<div class:list={[className, 'overflow-hidden relative']}>
|
<div class:list={[className, 'overflow-hidden relative']}>
|
||||||
<div class="transition absolute inset-0 dark:bg-black/10 bg-opacity-50 pointer-events-none"></div>
|
<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 && <Image src={img} alt={alt || ""} class={imageClass} style={imageStyle}/>}
|
||||||
{!isLocal && <img src={isPublic ? url(src) : src} alt={alt || ""} class="w-full h-full object-center object-cover" />}
|
{!isLocal && <img src={isPublic ? url(src) : src} alt={alt || ""} class={imageClass} style={imageStyle}/>}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ export const siteConfig: SiteConfig = {
|
||||||
banner: {
|
banner: {
|
||||||
enable: false,
|
enable: false,
|
||||||
src: 'assets/images/demo-banner.png', // Relative to the /src directory. Relative to the /public directory if it starts with '/'
|
src: 'assets/images/demo-banner.png', // Relative to the /src directory. Relative to the /public directory if it starts with '/'
|
||||||
|
position: 'center', // Equivalent to object-position, defaults center
|
||||||
},
|
},
|
||||||
favicon: [ // Leave this array empty to use the default favicon
|
favicon: [ // Leave this array empty to use the default favicon
|
||||||
// {
|
// {
|
||||||
|
|
|
@ -13,6 +13,7 @@ export type SiteConfig = {
|
||||||
banner: {
|
banner: {
|
||||||
enable: boolean
|
enable: boolean
|
||||||
src: string
|
src: string
|
||||||
|
position?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
favicon: Favicon[]
|
favicon: Favicon[]
|
||||||
|
|
Loading…
Reference in New Issue