Skip to content

Commit

Permalink
Cleanup image usage
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielPower committed May 19, 2024
1 parent f28680d commit a2858db
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 40 deletions.
28 changes: 19 additions & 9 deletions src/lib/components/Image.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
<script lang="ts">
type Size = "original" | "fullwidth" | "thumbnail";
export let src: string;
export let alt: string;
export let size: Size = "fullwidth";
const path = `/src/lib/assets/${src}`;
const original = import.meta.glob<{ default: string }>("$lib/assets/*", {
eager: true,
})[path]?.default!;
const thumbnail = import.meta.glob<{ default: string }>("$lib/assets/*", {
query: "?w=960&format=webp&quality=80",
eager: true,
})[path]?.default!;
const images: { [key in Size]: string } = {
original: import.meta.glob<{ default: string }>("$lib/assets/*", {
eager: true,
})[path]?.default!,
thumbnail: import.meta.glob<{ default: string }>("$lib/assets/*", {
query: "?w=320&format=webp&quality=80",
eager: true,
})[path]?.default!,
fullwidth: import.meta.glob<{ default: string }>("$lib/assets/*", {
query: "?w=960&format=webp&quality=80",
eager: true,
})[path]?.default!,
};
</script>

<figure>
<a href={original}>
<img src={thumbnail} {alt} />
<a href={images.original}>
<img src={images[size]} {alt} />
</a>
{#if $$slots.default}
<figcaption><slot /></figcaption>
Expand Down
33 changes: 13 additions & 20 deletions src/routes/projects/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
<script>
import Fa from "svelte-fa";
import keebProOrig from "$lib/assets/keeb-pro.png";
import keebProThumb from "$lib/assets/keeb-pro.png?thumbnail";
import eclipseOrig from "$lib/assets/eclipse.png";
import eclipseThumb from "$lib/assets/eclipse.png?thumbnail";
import orbsOrig from "$lib/assets/orbs.png";
import orbsThumb from "$lib/assets/orbs.png?thumbnail";
import motionOrig from "$lib/assets/motion.jpg";
import motionThumb from "$lib/assets/motion.jpg?thumbnail";
import Image from "$lib/components/Image.svelte";
import {
faDiscord,
faGithub,
Expand Down Expand Up @@ -43,9 +36,9 @@

<div class="project">
<h1>Eclipse (2023)</h1>
<a href={eclipseOrig}
><img class="thumb" src={eclipseThumb} alt="Screenshot of Eclipse" /></a
>
<div class="thumb">
<Image src="eclipse.png" size="thumbnail" alt="Screenshot of Eclipse" />
</div>
<p>
A tool for visualizing GLSL shaders. It is written in Lua using the Love2D
framework. It is designed to be compatible with shaders from <a
Expand All @@ -61,9 +54,9 @@

<div class="project">
<h1>Orbs in Space - Love2D Game Jam entry (2023)</h1>
<a href={orbsOrig}
><img class="thumb" src={orbsThumb} alt="Screenshot of Orbs in Space" /></a
>
<div class="thumb">
<Image src="orbs.png" size="thumbnail" alt="Screenshot of Orbs in Space" />
</div>
<p>
A game made for the <a href="https://itch.io/jam/love2d-jam-2023"
>Love2D Jam 2023.</a
Expand Down Expand Up @@ -163,9 +156,9 @@

<div class="project">
<h1>Keeb Pro (2020)</h1>
<a href={keebProOrig}
><img class="thumb" src={keebProThumb} alt="Screenshot of Keeb Pro" /></a
>
<div class="thumb">
<Image src="keeb-pro.png" size="thumbnail" alt="Screenshot of Keeb Pro" />
</div>
<p>
A typing test built with svelte. It prompts the user to type a random
selection of common English words, and displays the user's typing speed in
Expand Down Expand Up @@ -201,9 +194,9 @@

<div class="project">
<h1>Motion (2017)</h1>
<a href={motionOrig}
><img class="thumb" src={motionThumb} alt="Screenshot of Motion" /></a
>
<div class="thumb">
<Image src="motion.png" size="thumbnail" alt="Screenshot of Motion" />
</div>
<p>
Motion is an animation library for the Love2D game framework. It includes a
companion GUI tool for composing animations from spritesheets. Motion allows
Expand Down
12 changes: 1 addition & 11 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,7 @@ import { defineConfig } from "vite";
export default defineConfig({
plugins: [
sveltekit(),
imagetools({
defaultDirectives: (id) => {
if (id.searchParams.has("thumbnail")) {
return new URLSearchParams("w=300&format=webp");
}
if (id.searchParams.has("full")) {
return new URLSearchParams("w=960&format=webp");
}
return new URLSearchParams();
},
}),
imagetools(),
],
server: {
fs: {
Expand Down

0 comments on commit a2858db

Please sign in to comment.