naslovnice: fokusna tocka obraza povsod (aktuelles, kategorije, videi, iskanje, clanek + sorodni), skupni pomocnik lib/focal, streznik osvezuje fokusne tocke vsakih 20 minut

This commit is contained in:
claude
2026-08-20 07:15:07 +02:00
parent 2ec7c259c3
commit ca47bc8698
7 changed files with 61 additions and 13 deletions
+30
View File
@@ -0,0 +1,30 @@
import { useQuery } from "@tanstack/react-query";
export type FocalPoint = { x: number; y: number };
export type FocalMap = Record<string, FocalPoint>;
/**
* Fokusne tocke naslovnic (obraz na sliki), ki jih izracuna streznik
* (server/focal-point.ts) in postreze na /api/focal-points.
* Uporabi POVSOD, kjer se naslovnica clanka prikazuje z object-cover,
* sicer brskalnik obreze na sredino in odreze glave.
*/
export function useFocalPoints() {
const { data } = useQuery<FocalMap>({
queryKey: ["/api/focal-points"],
staleTime: 10 * 60 * 1000,
});
return data;
}
/** Vrne vrednost za CSS object-position. */
export function objectPositionFor(coverImage: string | null | undefined, focalPoints?: FocalMap): string {
const FALLBACK = "center 25%";
if (!coverImage || !focalPoints) return FALLBACK;
const fp =
focalPoints[coverImage] ||
focalPoints[coverImage.replace(/^https?:\/\/[^/]+/, "")] ||
focalPoints["https://folx.tv" + coverImage];
if (!fp) return FALLBACK;
return `${fp.x}% ${fp.y}%`;
}