« get me outta code hell

content: transformContent: use switch/case in node -> content - 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-07-30 18:02:30 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-07-30 18:02:30 -0300
commit093d425a02ff144a0f5c6475eadc537d7fd1f041 (patch)
treeab0ea2ed4e374f350c2144b30b466978dc6d5ecd /src
parent2d5e22df4b418d96a88afb4589ac326fb77b6e7a (diff)
content: transformContent: use switch/case in node -> content
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/transformContent.js78
1 files changed, 40 insertions, 38 deletions
diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js
index 03bd7bcc..75cb4847 100644
--- a/src/content/dependencies/transformContent.js
+++ b/src/content/dependencies/transformContent.js
@@ -208,55 +208,57 @@ export default {
     // individual nodes).
     const contentFromNodes =
       data.nodes.map(node => {
-        if (node.type === 'text') {
-          return {type: 'text', data: node.data};
-        }
+        switch (node.type) {
+          case 'text':
+            return {type: 'text', data: node.data};
+
+          case 'link': {
+            const linkNode = relations.links[linkIndex++];
+            if (linkNode.type === 'text') {
+              return {type: 'text', data: linkNode.data};
+            }
 
-        if (node.type === 'link') {
-          const linkNode = relations.links[linkIndex++];
-          if (linkNode.type === 'text') {
-            return {type: 'text', data: linkNode.data};
+            const {link, label, hash, toIndex} = linkNode;
+
+            return {
+              type: 'link',
+              data:
+                (toIndex
+                  ? link.slots({content: label, hash})
+                  : link.slots({
+                      content: label, hash,
+                      preferShortName: slots.preferShortLinkNames,
+                    })),
+            };
           }
 
-          const {link, label, hash, toIndex} = linkNode;
-
-          return {
-            type: 'link',
-            data:
-              (toIndex
-                ? link.slots({content: label, hash})
-                : link.slots({
-                    content: label, hash,
-                    preferShortName: slots.preferShortLinkNames,
-                  })),
-          };
-        }
+          case 'tag': {
+            const {replacerKey, replacerValue} = node.data;
 
-        if (node.type === 'tag') {
-          const {replacerKey, replacerValue} = node.data;
+            const spec = replacerSpec[replacerKey];
 
-          const spec = replacerSpec[replacerKey];
+            if (!spec) {
+              return getPlaceholder(node, data.content);
+            }
 
-          if (!spec) {
-            return getPlaceholder(node, data.content);
-          }
+            const {value: valueFn, html: htmlFn} = spec;
 
-          const {value: valueFn, html: htmlFn} = spec;
+            const value =
+              (valueFn
+                ? valueFn(replacerValue)
+                : replacerValue);
 
-          const value =
-            (valueFn
-              ? valueFn(replacerValue)
-              : replacerValue);
+            const contents =
+              (htmlFn
+                ? htmlFn(value, {html, language})
+                : value);
 
-          const contents =
-            (htmlFn
-              ? htmlFn(value, {html, language})
-              : value);
+            return {type: 'text', data: contents};
+          }
 
-          return {type: 'text', data: contents};
+          default:
+            return getPlaceholder(node, data.content);
         }
-
-        return getPlaceholder(node, data.content);
       });
 
     // In single-link mode, return the link node exactly as is - exposing