From f55ae8a267df0ce93da175c0d2a36c1226c721fa Mon Sep 17 00:00:00 2001 From: Max Richter Date: Fri, 21 Jun 2024 16:22:49 +0200 Subject: [PATCH] feat: add exif data to image tags --- src/helpers/image.ts | 16 +++------------- src/pages/tag/[tag].astro | 7 +------ 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/helpers/image.ts b/src/helpers/image.ts index c66f6c0..4d4f0af 100644 --- a/src/helpers/image.ts +++ b/src/helpers/image.ts @@ -1,22 +1,12 @@ -let loadingSharp = false; import { rgbaToThumbHash } from "thumbhash"; import ExifReader from 'exifreader'; +import type { ImageMetadata } from "astro"; let s: typeof import("sharp") | undefined; - async function getSharp(): Promise { - if (s) return s; s = (await import("sharp")).default; return s; - - if (!loadingSharp) { - loadingSharp = true; - setTimeout(async () => { - s = (await import("sharp")).default; - }, 1000); - return; - } } export async function generateThumbHash(image: { width: number, height: number }) { @@ -54,10 +44,10 @@ const allowedExif = [ "IsoSpeedRatings", ]; -export async function getExifData(image: { fsPath: string }) { +export async function getExifData(image: ImageMetadata) { const sharp = await getSharp(); if (!sharp) return; - const tags = await ExifReader.load(image.fsPath, { async: true }); + const tags = await ExifReader.load((image as ImageMetadata & { fsPath: string }).fsPath, { async: true }); const out: Record = {}; let hasExif = false; diff --git a/src/pages/tag/[tag].astro b/src/pages/tag/[tag].astro index a85d04e..cde190a 100644 --- a/src/pages/tag/[tag].astro +++ b/src/pages/tag/[tag].astro @@ -1,14 +1,11 @@ --- import Layout from "@layouts/Layout.astro"; import { getCollection } from "astro:content"; -import { useTranslatedPath } from "@i18n/utils"; import SmallCard from "@components/SmallCard.astro"; import SmallGrid from "@components/SmallGrid.astro"; const collections = ["blog", "photos", "projects"] as const; -const tp = useTranslatedPath(Astro.url); - export async function getStaticPaths() { const collections = ["blog", "photos", "projects"] as const; const posts = await Promise.all( @@ -54,9 +51,7 @@ const posts = allPosts.filter((post) => { { posts.map((post) => { - return ( - - ); + return ; }) }