import EleventyFetch from "@11ty/eleventy-fetch"; const { POSTGREST_URL, POSTGREST_API_KEY } = process.env; const fetchAllNavigation = async () => { try { const data = await EleventyFetch(`${POSTGREST_URL}/optimized_navigation?select=*`, { duration: "1d", type: "json", fetchOptions: { method: "GET", headers: { "Content-Type": "application/json", Authorization: `Bearer ${POSTGREST_API_KEY}` } } }); const nav = data.reduce((acc, item) => { const navItem = { title: item.title || item.page_title, permalink: item.permalink || item.page_permalink, icon: item.icon, section: item.section, sort: item.sort }; if (!acc[item.menu_location]) { acc[item.menu_location] = [navItem]; } else { acc[item.menu_location].push(navItem); } return acc; }, {}); Object.keys(nav).forEach((location) => { nav[location].sort((a, b) => a.sort - b.sort); }); return nav; } catch (error) { console.error("Error fetching navigation data:", error); return {}; } }; export default async function () { return await fetchAllNavigation(); }