refactor: update to AstroV2 and remove headings on search result

Update imports and types according to Astro v2 content collections. Remove headings on search result
for better search accuracy.
This commit is contained in:
satnaing
2023-01-28 00:58:40 +06:30
parent bf4f687d2d
commit db385b6567
2 changed files with 15 additions and 17 deletions
+8 -9
View File
@@ -1,23 +1,22 @@
---
import { SITE } from "src/config";
import { getCollection } from "astro:content";
import { SITE } from "@config";
import Layout from "@layouts/Layout.astro";
import Main from "@layouts/Main.astro";
import Header from "@components/Header.astro";
import Footer from "@components/Footer.astro";
import Search from "@components/Search";
import type { Frontmatter } from "src/types";
// Retrieve all articles
const posts = await Astro.glob<Frontmatter>("../contents/**/*.md");
const posts = await getCollection("blog");
// List of items to search in
const searchList = posts
.filter(({ frontmatter }) => !frontmatter.draft)
.map(post => ({
title: post.frontmatter.title,
description: post.frontmatter.description,
headings: post.getHeadings().map(h => h.text),
frontmatter: post.frontmatter,
.filter(({ data }) => !data.draft)
.map(({ data }) => ({
title: data.title,
description: data.description,
data,
}));
---