chore: refactoring

This commit is contained in:
Cory Dransfeldt 2024-10-08 17:35:26 -07:00
parent df5fddefc0
commit e0593447eb
No known key found for this signature in database
40 changed files with 181 additions and 232 deletions

View file

@ -1,6 +1,4 @@
import { createClient } from '@supabase/supabase-js'
import slugify from 'slugify'
import { sanitizeMediaString, parseCountryField } from '../../config/utilities/index.js'
const SUPABASE_URL = process.env['SUPABASE_URL']
const SUPABASE_KEY = process.env['SUPABASE_KEY']
@ -110,34 +108,27 @@ const processPosts = async (posts, tagsByPostId, blocksByPostId) => {
})).then(blocks => blocks.filter(block => block !== null))
// artists
post['artists'] = post['artists']?.[0]?.['id'] ? post['artists'].map(artist => {
artist['url'] = `/music/artists/${sanitizeMediaString(artist['name'])}-${sanitizeMediaString(parseCountryField(artist['country']))}`
return artist
}).sort((a, b) => a['name'].localeCompare(b['name'])) : null
post['artists'] = post['artists'] ? post['artists'].sort((a, b) => a['name'].localeCompare(b['name'])) : null
// books
post['books'] = post['books']?.[0]?.['id'] ? post['books'].map(book => ({
post['books'] = post['books'] ? post['books'].map(book => ({
title: book['title'],
author: book['author'],
isbn: book['isbn'],
description: book['description'],
url: `/books/${book['isbn']}`,
})).sort((a, b) => a['title'].localeCompare(b['title'])) : null
// movies
post['movies'] = post['movies']?.[0]?.['id'] ? post['movies'].map(movie => {
post['movies'] = post['movies'] ? post['movies'].map(movie => {
movie['url'] = `/watching/movies/${movie['tmdb_id']}`
return movie
}).sort((a, b) => b['year'] - a['year']) : null
// genres
post['genres'] = post['genres']?.[0]?.['id'] ? post['genres'].map(genre => {
genre['url'] = `/music/genres/${slugify(genre['name'].replace('/', '-').toLowerCase())}`
return genre
}).sort((a, b) => a['name'].localeCompare(b['name'])) : null
post['genres'] = post['genres'] ? post['genres'].sort((a, b) => a['name'].localeCompare(b['name'])) : null
// shows
post['shows'] = post['shows']?.[0]?.['id'] ? post['shows'].map(show => {
post['shows'] = post['shows'] ? post['shows'].map(show => {
show['url'] = `/watching/shows/${show['tmdb_id']}`
return show
}).sort((a, b) => b['year'] - a['year']) : null