« get me outta code hell

content: linkExternal: make direct wrapper for formatExternalLink - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-11-23 21:01:27 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-11-24 13:45:46 -0400
commitface11b98dbaa866055718b7731f61a21fcf9088 (patch)
tree5ed39fc30b90f783fc6a789f90f97f0fce00bf2a
parentba6c4e043b3364481ac3beff1e2a141d1bfcf6fb (diff)
content: linkExternal: make direct wrapper for formatExternalLink
-rw-r--r--src/content/dependencies/linkExternal.js78
1 files changed, 15 insertions, 63 deletions
diff --git a/src/content/dependencies/linkExternal.js b/src/content/dependencies/linkExternal.js
index e51ea89e..4941e48a 100644
--- a/src/content/dependencies/linkExternal.js
+++ b/src/content/dependencies/linkExternal.js
@@ -1,78 +1,30 @@
-import {isExternalLinkContext} from '#external-links';
+import {isExternalLinkContext, isExternalLinkStyle} from '#external-links';
 
 export default {
   extraDependencies: ['html', 'language', 'wikiData'],
 
-  sprawl: ({wikiInfo}) => ({wikiInfo}),
-
-  data(sprawl, url) {
-    const data = {url};
-
-    const {canonicalBase} = sprawl.wikiInfo;
-    if (canonicalBase) {
-      const {hostname: canonicalDomain} = new URL(canonicalBase);
-      Object.assign(data, {canonicalDomain});
-    }
-
-    return data;
-  },
+  data: (url) => ({url}),
 
   slots: {
-    context: {
+    style: {
       // This awkward syntax is because the slot descriptor validator can't
       // differentiate between a function that returns a validator (the usual
       // syntax) and a function that is itself a validator.
+      validate: () => isExternalLinkStyle,
+      default: 'platform',
+    },
+
+    context: {
       validate: () => isExternalLinkContext,
       default: 'generic',
     },
   },
 
-  generate(data, slots, {html, language}) {
-    return (
-      html.tag('a',
-        {href: data.url, class: 'nowrap'},
-        language.formatExternalLink(data.url, {
-          style: 'platform',
-          context: slots.context,
-        })));
-  },
-
-    /*
-    : domain.includes('youtu')
-        ? slots.mode === 'album'
-          ? data.url.includes('list=')
-            ? language.$('misc.external.youtube.playlist')
-            : language.$('misc.external.youtube.fullAlbum')
-          : language.$('misc.external.youtube')
-
-    switch (slots.mode) {
-      case 'flash': {
-        const wrap = content =>
-          html.tag('span', {class: 'nowrap'}, content);
-
-        if (domain.includes('homestuck.com')) {
-          const match = pathname.match(/\/story\/(.*)\/?/);
-          if (match) {
-            if (isNaN(Number(match[1]))) {
-              return wrap(language.$('misc.external.flash.homestuck.secret', {link}));
-            } else {
-              return wrap(language.$('misc.external.flash.homestuck.page', {
-                link,
-                page: match[1],
-              }));
-            }
-          }
-        } else if (domain.includes('bgreco.net')) {
-          return wrap(language.$('misc.external.flash.bgreco', {link}));
-        } else if (domain.includes('youtu')) {
-          return wrap(language.$('misc.external.flash.youtube', {link}));
-        }
-
-        return link;
-      }
-
-      default:
-        return link;
-    }
-    */
+  generate: (data, slots, {html, language}) =>
+    html.tag('a',
+      {href: data.url, class: 'nowrap'},
+      language.formatExternalLink(data.url, {
+        style: slots.style,
+        context: slots.context,
+      })),
 };