From 4e2993f3bedd8e413e56aafcb96a22b16d930680 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 12 Jun 2023 17:11:35 -0300 Subject: content: linkExternal: slot mode instead of taking type option --- src/content/dependencies/generateAlbumInfoPage.js | 7 +++++-- src/content/dependencies/linkExternal.js | 23 ++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/content') diff --git a/src/content/dependencies/generateAlbumInfoPage.js b/src/content/dependencies/generateAlbumInfoPage.js index e317adb1..09de21bf 100644 --- a/src/content/dependencies/generateAlbumInfoPage.js +++ b/src/content/dependencies/generateAlbumInfoPage.js @@ -99,7 +99,7 @@ export default { listen.externalLinks = album.urls.map(url => - relation('linkExternal', url, {type: 'album'})); + relation('linkExternal', url)); } // Section: Extra links @@ -234,7 +234,10 @@ export default { sec.listen && html.tag('p', language.$('releaseInfo.listenOn', { - links: language.formatDisjunctionList(sec.listen.externalLinks), + links: + language.formatDisjunctionList( + sec.listen.externalLinks + .map(link => link.slot('mode', 'album'))), })), html.tag('p', diff --git a/src/content/dependencies/linkExternal.js b/src/content/dependencies/linkExternal.js index 08191a21..7c3d86a8 100644 --- a/src/content/dependencies/linkExternal.js +++ b/src/content/dependencies/linkExternal.js @@ -5,21 +5,18 @@ const MASTODON_DOMAINS = ['types.pl']; export default { extraDependencies: ['html', 'language'], - data(url, { - type = 'generic', - } = {}) { - const types = ['generic', 'album']; - if (!types.includes(type)) { - throw new TypeError(`Expected type to be one of ${types}`); - } + data(url) { + return {url}; + }, - return { - url, - type, - }; + slots: { + mode: { + validate: v => v.is('generic', 'album'), + default: 'generic', + }, }, - generate(data, {html, language}) { + generate(data, slots, {html, language}) { let isLocal; let domain; try { @@ -50,7 +47,7 @@ export default { ? language.$('misc.external.mastodon.domain', {domain}) : domain.includes('youtu') - ? data.type === 'album' + ? slots.mode === 'album' ? data.url.includes('list=') ? language.$('misc.external.youtube.playlist') : language.$('misc.external.youtube.fullAlbum') -- cgit 1.3.0-6-gf8a5