Update search result url with slugified url

This commit is contained in:
Sat Naing
2022-09-25 19:11:19 +06:30
parent 0983bcf8e1
commit 93fa12a25b
+13 -16
View File
@@ -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>