mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
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:
@@ -2,13 +2,12 @@ import Fuse from "fuse.js";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import Card from "@components/Card";
|
||||
import slugify from "@utils/slugify";
|
||||
import type { Frontmatter } from "src/types";
|
||||
import type { BlogFrontmatter } from "@content/_schemas";
|
||||
|
||||
type SearchItem = {
|
||||
export type SearchItem = {
|
||||
title: string;
|
||||
description: string;
|
||||
headings: string[];
|
||||
frontmatter: Frontmatter;
|
||||
data: BlogFrontmatter;
|
||||
};
|
||||
|
||||
interface Props {
|
||||
@@ -32,7 +31,7 @@ export default function SearchBar({ searchList }: Props) {
|
||||
};
|
||||
|
||||
const fuse = new Fuse(searchList, {
|
||||
keys: ["title", "description", "headings"],
|
||||
keys: ["title", "description"],
|
||||
includeMatches: true,
|
||||
minMatchCharLength: 2,
|
||||
threshold: 0.5,
|
||||
@@ -108,9 +107,9 @@ export default function SearchBar({ searchList }: Props) {
|
||||
{searchResults &&
|
||||
searchResults.map(({ item, refIndex }) => (
|
||||
<Card
|
||||
post={item.frontmatter}
|
||||
href={`/posts/${slugify(item.frontmatter)}`}
|
||||
key={`${refIndex}-${slugify(item.frontmatter)}`}
|
||||
href={`/posts/${slugify(item.data)}`}
|
||||
frontmatter={item.data}
|
||||
key={`${refIndex}-${slugify(item.data)}`}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user