feat: add movies w/reviews to search

This commit is contained in:
Cory Dransfeldt 2024-05-24 11:17:31 -07:00
parent b3e4cde12b
commit c85c3e9cfa
No known key found for this signature in database
6 changed files with 40 additions and 50 deletions

View file

@ -7,7 +7,8 @@ export const searchIndex = (collection) => {
let id = 0
const collectionData = collection.getAll()[0]
const { data } = collectionData
const { collections: { posts, links } } = data
const { collections: { posts, links }, movies } = data
const movieData = movies.movies.filter(movie => (movie.review?.length && movie.review?.length > 0 && movie.rating))
const addItemToIndex = (items, icon, getUrl, getTitle, getTags) => {
if (items) {
items.forEach((item) => {
@ -15,7 +16,7 @@ export const searchIndex = (collection) => {
id,
url: getUrl(item),
title: `${icon}: ${getTitle(item)}`,
tags: getTags(item),
tags: getTags ? getTags(item) : [],
})
id++
})
@ -24,6 +25,7 @@ export const searchIndex = (collection) => {
addItemToIndex(posts, '📝', item => item.url.includes('http') ? item.url : `https://coryd.dev${item.url}`, item => item.data.title, item => item.data.tags.filter(tag => tag !== 'posts'))
addItemToIndex(links, '🔗', item => item.data.link, item => item.data.title, item => item.data.tags)
if (movieData) addItemToIndex(movieData, '🎥', item => item.url, item => `${item.title} (${item.rating})`)
return searchIndex
}