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 let id = 0
const collectionData = collection.getAll()[0] const collectionData = collection.getAll()[0]
const { data } = collectionData 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) => { const addItemToIndex = (items, icon, getUrl, getTitle, getTags) => {
if (items) { if (items) {
items.forEach((item) => { items.forEach((item) => {
@ -15,7 +16,7 @@ export const searchIndex = (collection) => {
id, id,
url: getUrl(item), url: getUrl(item),
title: `${icon}: ${getTitle(item)}`, title: `${icon}: ${getTitle(item)}`,
tags: getTags(item), tags: getTags ? getTags(item) : [],
}) })
id++ 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(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) 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 return searchIndex
} }

10
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "17.0.5", "version": "17.1.5",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "coryd.dev", "name": "coryd.dev",
"version": "17.0.5", "version": "17.1.5",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@cdransf/api-text": "^1.2.2", "@cdransf/api-text": "^1.2.2",
@ -3346,9 +3346,9 @@
"dev": true "dev": true
}, },
"node_modules/electron-to-chromium": { "node_modules/electron-to-chromium": {
"version": "1.4.782", "version": "1.4.783",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.782.tgz", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.783.tgz",
"integrity": "sha512-JUfU61e8tr+i5Y1FKXcKs+Xe+rJ+CEqm4cgv1kMihPE2EvYHmYyVr3Im/+1+Z5B29Be2EEGCZCwAc6Tazdl1Yg==", "integrity": "sha512-bT0jEz/Xz1fahQpbZ1D7LgmPYZ3iHVY39NcWWro1+hA2IvjiPeaXtfSqrQ+nXjApMvQRE2ASt1itSLRrebHMRQ==",
"dev": true "dev": true
}, },
"node_modules/encodeurl": { "node_modules/encodeurl": {

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "17.0.5", "version": "17.1.5",
"description": "The source for my personal site. Built using 11ty.", "description": "The source for my personal site. Built using 11ty.",
"type": "module", "type": "module",
"scripts": { "scripts": {

View file

@ -1,25 +1,10 @@
import { createClient } from '@supabase/supabase-js' import { createClient } from '@supabase/supabase-js'
import { parseCountryField } from './utilities/index.js'
const SUPABASE_URL = process.env.SUPABASE_URL || 'YOUR_SUPABASE_URL' const SUPABASE_URL = process.env.SUPABASE_URL || 'YOUR_SUPABASE_URL'
const SUPABASE_KEY = process.env.SUPABASE_KEY || 'YOUR_SUPABASE_KEY' const SUPABASE_KEY = process.env.SUPABASE_KEY || 'YOUR_SUPABASE_KEY'
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY) const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
const regionNames = new Intl.DisplayNames(['en'], { type: 'region' })
const getCountryName = (countryCode) => regionNames.of(countryCode.trim()) || countryCode.trim()
const parseCountryField = (countryField) => {
if (!countryField) return null
const delimiters = [',', '/', '&', 'and']
let countries = [countryField]
delimiters.forEach(delimiter => {
countries = countries.flatMap(country => country.split(delimiter))
})
return countries.map(getCountryName).join(', ')
}
const PAGE_SIZE = 50 const PAGE_SIZE = 50
const fetchPaginatedData = async (table, selectFields) => { const fetchPaginatedData = async (table, selectFields) => {

View file

@ -1,36 +1,11 @@
import { createClient } from '@supabase/supabase-js' import { createClient } from '@supabase/supabase-js'
import { DateTime } from 'luxon' import { DateTime } from 'luxon'
import slugify from 'slugify' import { sanitizeMediaString, parseCountryField } from './utilities/index.js'
const SUPABASE_URL = process.env.SUPABASE_URL const SUPABASE_URL = process.env.SUPABASE_URL
const SUPABASE_KEY = process.env.SUPABASE_KEY const SUPABASE_KEY = process.env.SUPABASE_KEY
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY) const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
const sanitizeMediaString = (str) => {
const sanitizedString = str.normalize('NFD').replace(/[\u0300-\u036f\u2010—\.\?\(\)\[\]\{\}]/g, '').replace(/\.{3}/g, '')
return slugify(sanitizedString, {
replacement: '-',
remove: /[#,&,+()$~%.'":*?<>{}]/g,
lower: true,
})
}
const regionNames = new Intl.DisplayNames(['en'], { type: 'region' })
const getCountryName = (countryCode) => regionNames.of(countryCode.trim()) || countryCode.trim()
const parseCountryField = (countryField) => {
if (!countryField) return null
const delimiters = [',', '/', '&', 'and']
let countries = [countryField]
delimiters.forEach(delimiter => {
countries = countries.flatMap(country => country.split(delimiter))
})
return countries.map(getCountryName).join(', ')
}
const fetchDataForPeriod = async (startPeriod, fields, table) => { const fetchDataForPeriod = async (startPeriod, fields, table) => {
const PAGE_SIZE = 1000 const PAGE_SIZE = 1000
let rows = [] let rows = []

View file

@ -0,0 +1,28 @@
import slugify from 'slugify'
export const sanitizeMediaString = (str) => {
const sanitizedString = str.normalize('NFD').replace(/[\u0300-\u036f\u2010—\.\?\(\)\[\]\{\}]/g, '').replace(/\.{3}/g, '')
return slugify(sanitizedString, {
replacement: '-',
remove: /[#,&,+()$~%.'":*?<>{}]/g,
lower: true,
})
}
export const regionNames = new Intl.DisplayNames(['en'], { type: 'region' })
export const getCountryName = (countryCode) => regionNames.of(countryCode.trim()) || countryCode.trim()
export const parseCountryField = (countryField) => {
if (!countryField) return null
const delimiters = [',', '/', '&', 'and']
let countries = [countryField]
delimiters.forEach(delimiter => {
countries = countries.flatMap(country => country.split(delimiter))
})
return countries.map(getCountryName).join(', ')
}