add gradient if no hero image available
This commit is contained in:
parent
d2a0ec152f
commit
810b9ee1f8
|
@ -5,7 +5,6 @@ import Header from '../components/Header.astro';
|
|||
import FormattedDate from '../components/FormattedDate.astro';
|
||||
|
||||
type Props = CollectionEntry<'blog'>['data'];
|
||||
|
||||
const { title, description, pubDate, updatedDate, heroImage } = Astro.props;
|
||||
---
|
||||
|
||||
|
@ -51,6 +50,10 @@ const { title, description, pubDate, updatedDate, heroImage } = Astro.props;
|
|||
font-style: italic;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function randomColor() {return "#000000".replace(/0/g,function(){return (~~(Math.random()*16)).toString(16);});}
|
||||
gradient.style.cssText += `background: linear-gradient(${randomColor()},${randomColor()})`;
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
@ -58,7 +61,7 @@ const { title, description, pubDate, updatedDate, heroImage } = Astro.props;
|
|||
<main>
|
||||
<article>
|
||||
<div class="hero-image">
|
||||
{heroImage && <img width={1020} height={510} src={heroImage} alt="" />}
|
||||
{heroImage ? <img width={1020} height={510} src={heroImage} alt="" /> : <img width={1020} height={510} id="gradient" alt="" />}
|
||||
</div>
|
||||
<div class="prose">
|
||||
<div class="title">
|
||||
|
|
|
@ -82,6 +82,10 @@ const posts = (await getCollection('blog')).sort(
|
|||
}
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function randomColor() {return "#000000".replace(/0/g,function(){return (~~(Math.random()*16)).toString(16);});}
|
||||
gradient.style.cssText += `background: linear-gradient(45deg,${randomColor()},${randomColor()})`;
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<Header />
|
||||
|
@ -92,7 +96,7 @@ const posts = (await getCollection('blog')).sort(
|
|||
posts.map((post) => (
|
||||
<li>
|
||||
<a href={`/${post.slug}/`}>
|
||||
<img width={720} height={360} src={post.data.heroImage} alt="" />
|
||||
{ post.data.heroImage ? <img width={720} height={360} src={post.data.heroImage} alt="" /> : <img width={720} height={360} src={post.data.heroImage} id="gradient" alt="" />}
|
||||
<h4 class="title">{post.data.title}</h4>
|
||||
<p class="date">
|
||||
<FormattedDate date={post.data.pubDate} />
|
||||
|
|
Loading…
Reference in a new issue