Skip to content

Commit 732f328

Browse files
committed
Display Project images
1 parent e240404 commit 732f328

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

www/src/lib/components/project-article.svelte

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<script>
2+
import { urlFor } from '$lib/sanity/image.js'
3+
24
import FaviconGithub from './icons/favicon-github.svelte'
35
import Heading from './heading.svelte'
6+
import IconRSS from './icons/icon-rss.svelte'
47
import MentionLink from './mention-link.svelte'
58
import PortableText from './portable-text.svelte'
69
@@ -17,7 +20,9 @@ export let project
1720
<MentionLink href={project.site}>Visit site</MentionLink>
1821
{/if}
1922
{#if project.post}
20-
<MentionLink href={project.post}>Read blog post</MentionLink>
23+
<MentionLink href={project.post} logo={IconRSS}
24+
>Read post</MentionLink
25+
>
2126
{/if}
2227
{#if project.repo}
2328
<MentionLink href={project.repo} logo={FaviconGithub}
@@ -29,5 +34,32 @@ export let project
2934
<PortableText value={project.lede} />
3035
</div>
3136
</div>
32-
<!-- <div>Images</div> -->
37+
{#if project.images?.length > 0}
38+
<div class="l:gap-8 flex justify-end gap-6">
39+
{#each project.images as image}
40+
<figure class="not-prose m-0 flex">
41+
<picture class="transition-opacity duration-300">
42+
<source
43+
srcset={urlFor(image).format('webp').url()}
44+
type="image/webp"
45+
/>
46+
<img
47+
class="h-full w-full object-contain"
48+
style:aspect-ratio={image.metadata.dimensions
49+
.aspectRatio}
50+
style:max-height="{Math.floor(
51+
image.metadata.dimensions.height / 2,
52+
)}px"
53+
loading="lazy"
54+
decoding="async"
55+
alt=""
56+
sizes="100vw"
57+
srcset={urlFor(image).format('jpg').url()}
58+
src={urlFor(image).format('jpg').url()}
59+
/>
60+
</picture>
61+
</figure>
62+
{/each}
63+
</div>
64+
{/if}
3365
</article>

www/src/lib/sanity/projects.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ import { client } from './client.js'
66
* @returns {Promise<import('./types.js').ProjectsQueryResult>}
77
*/
88
export async function getProjects() {
9-
let projectsQuery = groq`*[_type == "project"] | order(_createdAt desc)`
9+
let projectsQuery = groq`
10+
*[_type == "project"]{
11+
...,
12+
'post': array::join(['/writing', post->slug.current], '/'),
13+
images[]{
14+
...,
15+
'metadata': asset->metadata
16+
},
17+
} | order(_createdAt desc)`
1018

1119
return await client.fetch(projectsQuery)
1220
}

0 commit comments

Comments
 (0)