« get me outta code hell

content: transformContent: basic external-link node support - 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>2024-03-01 07:47:49 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-03-31 19:08:10 -0300
commitb4a50b6bd41c35119572834ae39bc9f36eb5361c (patch)
tree33762d1b7ba9667af2fb55a241478ff27e259494 /src
parent5e35287e919741d21d273ec15d98445e23f24f63 (diff)
content: transformContent: basic external-link node support
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/transformContent.js23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js
index b981a3f8..d7b57ffd 100644
--- a/src/content/dependencies/transformContent.js
+++ b/src/content/dependencies/transformContent.js
@@ -37,6 +37,7 @@ export default {
         .map(description => description.link)
         .filter(Boolean)),
     'image',
+    'linkExternal',
   ],
 
   extraDependencies: ['html', 'language', 'to', 'wikiData'],
@@ -187,6 +188,15 @@ export default {
             }
           }),
 
+      externalLinks:
+        nodes
+          .filter(({type}) => type === 'external-link')
+          .map(node => {
+            const {href} = node.data;
+
+            return relation('linkExternal', href);
+          }),
+
       images:
         nodes
           .filter(({type}) => type === 'image')
@@ -215,6 +225,7 @@ export default {
   generate(data, relations, slots, {html, language, to}) {
     let imageIndex = 0;
     let internalLinkIndex = 0;
+    let externalLinkIndex = 0;
 
     const contentFromNodes =
       data.nodes.map(node => {
@@ -327,6 +338,15 @@ export default {
             return {type: 'processed-internal-link', data: link};
           }
 
+          case 'external-link': {
+            const {label} = node.data;
+            const externalLink = relations.externalLinks[externalLinkIndex++];
+
+            externalLink.setSlot('content', label);
+
+            return {type: 'processed-external-link', data: externalLink};
+          }
+
           case 'tag': {
             const {replacerKey, replacerValue} = node.data;
 
@@ -362,7 +382,8 @@ export default {
     if (slots.mode === 'single-link') {
       const link =
         contentFromNodes.find(node =>
-          node.type === 'processed-internal-link');
+          node.type === 'processed-internal-link' ||
+          node.type === 'processed-external-link');
 
       if (!link) {
         return html.blank();