Skip to content

Commit

Permalink
feat(lib): create searchMatch function to be used as search algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusfg7 committed May 25, 2023
1 parent d4e3505 commit 543babb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/lib/match.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Post } from 'contentlayer/generated'
import { slug } from './utils'

export function searchMath(post: Post, search: string) {
const sluggedSearch = slug(search)

if (slug(post.title).includes(sluggedSearch)) return true
if (slug(post.description).includes(sluggedSearch)) return true
if (slug(post.author).includes(sluggedSearch)) return true
if (slug(post.category).includes(sluggedSearch)) return true
if (slug(post.status).includes(sluggedSearch)) return true
if (slug(post.tags).includes(sluggedSearch)) return true

return false
}

0 comments on commit 543babb

Please sign in to comment.