Skip to content

Commit e8b72a2

Browse files
authored
Merge pull request #4 from 3200pro/patch-3
Conditional Image & Author
2 parents e733488 + 652a6d9 commit e8b72a2

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/routes/(app)/+page.svelte

+19-13
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@
4242
<a href="/posts/{post.slug}">
4343
<div class="flex flex-col overflow-hidden rounded-lg shadow-lg">
4444
<div class="flex-shrink-0">
45+
{#if post.coverImage}
4546
<img
4647
class="h-48 w-full object-cover"
4748
src={urlForImage(post.coverImage).crop("focalpoint").width(826).height(384).url()}
4849
alt=""
4950
/>
51+
{/if}
5052
</div>
5153
<div class="flex flex-1 flex-col justify-between bg-white p-6">
5254
<div class="flex-1">
@@ -63,21 +65,25 @@
6365
</div>
6466
<div class="mt-6 flex items-center">
6567
<div class="flex-shrink-0">
66-
<span class="sr-only">Roel Aufderehar</span>
67-
<img
68-
class="h-10 w-10 rounded-full"
69-
src={urlForImage(post.author.picture).crop("focalpoint").width(256).height(256).url()}
70-
alt=""
71-
/>
68+
<span class="sr-only">Author Image</span>
69+
{#if post.author}
70+
<img
71+
class="h-10 w-10 rounded-full"
72+
src={urlForImage(post.author.picture).crop("focalpoint").width(256).height(256).url()}
73+
alt=""
74+
/>
75+
{/if}
7276
</div>
73-
<div class="ml-3">
74-
<p class="text-sm font-medium text-gray-900">{post.author.name}</p>
75-
<div class="flex space-x-1 text-sm text-gray-500">
76-
<time datetime="2020-03-16">
77-
{new Date(post.date).toLocaleDateString()}
78-
</time>
77+
{#if post.author}
78+
<div class="ml-3">
79+
<p class="text-sm font-medium text-gray-900">{post.author.name}</p>
80+
<div class="flex space-x-1 text-sm text-gray-500">
81+
<time datetime="2020-03-16">
82+
{new Date(post.date).toLocaleDateString()}
83+
</time>
84+
</div>
7985
</div>
80-
</div>
86+
{/if}
8187
</div>
8288
</div>
8389
</div>

0 commit comments

Comments
 (0)