coryd.dev/src/data/nav.js
Cory Dransfeldt efe701f939
feat(*.liquid): apply prettier to liquid templates
- offer to create tag when none is found while adding a link from cli
- fix tag display in search
2025-06-16 14:41:29 -07:00

50 lines
1.2 KiB
JavaScript

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();
}