From 5bcc678e133d1b94fce5d51b333daf6c117bf28c Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 24 Jun 2023 18:14:57 -0300 Subject: content: generateAlbumTrackListItem: form string from parts --- .../dependencies/generateAlbumTrackListItem.js | 35 +++++++++++----------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src/content') diff --git a/src/content/dependencies/generateAlbumTrackListItem.js b/src/content/dependencies/generateAlbumTrackListItem.js index 761a4b50..794c4201 100644 --- a/src/content/dependencies/generateAlbumTrackListItem.js +++ b/src/content/dependencies/generateAlbumTrackListItem.js @@ -37,28 +37,29 @@ export default { }, generate(data, relations, {getColors, html, language}) { - const stringOpts = { - duration: language.formatDuration(data.duration), - track: relations.trackLink, - }; - let style; + if (data.color) { const {primary} = getColors(data.color); style = `--primary-color: ${primary}`; } - return html.tag('li', - {style}, - (!data.showArtists - ? language.$('trackList.item.withDuration', stringOpts) - : language.$('trackList.item.withDuration.withArtists', { - ...stringOpts, - by: - html.tag('span', {class: 'by'}, - language.$('trackList.item.withArtists.by', { - artists: language.formatConjunctionList(relations.contributionLinks), - })), - }))); + const parts = ['trackList.item.withDuration']; + const options = {}; + + options.duration = language.formatDuration(data.duration); + options.track = relations.trackLink; + + if (data.showArtists) { + parts.push('withArtists'); + options.by = + html.tag('span', {class: 'by'}, + language.$('trackList.item.withArtists.by', { + artists: language.formatConjunctionList(relations.contributionLinks), + })); + } + + return html.tag('li', {style}, + language.formatString(parts.join('.'), options)); }, }; -- cgit 1.3.0-6-gf8a5