mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 07:33:07 +08:00
Update search result url with slugified url
This commit is contained in:
+13
-16
@@ -2,24 +2,21 @@
|
||||
import Fuse from "fuse.js";
|
||||
import { useEffect, useState } from "react";
|
||||
import Card from "@components/Card";
|
||||
import slugify from "@utils/slugify";
|
||||
import type { Frontmatter } from "src/types";
|
||||
|
||||
type SearchItem = {
|
||||
title: string;
|
||||
description: string;
|
||||
frontmatter: Frontmatter;
|
||||
};
|
||||
|
||||
interface Props {
|
||||
searchList: {
|
||||
title: string;
|
||||
description: string;
|
||||
frontmatter: Frontmatter;
|
||||
slug: string;
|
||||
}[];
|
||||
searchList: SearchItem[];
|
||||
}
|
||||
|
||||
interface SearchResult {
|
||||
item: {
|
||||
title: string;
|
||||
description: string;
|
||||
frontmatter: Frontmatter;
|
||||
slug: string;
|
||||
};
|
||||
item: SearchItem;
|
||||
refIndex: number;
|
||||
}
|
||||
|
||||
@@ -79,11 +76,11 @@ export default function SearchBar({ searchList }: Props) {
|
||||
|
||||
<ul>
|
||||
{searchResults &&
|
||||
searchResults.map((result) => (
|
||||
searchResults.map(({ item, refIndex }) => (
|
||||
<Card
|
||||
post={result.item.frontmatter}
|
||||
href={`/posts/${result.item.slug}`}
|
||||
key={`${result.refIndex}-${result.item.slug}`}
|
||||
post={item.frontmatter}
|
||||
href={`/posts/${slugify(item.frontmatter)}`}
|
||||
key={`${refIndex}-${slugify(item.frontmatter)}`}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user