Browse Source

Wire the js build into tasks and use the generated JavaScript

Getty Ritter 1 year ago
parent
commit
717f062d26
2 changed files with 9 additions and 17 deletions
  1. 1 17
      static/index.html
  2. 8 0
      tasks.py

+ 1 - 17
static/index.html

@@ -2,25 +2,9 @@
 <html>
   <head>
     <title>Baba Yaga</title>
-    <script src="/static/jquery-3.5.0.min.js"></script>
   </head>
   <body>
     <div id="root"></div>
-    <script type="application/javascript">
-     function renderPage() {
-       if (!window.location.hash) {
-         window.location.hash = "#index";
-       }
-       const currentPage = window.location.hash.substring(1);
-       const req = new XMLHttpRequest();
-       req.addEventListener("load", function () {
-         $("#root").html(JSON.parse(this.responseText).rendered);
-       });
-       req.open("GET", `/p/${currentPage}`);
-       req.setRequestHeader("Accept", "application/json");
-       req.send();
-     }
-     renderPage();
-    </script>
+    <script src="/static/by.js"></script>
   </body>
 </html>

+ 8 - 0
tasks.py

@@ -2,6 +2,13 @@ from invoke import task
 
 
 @task
+def js(c):
+    """Build our JavaScript"""
+    c.run("yarn install")
+    c.run("yarn build")
+
+
+@task(js)
 def run(c, port=8080, host="127.0.0.1"):
     """Run a debug server locally"""
     c.run(
@@ -13,6 +20,7 @@ def run(c, port=8080, host="127.0.0.1"):
     )
 
 
+
 @task
 def install(c):
     """Install the listed dependencies into a virtualenv"""