« get me outta code hell

content: *mostly* port linkExternal to language.formatExternalLink - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-11-23 17:42:49 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-11-24 13:45:11 -0400
commitc5e02f9d314118a534fd0e942d87e74864674498 (patch)
treebd47495d4de76d11fdd975df540b63542973f55f /src
parent8f17782a5f2adbafd031b269195879eb7f79e05f (diff)
content: *mostly* port linkExternal to language.formatExternalLink
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/linkExternal.js64
-rw-r--r--src/util/external-links.js17
2 files changed, 15 insertions, 66 deletions
diff --git a/src/content/dependencies/linkExternal.js b/src/content/dependencies/linkExternal.js
index 5de612e2..7f090084 100644
--- a/src/content/dependencies/linkExternal.js
+++ b/src/content/dependencies/linkExternal.js
@@ -1,7 +1,3 @@
-// TODO: Define these as extra dependencies and pass them somewhere
-const BANDCAMP_DOMAINS = ['bc.s3m.us', 'music.solatrux.com'];
-const MASTODON_DOMAINS = ['types.pl'];
-
 export default {
   extraDependencies: ['html', 'language', 'wikiData'],
 
@@ -27,6 +23,13 @@ export default {
   },
 
   generate(data, slots, {html, language}) {
+    return (
+      html.tag('a',
+        {href: data.url, class: 'nowrap'},
+        language.formatExternalLink(data.url, {style: 'platform'})));
+  },
+
+    /*
     let isLocal;
     let domain;
     let pathname;
@@ -49,25 +52,6 @@ export default {
       isLocal = true;
     }
 
-    const link = html.tag('a',
-      {
-        href: data.url,
-        class: 'nowrap',
-      },
-
-      // truly unhinged indentation here
-      isLocal
-        ? language.$('misc.external.local')
-
-    : domain.includes('bandcamp.com')
-        ? language.$('misc.external.bandcamp')
-
-    : BANDCAMP_DOMAINS.includes(domain)
-        ? language.$('misc.external.bandcamp.domain', {domain})
-
-    : MASTODON_DOMAINS.includes(domain)
-        ? language.$('misc.external.mastodon.domain', {domain})
-
     : domain.includes('youtu')
         ? slots.mode === 'album'
           ? data.url.includes('list=')
@@ -75,38 +59,6 @@ export default {
             : language.$('misc.external.youtube.fullAlbum')
           : language.$('misc.external.youtube')
 
-    : domain.includes('soundcloud')
-        ? language.$('misc.external.soundcloud')
-
-    : domain.includes('tumblr.com')
-        ? language.$('misc.external.tumblr')
-
-    : domain.includes('twitter.com')
-        ? language.$('misc.external.twitter')
-
-    : domain.includes('deviantart.com')
-        ? language.$('misc.external.deviantart')
-
-    : domain.includes('wikipedia.org')
-        ? language.$('misc.external.wikipedia')
-
-    : domain.includes('poetryfoundation.org')
-        ? language.$('misc.external.poetryFoundation')
-
-    : domain.includes('instagram.com')
-        ? language.$('misc.external.instagram')
-
-    : domain.includes('patreon.com')
-        ? language.$('misc.external.patreon')
-
-    : domain.includes('spotify.com')
-        ? language.$('misc.external.spotify')
-
-    : domain.includes('newgrounds.com')
-        ? language.$('misc.external.newgrounds')
-
-        : domain);
-
     switch (slots.mode) {
       case 'flash': {
         const wrap = content =>
@@ -136,5 +88,5 @@ export default {
       default:
         return link;
     }
-  }
+    */
 };
diff --git a/src/util/external-links.js b/src/util/external-links.js
index 8e1c3ca9..2047a720 100644
--- a/src/util/external-links.js
+++ b/src/util/external-links.js
@@ -12,6 +12,7 @@ import {
 export const externalLinkStyles = [
   'normal',
   'compact',
+  'platform',
   'icon-id',
 ];
 
@@ -181,16 +182,15 @@ export function getMatchingDescriptorsForExternalLink(url, descriptors) {
 export function getExternalLinkStringsFromDescriptor(url, descriptor, language) {
   const prefix = 'misc.external';
 
-  const results = {
-    'normal': null,
-    'compact': null,
-    'icon-id': null,
-  };
+  const results =
+    Object.fromEntries(externalLinkStyles.map(style => [style, null]));
 
   const {hostname: domain, pathname} = new URL(url);
 
   const place = language.$(prefix, descriptor.string);
 
+  results['platform'] = place;
+
   if (descriptor.icon) {
     results['icon-id'] = descriptor.icon;
   }
@@ -270,11 +270,8 @@ export function getExternalLinkStringsFromDescriptor(url, descriptor, language)
 }
 
 export function getExternalLinkStringsFromDescriptors(url, descriptors, language) {
-  const results = {
-    'normal': null,
-    'compact': null,
-    'icon-id': null,
-  };
+  const results =
+    Object.fromEntries(externalLinkStyles.map(style => [style, null]));
 
   const remainingKeys =
     new Set(Object.keys(results));