Skip to content

Commit

Permalink
feat: hide categories without posts
Browse files Browse the repository at this point in the history
  • Loading branch information
EATSTEAK committed Jun 24, 2024
1 parent c2589b3 commit 8cf41cd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/pages/category/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { SITE_TITLE, SITE_DESCRIPTION, CATEGORIES } from "../../consts";
import Layout from "../../layouts/Layout.astro";
import { GrillContainer } from "../../components/GrillContainer";
import { Container } from "../../components/Container";
import type { CollectionEntry } from "astro:content";
async function getTopics() {
const posts = await getCollection("blog");
const posts = await getCollection("blog");
function getTopics(posts: CollectionEntry<"blog">[]) {
const initial: { [topic: string]: number } = {};
return posts
.filter((post) => post.data.hidden !== true)
Expand All @@ -20,9 +22,14 @@ async function getTopics() {
}, initial);
}
const categories = Object.values(CATEGORIES);
const categories = Object.values(CATEGORIES).filter(
(category) =>
posts.find(
(post) => post.data.hidden != true && post.data.category == category.id,
) != undefined,
);
const topics = Object.keys(await getTopics());
const topics = Object.keys(getTopics(posts));
---

<Layout title={SITE_TITLE} description={SITE_DESCRIPTION}>
Expand Down

0 comments on commit 8cf41cd

Please sign in to comment.