feat: add ratings
This commit is contained in:
parent
c37fc2f1a3
commit
614d1e210c
13 changed files with 98 additions and 66 deletions
|
@ -45,12 +45,11 @@ export const followContent = (collection) => {
|
|||
if (!parsedDate.isValid) parsedDate = DateTime.fromFormat(date, 'dd-MM-yyyy')
|
||||
return parsedDate.isValid ? parsedDate.toISO() : null
|
||||
}
|
||||
|
||||
const addContent = (items, icon, getTitle, getDate) => {
|
||||
if (items) {
|
||||
items.forEach(item => {
|
||||
const content = {
|
||||
url: item.url.includes('http') ? item.url : `https://coryd.dev${item.url}`,
|
||||
url: item.url?.includes('http') ? item.url : `https://coryd.dev${item.url}`,
|
||||
title: `${icon}: ${getTitle(item)}`
|
||||
}
|
||||
if (item.data?.link) content.url = item.data?.link
|
||||
|
@ -63,8 +62,8 @@ export const followContent = (collection) => {
|
|||
|
||||
addContent(posts, '📝', item => item.data.title, item => item.data.date)
|
||||
addContent(links, '🔗', item => item.data.title, item => item.data.date)
|
||||
addContent(books.filter(book => book.status === 'started'), '📖', item => item.title, item => item.date)
|
||||
addContent(movies, '🎥', item => item.title, item => item.lastWatched)
|
||||
addContent(books.filter(book => book.status === 'finished'), '📖', item => item.title, item => item.date)
|
||||
addContent(movies, '🎥', item => `${item.title}${item.rating ? ' (' + item.rating + ')' : ''}`, item => item.lastWatched)
|
||||
addContent(weeklyArtistChart, '🎧', item => item.title, item => item.date)
|
||||
|
||||
return aggregateContent.sort((a, b) => {
|
||||
|
|
|
@ -174,6 +174,7 @@ export default {
|
|||
content: entry?.description || entry?.data?.description,
|
||||
date,
|
||||
excerpt,
|
||||
rating: entry?.rating || ''
|
||||
})
|
||||
})
|
||||
return posts
|
||||
|
@ -197,7 +198,12 @@ export default {
|
|||
normalized['alt'] = `${item['plays']} plays of ${item['title']}`
|
||||
normalized['subtext'] = `${item['plays']} plays`
|
||||
}
|
||||
if (item.type === 'movie') normalized['alt'] = item['title']
|
||||
if (item.type === 'movie') {
|
||||
normalized['title'] = `${item['title']} (${item['year']})`
|
||||
normalized['alt'] = item['title']
|
||||
normalized['rating'] = item['rating']
|
||||
normalized['subtext'] = item['rating']
|
||||
}
|
||||
if (item.type === 'book') {
|
||||
normalized['alt'] = `${item['title']} by ${item['authors']}`
|
||||
normalized['subtext'] = `${item['percentage']} finished`
|
||||
|
@ -217,14 +223,15 @@ export default {
|
|||
}),
|
||||
calculatePlayPercentage: (plays, mostPlayed) => `${plays/mostPlayed * 100}%`,
|
||||
bookStatus: (books, status) => books.filter(book => book.status === status),
|
||||
bookFinishedYear: (books, year) => books.filter(book => {
|
||||
if (book.status === 'finished' && book.date) return parseInt(book.date.split('-')[0]) === year
|
||||
return ''
|
||||
}).sort((a, b) => {
|
||||
bookSortDescending: (books) => books.sort((a, b) => {
|
||||
const dateA = DateTime.fromISO(a.date)
|
||||
const dateB = DateTime.fromISO(b.date)
|
||||
return dateB - dateA
|
||||
}),
|
||||
bookFinishedYear: (books, year) => books.filter(book => {
|
||||
if (book.status === 'finished' && book.date) return parseInt(book.date.split('-')[0]) === year
|
||||
return ''
|
||||
}),
|
||||
currentBookCount: (books) => {
|
||||
const year = DateTime.now().year
|
||||
return books.filter(book => {
|
||||
|
|
Reference in a new issue