From 1fbb2d3c4dbe50662010bf2e8ea07649c42e9008 Mon Sep 17 00:00:00 2001 From: satnaing Date: Sun, 29 Jan 2023 21:25:54 +0630 Subject: [PATCH] refactor: move filtering draft to getCollection func --- src/pages/search.astro | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/pages/search.astro b/src/pages/search.astro index c4f8ebb..f1972f5 100644 --- a/src/pages/search.astro +++ b/src/pages/search.astro @@ -8,16 +8,14 @@ import Footer from "@components/Footer.astro"; import Search from "@components/Search"; // Retrieve all articles -const posts = await getCollection("blog"); +const posts = await getCollection("blog", ({ data }) => !data.draft); // List of items to search in -const searchList = posts - .filter(({ data }) => !data.draft) - .map(({ data }) => ({ - title: data.title, - description: data.description, - data, - })); +const searchList = posts.map(({ data }) => ({ + title: data.title, + description: data.description, + data, +})); ---