feat: related posts + show tags

This commit is contained in:
Cory Dransfeldt 2024-08-25 10:44:47 -07:00
parent 9111405c3f
commit 510e07da4f
No known key found for this signature in database
19 changed files with 215 additions and 79 deletions

View file

@ -29,7 +29,8 @@ const fetchAllArtists = async () => {
albums,
concerts,
books,
movies
movies,
posts
`)
.range(rangeStart, rangeStart + PAGE_SIZE - 1)
@ -82,6 +83,13 @@ const processArtists = (artists) => {
tmdb_id: movie['tmdb_id'],
url: `/watching/movies/${movie['tmdb_id']}`,
})).sort((a, b) => b['year'] - a['year']) : null,
posts: artist['posts']?.[0]?.['id'] ? artist['posts'].map(post => ({
id: post['id'],
title: post['title'],
date: post['date'],
slug: post['slug'],
url: post['slug'],
})).sort((a, b) => new Date(b['date']) - new Date(a['date'])) : null,
}))
}

View file

@ -32,7 +32,8 @@ const fetchAllBooks = async () => {
artists,
movies,
genres,
shows
shows,
posts
`)
.order('date_finished', { ascending: false })
.range(rangeStart, rangeStart + PAGE_SIZE - 1)
@ -68,7 +69,7 @@ const processBooks = (books) => {
date: book['date_finished'],
status: book['read_status'],
progress: book['progress'],
tags: Array.isArray(book['tags']) ? book['tags'] : book['tags']?.split(',') || [], // Ensure tags is an array
tags: Array.isArray(book['tags']) ? book['tags'] : book['tags']?.split(',') || [],
isbn: book['isbn'],
type: 'book',
artists: book['artists']?.[0]?.['id'] ? book['artists'].map(artist => {
@ -87,6 +88,13 @@ const processBooks = (books) => {
show['url'] = `/watching/shows/${show['tmdb_id']}`
return show
}).sort((a, b) => b['year'] - a['year']) : null,
posts: book['posts']?.[0]?.['id'] ? book['posts'].map(post => ({
id: post['id'],
title: post['title'],
date: post['date'],
slug: post['slug'],
url: post['slug'],
})).sort((a, b) => new Date(b['date']) - new Date(a['date'])) : null,
year,
}
})

View file

@ -23,7 +23,8 @@ const fetchGenresWithArtists = async () => {
favorite
),
books,
movies
movies,
posts
`)
.order('id', { ascending: true })
@ -52,6 +53,13 @@ const fetchGenresWithArtists = async () => {
tmdb_id: movie['tmdb_id'],
url: `/watching/movies/${movie['tmdb_id']}`,
})).sort((a, b) => b['year'] - a['year']) : null,
posts: genre['posts']?.[0]?.['id'] ? genre['posts'].map(post => ({
id: post['id'],
title: post['title'],
date: post['date'],
slug: post['slug'],
url: post['slug'],
})).sort((a, b) => new Date(b['date']) - new Date(a['date'])) : null,
}))
}

View file

@ -34,7 +34,8 @@ const fetchAllMovies = async () => {
artists,
books,
genres,
shows
shows,
posts
`)
.order('last_watched', { ascending: false })
.range(rangeStart, rangeStart + PAGE_SIZE - 1)
@ -88,6 +89,13 @@ const processMovies = (movies) => {
show['url'] = `/watching/shows/${show['tmdb_id']}`
return show
}).sort((a, b) => b['year'] - a['year']) : null,
posts: item['posts']?.[0]?.['id'] ? item['posts'].map(post => ({
id: post['id'],
title: post['title'],
date: post['date'],
slug: post['slug'],
url: post['slug'],
})).sort((a, b) => new Date(b['date']) - new Date(a['date'])) : null,
}))
}

View file

@ -1,4 +1,6 @@
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']
@ -92,9 +94,11 @@ const fetchAllPosts = async () => {
const processPosts = async (posts, tagsByPostId, blocksByPostId) => {
return Promise.all(posts.map(async post => {
// tags
post['tags'] = tagsByPostId[post['id']] || []
const blocks = blocksByPostId[post['id']] || []
// blocks
const blocks = blocksByPostId[post['id']] || []
post['blocks'] = await Promise.all(blocks.map(async block => {
const blockData = await fetchBlockData(block['collection'], block['item'])
if (!blockData) return null
@ -105,7 +109,42 @@ 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
// books
post['books'] = post['books']?.[0]?.['id'] ? 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 => {
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
// shows
post['shows'] = post['shows']?.[0]?.['id'] ? post['shows'].map(show => {
show['url'] = `/watching/shows/${show['tmdb_id']}`
return show
}).sort((a, b) => b['year'] - a['year']) : null
// image
if (post['image']) post['image'] = post['image']['filename_disk']
return post
}))
}

View file

@ -25,9 +25,11 @@ const fetchAllShows = async () => {
review,
art,
backdrop,
tags,
episodes,
movies,
books
books,
posts
`)
.range(rangeStart, rangeStart + PAGE_SIZE - 1)
@ -51,6 +53,7 @@ const prepareShowData = (show) => ({
url: `/watching/shows/${show['tmdb_id']}`,
episodes: show['episodes'] || [],
tattoo: show['tattoo'],
tags: Array.isArray(show['tags']) ? show['tags'] : show['tags']?.split(',') || [],
movies: show['movies']?.[0]?.['id'] ? show['movies'].map(movie => {
movie['url'] = `/watching/movies/${movie['tmdb_id']}`
return movie
@ -62,6 +65,13 @@ const prepareShowData = (show) => ({
description: book['description'],
url: `/books/${book['isbn']}`,
})).sort((a, b) => a['title'].localeCompare(b['title'])) : null,
posts: show['posts']?.[0]?.['id'] ? show['posts'].map(post => ({
id: post['id'],
title: post['title'],
date: post['date'],
slug: post['slug'],
url: post['slug'],
})).sort((a, b) => new Date(b['date']) - new Date(a['date'])) : null,
})
const prepareEpisodeData = (show) => show['episodes'].map(episode => ({