feat: feed/search/sitemap
This commit is contained in:
parent
086cd20788
commit
c6d00b2836
34 changed files with 198 additions and 535 deletions
19
src/data/activity.js
Normal file
19
src/data/activity.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { createClient } from '@supabase/supabase-js'
|
||||
|
||||
const SUPABASE_URL = process.env.SUPABASE_URL
|
||||
const SUPABASE_KEY = process.env.SUPABASE_KEY
|
||||
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
|
||||
|
||||
export default async function fetchSyndication() {
|
||||
const { data, error } = await supabase
|
||||
.from('optimized_all_activity')
|
||||
.select('feed')
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching search index data:', error)
|
||||
return []
|
||||
}
|
||||
|
||||
const [{ feed } = {}] = data
|
||||
return feed?.filter(item => item['feed'] !== null) || []
|
||||
}
|
|
@ -29,9 +29,8 @@ const fetchAlbumReleases = async () => {
|
|||
}).sort((a, b) => a['timestamp'] - b['timestamp'])
|
||||
|
||||
const upcoming = all.filter(album => album['release_timestamp'] > today)
|
||||
const current = all.filter(album => album['release_timestamp'] <= today)
|
||||
|
||||
return { all, upcoming, current }
|
||||
return { all, upcoming }
|
||||
}
|
||||
|
||||
export default async function () {
|
||||
|
|
|
@ -29,18 +29,6 @@ const fetchAllBooks = async () => {
|
|||
return books
|
||||
}
|
||||
|
||||
const processBooks = (books) => {
|
||||
return books.map(book => {
|
||||
const dateFinished = book['date_finished'] ? new Date(book['date_finished']) : null
|
||||
const year = dateFinished && !isNaN(dateFinished.getTime()) ? dateFinished.getUTCFullYear() : null
|
||||
|
||||
return {
|
||||
...book,
|
||||
year,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const sortBooksByYear = (books) => {
|
||||
const years = {}
|
||||
books.forEach(book => {
|
||||
|
@ -51,12 +39,11 @@ const sortBooksByYear = (books) => {
|
|||
years[year]['data'].push(book)
|
||||
}
|
||||
})
|
||||
return Object.values(years).filter(year => year.value > 2017)
|
||||
return Object.values(years).filter(year => year['value'] > 2017)
|
||||
}
|
||||
|
||||
export default async function () {
|
||||
const books = await fetchAllBooks()
|
||||
const processedBooks = processBooks(books)
|
||||
|
||||
return { all: processedBooks, years: sortBooksByYear(processedBooks) }
|
||||
return { all: books, years: sortBooksByYear(books), feed: books.filter(book => book['feed']) }
|
||||
}
|
|
@ -35,15 +35,15 @@ export default async function () {
|
|||
|
||||
try {
|
||||
const movies = await fetchAllMovies()
|
||||
const filterMovies = (condition) => movies.filter(condition)
|
||||
const favoriteMovies = filterMovies(movie => movie.favorite)
|
||||
const recentlyWatchedMovies = filterMovies(movie => movie.last_watched && year - DateTime.fromISO(movie.last_watched).year <= 3)
|
||||
const favoriteMovies = movies.filter(movie => movie['favorite'])
|
||||
const recentlyWatchedMovies = movies.filter(movie => movie['last_watched'] && year - DateTime.fromISO(movie['last_watched']).year <= 3)
|
||||
|
||||
return {
|
||||
movies,
|
||||
watchHistory: filterMovies(movie => movie.last_watched),
|
||||
watchHistory: movies.filter(movie => movie['last_watched']),
|
||||
recentlyWatched: recentlyWatchedMovies,
|
||||
favorites: favoriteMovies.sort((a, b) => a.title.localeCompare(b.title)),
|
||||
favorites: favoriteMovies.sort((a, b) => a['title'].localeCompare(b['title'])),
|
||||
feed: movies.filter(movie => movie['feed']),
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching and processing movies data:', error)
|
||||
|
@ -51,7 +51,8 @@ export default async function () {
|
|||
movies: [],
|
||||
watchHistory: [],
|
||||
recentlyWatched: [],
|
||||
favorites: []
|
||||
favorites: [],
|
||||
feed: []
|
||||
}
|
||||
}
|
||||
}
|
19
src/data/search.js
Normal file
19
src/data/search.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { createClient } from '@supabase/supabase-js'
|
||||
|
||||
const SUPABASE_URL = process.env.SUPABASE_URL
|
||||
const SUPABASE_KEY = process.env.SUPABASE_KEY
|
||||
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
|
||||
|
||||
export default async function fetchSearchIndex() {
|
||||
const { data, error } = await supabase
|
||||
.from('optimized_search_index')
|
||||
.select('search_index')
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching search index data:', error)
|
||||
return []
|
||||
}
|
||||
|
||||
const [{ search_index } = {}] = data
|
||||
return search_index || []
|
||||
}
|
19
src/data/sitemap.js
Normal file
19
src/data/sitemap.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { createClient } from '@supabase/supabase-js'
|
||||
|
||||
const SUPABASE_URL = process.env.SUPABASE_URL
|
||||
const SUPABASE_KEY = process.env.SUPABASE_KEY
|
||||
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
|
||||
|
||||
export default async function fetchSitemap() {
|
||||
const { data, error } = await supabase
|
||||
.from('optimized_sitemap')
|
||||
.select('sitemap')
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching sitemap data:', error)
|
||||
return []
|
||||
}
|
||||
|
||||
const [{ sitemap } = {}] = data
|
||||
return sitemap || []
|
||||
}
|
19
src/data/syndication.js
Normal file
19
src/data/syndication.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { createClient } from '@supabase/supabase-js'
|
||||
|
||||
const SUPABASE_URL = process.env.SUPABASE_URL
|
||||
const SUPABASE_KEY = process.env.SUPABASE_KEY
|
||||
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
|
||||
|
||||
export default async function fetchSyndication() {
|
||||
const { data, error } = await supabase
|
||||
.from('optimized_syndication')
|
||||
.select('syndication')
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching search index data:', error)
|
||||
return []
|
||||
}
|
||||
|
||||
const [{ syndication } = {}] = data
|
||||
return syndication?.filter(item => item['syndication'] !== null) || []
|
||||
}
|
Reference in a new issue