diff --git a/src/components/Header.astro b/src/components/Header.astro index d0bf8b8..009deb1 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -2,9 +2,30 @@ import { SITE } from "@consts"; import Button from "@components/Button.astro"; import { Icon } from "astro-icon/components"; +import { getCollection } from "astro:content"; const pathname = new URL(Astro.request.url).pathname; const currentPath = pathname.replace(/\/$/, ""); + +const allPosts = (await getCollection("posts")).filter( + (post) => !post.data.draft, +); +const hasPosts = allPosts.length > 0; + +const allProjects = (await getCollection("projects")).filter( + (post) => !post.data.draft, +); +const hasProjects = allProjects.length > 0; + +const filteredNavLinks = SITE.NAVLINKS.filter((link) => { + if (link.href === "/posts") { + return hasPosts; + } + if (link.href === "/projects") { + return hasProjects; + } + return true; +}); ---
@@ -17,9 +38,10 @@ const currentPath = pathname.replace(/\/$/, "");