From 7d3169246f31234c2f182480b281f9fa93d0c431 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 29 Mar 2024 19:06:24 -0300 Subject: external-links: unusualDomain on descriptors --- src/util/external-links.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/util') diff --git a/src/util/external-links.js b/src/util/external-links.js index 585e28aa..e19ecbfc 100644 --- a/src/util/external-links.js +++ b/src/util/external-links.js @@ -3,6 +3,7 @@ import {empty, stitchArrays, withEntries} from '#sugar'; import { anyOf, is, + isBoolean, isObject, isStringNonEmpty, looseArrayOf, @@ -99,6 +100,8 @@ export const isExternalLinkSpec = substring: isStringNonEmpty, }))), + unusualDomain: optional(isBoolean), + icon: optional(isStringNonEmpty), })); @@ -263,6 +266,7 @@ export const externalLinkSpec = [ platform: 'bandcamp', handle: {domain: /.+/}, + unusualDomain: true, icon: 'bandcamp', }, @@ -416,6 +420,7 @@ export const externalLinkSpec = [ platform: 'mastodon', handle: {domain: /.+/}, + unusualDomain: true, icon: 'mastodon', }, @@ -705,20 +710,24 @@ export function getExternalLinkStringOfStyleFromDescriptor(url, style, descripto switch (style) { case 'platform': { + const platform = language.$(prefix, descriptor.platform); + const domain = urlParts(url).domain; + if (descriptor === fallbackDescriptor) { // The fallback descriptor has a "platform" which is just // the word "External". This isn't really useful when you're // looking for platform info! - const domain = urlParts(url).domain; if (domain) { return language.sanitize(domain.replace(/^www\./, '')); } else { - return language.$(prefix, descriptor.platform); + return platform; } } else if (descriptor.detail) { return getDetail(); + } else if (descriptor.unusualDomain && domain) { + return language.$(prefix, 'withDomain', {platform, domain}); } else { - return language.$(prefix, descriptor.platform); + return platform; } } -- cgit 1.3.0-6-gf8a5