« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies')
-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