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

@ -1,25 +1,10 @@
import { createClient } from '@supabase/supabase-js'
import { parseCountryField } from './utilities/index.js'
const SUPABASE_URL = process.env.SUPABASE_URL || 'YOUR_SUPABASE_URL'
const SUPABASE_KEY = process.env.SUPABASE_KEY || 'YOUR_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 fetchPaginatedData = async (table, selectFields) => {

View file

@ -1,36 +1,11 @@
import { createClient } from '@supabase/supabase-js'
import { DateTime } from 'luxon'
import slugify from 'slugify'
import { sanitizeMediaString, parseCountryField } from './utilities/index.js'
const SUPABASE_URL = process.env.SUPABASE_URL
const SUPABASE_KEY = process.env.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 PAGE_SIZE = 1000
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(', ')
}