refactor: move filtering draft to getCollection func

This commit is contained in:
satnaing
2023-01-29 21:25:54 +06:30
parent 4a0bd18b1b
commit 1fbb2d3c4d
+3 -5
View File
@@ -8,16 +8,14 @@ import Footer from "@components/Footer.astro";
import Search from "@components/Search"; import Search from "@components/Search";
// Retrieve all articles // Retrieve all articles
const posts = await getCollection("blog"); const posts = await getCollection("blog", ({ data }) => !data.draft);
// List of items to search in // List of items to search in
const searchList = posts const searchList = posts.map(({ data }) => ({
.filter(({ data }) => !data.draft)
.map(({ data }) => ({
title: data.title, title: data.title,
description: data.description, description: data.description,
data, data,
})); }));
--- ---
<Layout title={`Search | ${SITE.title}`}> <Layout title={`Search | ${SITE.title}`}>