add gradient if no hero image available
This commit is contained in:
parent
d2a0ec152f
commit
810b9ee1f8
2 changed files with 10 additions and 3 deletions
|
@ -5,7 +5,6 @@ import Header from '../components/Header.astro';
|
||||||
import FormattedDate from '../components/FormattedDate.astro';
|
import FormattedDate from '../components/FormattedDate.astro';
|
||||||
|
|
||||||
type Props = CollectionEntry<'blog'>['data'];
|
type Props = CollectionEntry<'blog'>['data'];
|
||||||
|
|
||||||
const { title, description, pubDate, updatedDate, heroImage } = Astro.props;
|
const { title, description, pubDate, updatedDate, heroImage } = Astro.props;
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -51,6 +50,10 @@ const { title, description, pubDate, updatedDate, heroImage } = Astro.props;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
</style>
|
</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>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
@ -58,7 +61,7 @@ const { title, description, pubDate, updatedDate, heroImage } = Astro.props;
|
||||||
<main>
|
<main>
|
||||||
<article>
|
<article>
|
||||||
<div class="hero-image">
|
<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>
|
||||||
<div class="prose">
|
<div class="prose">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
|
|
|
@ -82,6 +82,10 @@ const posts = (await getCollection('blog')).sort(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<Header />
|
<Header />
|
||||||
|
@ -92,7 +96,7 @@ const posts = (await getCollection('blog')).sort(
|
||||||
posts.map((post) => (
|
posts.map((post) => (
|
||||||
<li>
|
<li>
|
||||||
<a href={`/${post.slug}/`}>
|
<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>
|
<h4 class="title">{post.data.title}</h4>
|
||||||
<p class="date">
|
<p class="date">
|
||||||
<FormattedDate date={post.data.pubDate} />
|
<FormattedDate date={post.data.pubDate} />
|
||||||
|
|
Loading…
Add table
Reference in a new issue