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 Fuse from "fuse.js";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import Card from "@components/Card";
|
import Card from "@components/Card";
|
||||||
|
import slugify from "@utils/slugify";
|
||||||
import type { Frontmatter } from "src/types";
|
import type { Frontmatter } from "src/types";
|
||||||
|
|
||||||
|
type SearchItem = {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
frontmatter: Frontmatter;
|
||||||
|
};
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
searchList: {
|
searchList: SearchItem[];
|
||||||
title: string;
|
|
||||||
description: string;
|
|
||||||
frontmatter: Frontmatter;
|
|
||||||
slug: string;
|
|
||||||
}[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SearchResult {
|
interface SearchResult {
|
||||||
item: {
|
item: SearchItem;
|
||||||
title: string;
|
|
||||||
description: string;
|
|
||||||
frontmatter: Frontmatter;
|
|
||||||
slug: string;
|
|
||||||
};
|
|
||||||
refIndex: number;
|
refIndex: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,11 +76,11 @@ export default function SearchBar({ searchList }: Props) {
|
|||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
{searchResults &&
|
{searchResults &&
|
||||||
searchResults.map((result) => (
|
searchResults.map(({ item, refIndex }) => (
|
||||||
<Card
|
<Card
|
||||||
post={result.item.frontmatter}
|
post={item.frontmatter}
|
||||||
href={`/posts/${result.item.slug}`}
|
href={`/posts/${slugify(item.frontmatter)}`}
|
||||||
key={`${result.refIndex}-${result.item.slug}`}
|
key={`${refIndex}-${slugify(item.frontmatter)}`}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user