« get me outta code hell

linkExternal: add content slot - 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>2024-03-01 07:38:54 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-03-31 19:08:09 -0300
commitf500eb7b8cc8b17785dd098934505bfcbca4e98f (patch)
treef44d3ae87c2bdf0de3d5ca1e439756986ec88bcc
parentc8d728e1eda094ac570f34b67004d100b2596ecb (diff)
linkExternal: add content slot
There's not necessarily a use for linkExternal with content slot
on its own as of this commit, compared to a normal html.tag('a'),
because linkExternal basically just wraps formatExternalLink and
the content slot opts out of using that. But this does allow this
component to be used in places now... and extended upon... later!
-rw-r--r--src/content/dependencies/linkExternal.js18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/content/dependencies/linkExternal.js b/src/content/dependencies/linkExternal.js
index 9469a9e9..2de1bc70 100644
--- a/src/content/dependencies/linkExternal.js
+++ b/src/content/dependencies/linkExternal.js
@@ -6,6 +6,11 @@ export default {
   data: (url) => ({url}),
 
   slots: {
+    content: {
+      type: 'html',
+      mutable: false,
+    },
+
     style: {
       // This awkward syntax is because the slot descriptor validator can't
       // differentiate between a function that returns a validator (the usual
@@ -27,12 +32,15 @@ export default {
 
   generate(data, slots, {html, language}) {
     const linkAttributes = html.attributes();
+    let linkContent = slots.content;
 
-    let linkContent =
-      language.formatExternalLink(data.url, {
-        style: slots.style,
-        context: slots.context,
-      });
+    if (html.isBlank(linkContent)) {
+      linkContent =
+        language.formatExternalLink(data.url, {
+          style: slots.style,
+          context: slots.context,
+        });
+    }
 
     // Fall back to platform if nothing matched the desired style.
     if (html.isBlank(linkContent) && slots.style !== 'platform') {