feat: everything is related
This commit is contained in:
parent
d1e3ab23bb
commit
077c54d5fb
20 changed files with 325 additions and 274 deletions
|
@ -243,11 +243,23 @@ export default {
|
|||
sortByPlaysDescending: (data, key) => data.sort((a, b) => b[key] - a[key]),
|
||||
genreStrings: (genres, key) => genres.map(genre => genre[key]),
|
||||
mediaLinks: (data, type, count = 10) => {
|
||||
if (!data || !type) return ''
|
||||
|
||||
const dataSlice = data.slice(0, count)
|
||||
let last;
|
||||
|
||||
if (dataSlice.length === 0) return null
|
||||
if (dataSlice.length === 1) return type === 'genre' ? dataSlice[0] : dataSlice[0]['artist_name']
|
||||
if (dataSlice.length === 1) {
|
||||
const item = dataSlice[0]
|
||||
if (type === 'genre') {
|
||||
return `<a href="/music/genres/${sanitizeMediaString(item)}">${item}</a>`
|
||||
} else if (type === 'artist') {
|
||||
return `<a href="/music/artists/${sanitizeMediaString(item['name_string'])}-${sanitizeMediaString(item['country'].toLowerCase())}">${item['name_string']}</a>`
|
||||
} else if (type === 'book') {
|
||||
return `<a href="/books/${item['isbn']}">${item['title']}</a>`
|
||||
} else if (type === 'movie') {
|
||||
return `<a href="${item['url']}">${item['title']}</a>`
|
||||
}
|
||||
}
|
||||
|
||||
const allButLast = dataSlice.slice(0, -1).map(item => {
|
||||
if (type === 'genre') {
|
||||
|
@ -256,17 +268,23 @@ export default {
|
|||
return `<a href="/music/artists/${sanitizeMediaString(item['name_string'])}-${sanitizeMediaString(item['country'].toLowerCase())}">${item['name_string']}</a>`
|
||||
} else if (type === 'book') {
|
||||
return `<a href="/books/${item['isbn']}">${item['title']}</a>`
|
||||
} else if (type === 'movie') {
|
||||
return `<a href="${item['url']}">${item['title']}</a>`
|
||||
}
|
||||
}).join(', ')
|
||||
|
||||
if (type === 'genre') {
|
||||
last = `<a href="/music/genres/${sanitizeMediaString(dataSlice[dataSlice.length - 1])}">${dataSlice[dataSlice.length - 1]}</a>`
|
||||
} else if (type === 'artist') {
|
||||
last = `<a href="/music/artists/${sanitizeMediaString(dataSlice[dataSlice.length - 1]['name_string'])}-${sanitizeMediaString(dataSlice[dataSlice.length - 1]['country'].toLowerCase())}">${dataSlice[dataSlice.length - 1]['name_string']}</a>`
|
||||
} else if (type === 'book') {
|
||||
last = `<a href="/books/${dataSlice[dataSlice.length - 1]['isbn']}">${dataSlice[dataSlice.length - 1]['title']}</a>`
|
||||
}
|
||||
let last
|
||||
const lastItem = dataSlice[dataSlice.length - 1]
|
||||
|
||||
if (type === 'genre') {
|
||||
last = `<a href="/music/genres/${sanitizeMediaString(lastItem)}">${lastItem}</a>`
|
||||
} else if (type === 'artist') {
|
||||
last = `<a href="/music/artists/${sanitizeMediaString(lastItem['name_string'])}-${sanitizeMediaString(lastItem['country'].toLowerCase())}">${lastItem['name_string']}</a>`
|
||||
} else if (type === 'book') {
|
||||
last = `<a href="/books/${lastItem['isbn']}">${lastItem['title']}</a>`
|
||||
} else if (type === 'movie') {
|
||||
last = `<a href="${lastItem['url']}">${lastItem['title']}</a>`
|
||||
}
|
||||
return `${allButLast} and ${last}`
|
||||
},
|
||||
formatVenue: (venue) => venue.split(',')[0].trim(),
|
||||
|
|
Reference in a new issue