feat: add exif data to image tags
Some checks failed
Deploy to SFTP Server / build (push) Failing after 2m10s

This commit is contained in:
max_richter 2024-06-21 16:22:49 +02:00
parent e5726437ed
commit f55ae8a267
2 changed files with 4 additions and 19 deletions

View File

@ -1,22 +1,12 @@
let loadingSharp = false;
import { rgbaToThumbHash } from "thumbhash"; import { rgbaToThumbHash } from "thumbhash";
import ExifReader from 'exifreader'; import ExifReader from 'exifreader';
import type { ImageMetadata } from "astro";
let s: typeof import("sharp") | undefined; let s: typeof import("sharp") | undefined;
async function getSharp(): Promise<typeof import("sharp") | undefined> { async function getSharp(): Promise<typeof import("sharp") | undefined> {
if (s) return s; if (s) return s;
s = (await import("sharp")).default; s = (await import("sharp")).default;
return s; return s;
if (!loadingSharp) {
loadingSharp = true;
setTimeout(async () => {
s = (await import("sharp")).default;
}, 1000);
return;
}
} }
export async function generateThumbHash(image: { width: number, height: number }) { export async function generateThumbHash(image: { width: number, height: number }) {
@ -54,10 +44,10 @@ const allowedExif = [
"IsoSpeedRatings", "IsoSpeedRatings",
]; ];
export async function getExifData(image: { fsPath: string }) { export async function getExifData(image: ImageMetadata) {
const sharp = await getSharp(); const sharp = await getSharp();
if (!sharp) return; 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<string, any> = {}; const out: Record<string, any> = {};
let hasExif = false; let hasExif = false;

View File

@ -1,14 +1,11 @@
--- ---
import Layout from "@layouts/Layout.astro"; import Layout from "@layouts/Layout.astro";
import { getCollection } from "astro:content"; import { getCollection } from "astro:content";
import { useTranslatedPath } from "@i18n/utils";
import SmallCard from "@components/SmallCard.astro"; import SmallCard from "@components/SmallCard.astro";
import SmallGrid from "@components/SmallGrid.astro"; import SmallGrid from "@components/SmallGrid.astro";
const collections = ["blog", "photos", "projects"] as const; const collections = ["blog", "photos", "projects"] as const;
const tp = useTranslatedPath(Astro.url);
export async function getStaticPaths() { export async function getStaticPaths() {
const collections = ["blog", "photos", "projects"] as const; const collections = ["blog", "photos", "projects"] as const;
const posts = await Promise.all( const posts = await Promise.all(
@ -54,9 +51,7 @@ const posts = allPosts.filter((post) => {
<SmallGrid> <SmallGrid>
{ {
posts.map((post) => { posts.map((post) => {
return ( return <SmallCard post={post} />;
<SmallCard post={post} />
);
}) })
} }
</SmallGrid> </SmallGrid>