{item.comment}
} -diff --git a/apps/site/src/pages/index.astro b/apps/site/src/pages/index.astro index 95e546e..2a8ffa1 100644 --- a/apps/site/src/pages/index.astro +++ b/apps/site/src/pages/index.astro @@ -1,76 +1,12 @@ --- import "../styles/global.css"; -type BoardCard = { - id: string | number; - title: string; - comment?: string | null; - imageUrl?: string | null; - published?: boolean; -}; - -type ApiResponse = { - docs?: BoardCard[]; -}; - -type BoardItem = { - id: string | number; - title: string; - comment?: string | null; - image: { - alt: string; - url: string; - } | null; -}; - const apiUrl = ( import.meta.env.API_URL || import.meta.env.PUBLIC_API_URL || "http://localhost:3001" ).replace(/\/$/, ""); -async function getCards() { - try { - const response = await fetch(`${apiUrl}/api/cards`); - - if (!response.ok) { - return []; - } - - const data = (await response.json()) as ApiResponse; - return data.docs ?? []; - } catch { - return []; - } -} - -function absolutize(url: string) { - if (/^https?:\/\//i.test(url)) { - return url; - } - - return `${apiUrl}${url.startsWith("/") ? "" : "/"}${url}`; -} - -function getImage(card: BoardCard) { - if (card.imageUrl) { - return { - alt: card.title, - url: absolutize(card.imageUrl) - }; - } - - return null; -} - -const cards = await getCards(); -const boardItems: BoardItem[] = cards.map((card) => ({ - id: card.id, - title: card.title, - comment: card.comment, - image: getImage(card) -})); -const boardStamp = boardItems.length === 0 ? "Empty" : `${boardItems.length} filed`; const adminUrl = `${apiUrl}/admin`; --- @@ -90,31 +26,63 @@ const adminUrl = `${apiUrl}/admin`;
тут только самое позорное.
-{item.comment}
} -