diff --git a/docs/hexascript/algorithm.html b/docs/hexascript/algorithm.html new file mode 100644 index 0000000..0c914a0 --- /dev/null +++ b/docs/hexascript/algorithm.html @@ -0,0 +1,234 @@ +

Pipeline Algorithm

+ diff --git a/docs/hexascript/config.json b/docs/hexascript/config.json index 8aa8616..1af2a08 100644 --- a/docs/hexascript/config.json +++ b/docs/hexascript/config.json @@ -18,11 +18,11 @@ "label": "Frontend", "submenu": [ { - "mermaid": "diagrams/frontend_logic.html", + "mermaid": "diagrams/frontend_logic", "label": "Frontend Logic" }, { - "mermaid": "diagrams/frontend_classes.html", + "mermaid": "diagrams/frontend_classes", "label": "Classes" } ] @@ -31,11 +31,11 @@ "label": "Backend", "submenu": [ { - "mermaid": "/diagrams/backend_api.html", + "mermaid": "/diagrams/backend_api", "label": "Api" }, { - "mermaid": "/diagrams/backend_db.html", + "mermaid": "/diagrams/backend_db", "label": "Database" } ] diff --git a/docs/hexascript/design_docs.handlebars b/docs/hexascript/design_docs.handlebars new file mode 100644 index 0000000..cf23fc8 --- /dev/null +++ b/docs/hexascript/design_docs.handlebars @@ -0,0 +1,31 @@ +{{!-- hexascript_docs.hbs --}} +
+ {{#if type}} + {{!-- CASE: HTML Injection --}} + {{#if (eq type "html")}} +
+ {{{content}}} +
+ {{/if}} + + {{!-- CASE: Mermaid Diagram Injection --}} + {{#if (eq type "mermaid")}} +
+{{{content}}}
+            
+ {{/if}} + + {{!-- CASE: Iframe Injection --}} + {{#if (eq type "frame")}} +
+ +
+ {{/if}} + {{else}} + {{!-- CASE: No Context (Index Page) --}} +
+

Documentation Index

+

Select a topic from the navigation to begin.

+
+ {{/if}} +
diff --git a/docs/hexascript/html/algorithm.html b/docs/hexascript/html/algorithm.html deleted file mode 100644 index 0c914a0..0000000 --- a/docs/hexascript/html/algorithm.html +++ /dev/null @@ -1,234 +0,0 @@ -

Pipeline Algorithm

- diff --git a/docs/hexascript/src/script.js b/docs/hexascript/src/script.js index c7812cd..3f79199 100644 --- a/docs/hexascript/src/script.js +++ b/docs/hexascript/src/script.js @@ -1,15 +1,17 @@ +const path = require("path"); +const navLinks = require(path.resolve(__dirname, "../config.json")); +const { promises: fs } = require("node:fs"); +const express = require("express"); +const router = express.Router(); +const processMenuLinks = require( + path.join(__dirname, "../../../../src/utils/processMenuLinks"), +); -const navLinks = require("./navLinks.json"); -const fs = require('node:fs'); -const express = require("express") -const router = express.Router() +const { winstonLogger } = require("../../../../src/utils/logging"); -export function htmlController(req, res) {} -export function mermaidController(req, res) {} -export function frameController(req, res) {} - -export function getContext(type, path) { +async function getContext(type, pathPrefix, navLink) { let filePath = null; + let fileName = null; let controllor; let route; switch (type) { @@ -18,58 +20,110 @@ * Injects html directly into the content area *
*/ - filePath = path.join("html", path + ".html"); - controllor = htmlController; - route = `${path}` + fileName = navLink.html; + filePath = path.join(__dirname, "..", "html", fileName + ".html"); + route = `/${fileName}`; break; - case: "mermaid": + case "mermaid": /** * Injects a mermaid file directly into the content area *

        */
-      filePath= path.join("diagrams", path + ".mmd");
-      controllor = mermaidController;
+      fileName = navLink.mermaid;
+      filePath = path.join(__dirname, "..", fileName + ".mmd");
+      route = `/${fileName}`;
     case "frame":
       /**
        * Injects an iframe into the content area
        * 
        */
-      controllor = frameController;
+      fileName = navLink.frame;
+      route = navLink.frame;
+      route = `/${navLink.mermaid}`;
+      break;
+
+    case "submenu":
+      route = null;
       break;
     default:
-      throw new Error(`Invalid option: ${type}`)
+      throw new Error(`Invalid option: ${type}`);
   }
-  if ( filePath != null) {
-   fileContent = await fs.readFile(filePath, 'utf8');
+  let fileContent;
+  try {
+    fileContent = filePath
+      ? Promise.resolve(fs.readFile(filePath, "utf8"))
+      : null;
+  } catch (e) {
+    winstonLogger.error(e.stack);
   }
   return {
-    path, controller
-    ,route: `diagram/${path}`,
-    content: fileContent
-
-  }
+    type,
+    path: filePath,
+    route,
+    content: fileContent,
+  };
 }
-function router() {
-navLinks.forEach((navLink) => {
-  const keys = Object.keys(navLink);
-  keys.forEach( key => {
-
-  // -- Html Injection
-  if (keys.indexOf("html") != -1) {
-    context = getContext("html", path)
-  }
-  // -- Mermaid Diagram Injection
-  if (keys.indexOf("mermaid") != -1) {
-    context = getContext("mermaid", path)
-    const fileContent
-  }
-  // -- Frame Injection
-  if (keys.indexOf("frame") != -1) {
-    context = getContext("frame", path)
-  }
-    router.get(context.path, context.controller)
-
-  })
-  return router
-});
+const templatePath = path.resolve(__dirname, "../design_docs.hbs");
+const rootPath = path.join("..", "..");
+const layoutPath = path.join(rootPath, "src/views/layouts/main.handlebars");
+const hbs = require("hbs");
+function controllor(context) {
+  return (req, res) => {
+    hbs.registerPartials(__dirname);
+    const links = processMenuLinks(navLinks, req.isAuthenticated, req.path);
+    const ctx = {
+      ...res.locals.baseContext,
+      ...context,
+      navLinks: links,
+      layout: "main.handlebars",
+      showSidebar: false,
+    };
+    res.render("design_docs.handlebars", ctx);
+  };
 }
+function generateRouter(links, pathPrefix = "./") {
+  for (const navLink of links) {
+    let context = {};
+    try {
+      // -- Html Injection
+      if (navLink.html) {
+        context = getContext("html", pathPrefix, navLink);
+      }
+      // -- Mermaid Diagram Injection
+      else if (navLink.mermaid) {
+        context = getContext("mermaid", pathPrefix, navLink);
+      }
+      // -- Frame Injection
+      else if (navLink.frame) {
+        context = getContext("frame", pathPrefix, navLink);
+        // winstonLogger.info(context);
+      }
+      // -- Submenu
+      else if (navLink.submenu) {
+        // Loop again
+        generateRouter(navLink.submenu, pathPrefix);
+        // winstonLogger.info(context);
+      } else {
+        throw new Error("No options found", navLink);
+      }
+      let route;
+      winstonLogger.info(
+        "Route: ",
+        context["route"], // If i remove await, the routes only appear in the line above
+        context.route,
+      );
+      if (context.route) {
+        route = path.join(pathPrefix, context.route);
+
+        router.get(route, controllor(context));
+        winstonLogger.info(`Registered Route: ${route}`);
+      }
+    } catch (e) {
+      winstonLogger.error("Context: ", e);
+    }
+  }
+  router.get("/", controllor({}));
+  return router;
+}
+
+module.exports = generateRouter(navLinks);