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:
@@ -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}%`;
|
||||
}
|
||||
Reference in New Issue
Block a user