« get me outta code hell

external-links: factor out getCompactDomain - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-03-29 16:38:25 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-03-29 20:10:12 -0300
commite52468280288daee71806c3e12028772dd60dbb6 (patch)
tree06f7a4d4d79a65fb4372c86dc95692ecf1f2a54d /src/util
parent3be13ce9e8145ee0ae4c626978f6b6c0deabf16e (diff)
external-links: factor out getCompactDomain
Diffstat (limited to 'src/util')
-rw-r--r--src/util/external-links.js18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/util/external-links.js b/src/util/external-links.js
index f63b924..0c6e9d5 100644
--- a/src/util/external-links.js
+++ b/src/util/external-links.js
@@ -612,6 +612,16 @@ export function getExternalLinkStringOfStyleFromDescriptor(url, style, descripto
     return urlParts(url).domain;
   }
 
+  function getCompactDomain() {
+    const domain = getDomain();
+
+    if (!domain) {
+      return null;
+    }
+
+    return language.sanitize(domain.replace(/^www\./, ''));
+  }
+
   function getCustom() {
     if (!descriptor.custom) {
       return null;
@@ -679,13 +689,7 @@ export function getExternalLinkStringOfStyleFromDescriptor(url, style, descripto
     }
 
     if (descriptor.compact === 'domain') {
-      const domain = getDomain();
-
-      if (!domain) {
-        return null;
-      }
-
-      return language.sanitize(domain.replace(/^www\./, ''));
+      return getCompactDomain();
     }
 
     if (descriptor.compact === 'handle') {