diff --git a/config/filters/media.js b/config/filters/media.js
index 43a7e6a8..b349d82f 100644
--- a/config/filters/media.js
+++ b/config/filters/media.js
@@ -13,39 +13,26 @@ export default {
if (!data || !type) return ''
const dataSlice = data.slice(0, count)
-
if (dataSlice.length === 0) return null
- if (dataSlice.length === 1) {
- const item = dataSlice[0]
- if (type === 'genre') {
- return `${item['genre_name']}`
- } else if (type === 'artist') {
- return `${item['name']}`
- } else if (type === 'book') {
- return `${item['title']}`
+
+ const buildLink = (item) => {
+ switch (type) {
+ case 'genre':
+ return `${item['genre_name']}`
+ case 'artist':
+ return `${item['name']}`
+ case 'book':
+ return `${item['title']}`
+ default:
+ return ''
}
}
- const allButLast = dataSlice.slice(0, -1).map(item => {
- if (type === 'genre') {
- return `${item['genre_name']}`
- } else if (type === 'artist') {
- return `${item['name']}`
- } else if (type === 'book') {
- return `${item['title']}`
- }
- }).join(', ')
+ if (dataSlice.length === 1) return buildLink(dataSlice[0])
- let last
- const lastItem = dataSlice[dataSlice.length - 1]
-
- if (type === 'genre') {
- last = `${lastItem['genre_name']}`
- } else if (type === 'artist') {
- last = `${lastItem['name']}`
- } else if (type === 'book') {
- last = `${lastItem['title']}`
- }
+ const links = dataSlice.map(buildLink)
+ const allButLast = links.slice(0, -1).join(', ')
+ const last = links[links.length - 1]
return `${allButLast} and ${last}`
}