AETH-erial 5 månader sedan
förälder
incheckning
f047c6b645
5 ändrade filer med 115 tillägg och 2 borttagningar
  1. 49 0
      html/css/custom.css
  2. 9 0
      html/js/slide.js
  3. 21 1
      html/templates/home.html
  4. 35 0
      pkg/controller/cdn_handlers.go
  5. 1 1
      pkg/routes/register.go

+ 49 - 0
html/css/custom.css

@@ -0,0 +1,49 @@
+ /* The side navigation menu */
+ .sidenav {
+    height: 100%; /* 100% Full-height */
+    width: 0; /* 0 width - change this with JavaScript */
+    position: fixed; /* Stay in place */
+    z-index: 1; /* Stay on top */
+    top: 0; /* Stay at the top */
+    left: 0;
+    background-color: #111; /* Black*/
+    overflow-x: hidden; /* Disable horizontal scroll */
+    padding-top: 60px; /* Place content 60px from the top */
+    transition: 0.5s; /* 0.5 second transition effect to slide in the sidenav */
+  }
+  
+  /* The navigation menu links */
+  .sidenav a {
+    padding: 8px 8px 8px 32px;
+    text-decoration: none;
+    font-size: 25px;
+    color: #818181;
+    display: block;
+    transition: 0.3s;
+  }
+  
+  /* When you mouse over the navigation links, change their color */
+  .sidenav a:hover {
+    color: #f1f1f1;
+  }
+  
+  /* Position and style the close button (top right corner) */
+  .sidenav .closebtn {
+    position: absolute;
+    top: 0;
+    right: 25px;
+    font-size: 36px;
+    margin-left: 50px;
+  }
+  
+  /* Style page content - use this if you want to push the page content to the right when you open the side navigation */
+  #main {
+    transition: margin-left .5s;
+    padding: 20px;
+  }
+  
+  /* On smaller screens, where height is less than 450px, change the style of the sidenav (less padding and a smaller font size) */
+  @media screen and (max-height: 450px) {
+    .sidenav {padding-top: 15px;}
+    .sidenav a {font-size: 18px;}
+  } 

+ 9 - 0
html/js/slide.js

@@ -0,0 +1,9 @@
+/* Set the width of the side navigation to 250px */
+function openNav() {
+    document.getElementById("mySidenav").style.width = "250px";
+  }
+
+  /* Set the width of the side navigation to 0 */
+  function closeNav() {
+    document.getElementById("mySidenav").style.width = "0";
+  }

+ 21 - 1
html/templates/home.html

@@ -6,6 +6,7 @@
         <meta name="viewport" content="width=device-width, initial-scale=1">
         <link rel="stylesheet" href="/api/v1/style/bootstrap.min.css">
         <link rel="stylesheet" href="/api/v1/style/mdb/mdb.min.css">
+        <link rel="stylesheet" href="/api/v1/style/custom.css">
     </head>
     <body style="background-color: rgb(56, 56, 56);">
         {{ template "navigation.html" .navigation }}
@@ -18,9 +19,28 @@
             </div>
         {{ end }}
         </div>
+
+        <div id="mySidenav" class="sidenav">
+            <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
+            <a href="#">About</a>
+            <a href="#">Services</a>
+            <a href="#">Clients</a>
+            <a href="#">Contact</a>
+          </div>
+          <!-- Use any element to open the sidenav -->
+          <span onclick="openNav()">open</span>
+
+          <!-- Add all page content inside this div if you want the side nav to push page content to the right (not used if you only want the sidenav to sit on top of the page -->
+          <div id="main">
+            ...
+          </div>
+
+
+
         <script type="text/javascript" src="/api/v1/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
-        <script src="https://unpkg.com/htmx.org@1.9.4"></script> 
+        <script src="https://unpkg.com/htmx.org@1.9.4"></script>
         <script src="https://unpkg.com/htmx.org/dist/ext/json-enc.js"></script>
+        <script src="/api/v1/js/slide.js"></script>
     </body>
 </html>
 {{ end }}

+ 35 - 0
pkg/controller/cdn_handlers.go

@@ -124,3 +124,38 @@ func (c *Controller) ServeImage(ctx *gin.Context) {
 	ctx.Data(200, "image/jpeg", b)
 }
 
+// @Name ServeGeneric
+// @Summary serves file from the html file
+// @Tags cdn
+// @Router /cdn/{file} [get]
+func (c *Controller) ServeGeneric(ctx *gin.Context) {
+	f, exist := ctx.Params.Get("file")
+	if !exist {
+		ctx.JSON(404, map[string]string{
+			"Error": "the requested file could not be found",
+		})
+		return
+	}
+	fext := strings.Split(f, ".")[len()strings.Split(f, ".")-1]
+	var ctype string
+	switch {
+	case fext == "css":
+		ctype = "text/css"
+	case fext == "js":
+		ctype = "text/javascript"
+	case fext == "json":
+		ctype = "application/json"
+	default:
+		ctype = "text"
+	}
+	b, err := os.ReadFile(f)
+	if err != nil {
+		ctx.JSON(500, map[string]string{
+			"Error": "Could not serve the requested file",
+			"msg":   err.Error(),
+		})
+		return
+	}
+	ctx.Data(200, ctype, b)
+}
+

+ 1 - 1
pkg/routes/register.go

@@ -25,7 +25,7 @@ func Register(e *gin.Engine, root string, domain string, redisPort string, redis
 	cdn.GET("/style/mdb/:file", c.ServeMdbCss)
 	cdn.GET("/assets/:file", c.ServeAsset)
 	cdn.GET("/images/:file", c.ServeImage)
-
+	cdn.GET("/cdn/:file", c.ServeGeneric)
 
 
 	priv := e.Group("/admin")