Explorar o código

change data/config to yaml

Help-14 %!s(int64=3) %!d(string=hai) anos
pai
achega
21f3b35db1
Modificáronse 7 ficheiros con 135 adicións e 203 borrados
  1. 0 132
      src/common/data.json
  2. 17 0
      src/common/js/core.js
  3. 12 22
      src/main.go
  4. 0 0
      src/sample/config.yaml
  5. 70 0
      src/sample/data.yaml
  6. 20 11
      src/themes/flame/index.html
  7. 16 38
      src/themes/flame/js/magma.js

+ 0 - 132
src/common/data.json

@@ -1,132 +0,0 @@
-[
-    {
-        "title": "Applications",
-        "columns": [
-            {
-                "title": "Servers",
-                "bookmarks": [
-                    {
-                        "icon": "fa-solid fa-wifi",
-                        "title": "OpenWRT",
-                        "url": "https://openwrt.org/"
-                    },
-                    {
-                        "icon": "fa-solid fa-rectangle-xmark",
-                        "title": "Proxmox",
-                        "url": "https://www.proxmox.com/en/"
-                    }
-                ]
-            },
-            {
-                "title": "Servers",
-                "bookmarks": [
-                    {
-                        "icon": "fa-solid fa-wifi",
-                        "title": "OpenWRT",
-                        "url": "https://openwrt.org/"
-                    },
-                    {
-                        "icon": "fa-solid fa-rectangle-xmark",
-                        "title": "Proxmox",
-                        "url": "https://www.proxmox.com/en/"
-                    }
-                ]
-            },
-            {
-                "title": "Servers",
-                "bookmarks": [
-                    {
-                        "icon": "fa-solid fa-wifi",
-                        "title": "OpenWRT",
-                        "url": "https://openwrt.org/"
-                    },
-                    {
-                        "icon": "fa-solid fa-rectangle-xmark",
-                        "title": "Proxmox",
-                        "url": "https://www.proxmox.com/en/"
-                    }
-                ]
-            },
-            {
-                "title": "Servers",
-                "bookmarks": [
-                    {
-                        "icon": "fa-solid fa-wifi",
-                        "title": "OpenWRT",
-                        "url": "https://openwrt.org/"
-                    },
-                    {
-                        "icon": "fa-solid fa-rectangle-xmark",
-                        "title": "Proxmox",
-                        "url": "https://www.proxmox.com/en/"
-                    }
-                ]
-            },
-            {
-                "title": "Servers",
-                "bookmarks": [
-                    {
-                        "icon": "fa-solid fa-wifi",
-                        "title": "OpenWRT",
-                        "url": "https://openwrt.org/"
-                    },
-                    {
-                        "icon": "fa-solid fa-rectangle-xmark",
-                        "title": "Proxmox",
-                        "url": "https://www.proxmox.com/en/"
-                    }
-                ]
-            }
-        ]
-    },
-    {
-        "title": "Bookmarks",
-        "bookmarks": [
-            {
-                "icon": "fa-solid fa-wifi",
-                "title": "OpenWRT",
-                "url": "https://openwrt.org/"
-            },
-            {
-                "icon": "fa-solid fa-rectangle-xmark",
-                "title": "Proxmox",
-                "url": "https://www.proxmox.com/en/"
-            },
-            {
-                "icon": "fa-solid fa-wifi",
-                "title": "OpenWRT",
-                "url": "https://openwrt.org/"
-            },
-            {
-                "icon": "fa-solid fa-rectangle-xmark",
-                "title": "Proxmox",
-                "url": "https://www.proxmox.com/en/"
-            },
-            {
-                "icon": "fa-solid fa-wifi",
-                "title": "OpenWRT",
-                "url": "https://openwrt.org/"
-            },
-            {
-                "icon": "fa-solid fa-rectangle-xmark",
-                "title": "Proxmox",
-                "url": "https://www.proxmox.com/en/"
-            },
-            {
-                "icon": "fa-solid fa-wifi",
-                "title": "OpenWRT",
-                "url": "https://openwrt.org/"
-            },
-            {
-                "icon": "fa-solid fa-rectangle-xmark",
-                "title": "Proxmox",
-                "url": "https://www.proxmox.com/en/"
-            },
-            {
-                "icon": "fa-solid fa-rectangle-xmark",
-                "title": "Proxmox",
-                "url": "https://www.proxmox.com/en/"
-            }
-        ]
-    }
-]

+ 17 - 0
src/common/js/core.js

@@ -0,0 +1,17 @@
+
+function loadCSS() {
+    for (let c = 0; c < document.styleSheets.length; c++) {
+        var declaration = document.styleSheets[c].cssRules[0];
+        if (declaration.selectorText === ":root") {
+            var allVar = declaration.style.cssText.split(";");
+            var cssRootKeys = {}
+            for (var i = 0; i < allVar.length; i++) {
+                var a = allVar[i].split(':');
+                if (a[0] !== "")
+                    cssRootKeys[a[0].trim()] = a[1].trim();
+            }
+            window.cssRoot = cssRootKeys;
+            return;
+        }
+    }
+}

+ 12 - 22
src/main.go

@@ -9,46 +9,36 @@ import (
 	"github.com/help-14/magma/modules"
 	"github.com/help-14/magma/modules"
 )
 )
 
 
+var appConfig modules.Config
+
 func main() {
 func main() {
-	appConfig := modules.LoadConfig()
+	appConfig = modules.LoadConfig()
 
 
 	commonfs := http.FileServer(http.Dir("./common"))
 	commonfs := http.FileServer(http.Dir("./common"))
 	http.Handle("/common/", http.StripPrefix("/common/", commonfs))
 	http.Handle("/common/", http.StripPrefix("/common/", commonfs))
 
 
+	languagefs := http.FileServer(http.Dir("./languages"))
+	http.Handle("/languages/", http.StripPrefix("/languages/", languagefs))
+
 	themePath := "/themes/" + appConfig.Website.Theme + "/"
 	themePath := "/themes/" + appConfig.Website.Theme + "/"
 	themefs := http.FileServer(http.Dir("." + themePath))
 	themefs := http.FileServer(http.Dir("." + themePath))
 	http.Handle("/theme/", http.StripPrefix("/theme/", themefs))
 	http.Handle("/theme/", http.StripPrefix("/theme/", themefs))
 
 
 	http.HandleFunc("/", serveTemplate)
 	http.HandleFunc("/", serveTemplate)
-	// tempPath := filepath.Join(".", "temp")
-	// err := os.MkdirAll(tempPath, os.ModePerm)
-	// if err != nil {
-	// 	log.Fatal(err)
-	// 	return
-	// }
-
-	log.Println("Listening on :7001 ...")
+
+	log.Println("Listening on http://localhost:7001 ...")
 	err := http.ListenAndServe(":7001", nil)
 	err := http.ListenAndServe(":7001", nil)
 	if err != nil {
 	if err != nil {
 		log.Fatal(err)
 		log.Fatal(err)
 	}
 	}
 }
 }
 
 
-// func TemplatedHandler(response http.ResponseWriter, request *http.Request) {
-// 	tmplt := template.New("hello template")
-// 	tmplt, _ = tmplt.Parse("Top Student: {{.Id}} - {{.Name}}!")
-
-// 	p := Student{Id: 1, Name: "Aisha"} //define an instance with required field
-
-// 	tmplt.Execute(response, p) //merge template ‘t’ with content of ‘p’
-// }
-
 func serveTemplate(w http.ResponseWriter, r *http.Request) {
 func serveTemplate(w http.ResponseWriter, r *http.Request) {
-	lp := filepath.Join("templates", "layout.html")
-	//fp := filepath.Join("templates", filepath.Clean(r.URL.Path))
-
+	lp := filepath.Join("themes", appConfig.Website.Theme, "index.html")
 	tmpl, _ := template.ParseFiles(lp)
 	tmpl, _ := template.ParseFiles(lp)
-	tmpl.Execute(w, nil)
+	tmpl.Execute(w, struct {
+		Config modules.WebsiteConfig
+	}{appConfig.Website})
 }
 }
 
 
 // templ.Execute(file, struct {
 // templ.Execute(file, struct {

+ 0 - 0
src/common/config.yaml → src/sample/config.yaml


+ 70 - 0
src/sample/data.yaml

@@ -0,0 +1,70 @@
+data:
+  - title: Applications
+    columns:
+      - title: Servers
+        bookmarks:
+          - name: OpenWRT
+            icon: fa-solid fa-wifi
+            url: https://openwrt.org
+          - name: Proxmox
+            icon: fa-solid fa-rectangle-xmark
+            url: https://www.proxmox.com/en/
+          - name: Home Assistant
+            icon: fa-solid fa-house
+            url: https://www.home-assistant.io
+          - name: Docker
+            icon: fa-brands fa-docker
+            url: https://www.docker.com
+      - title: Nas
+        bookmarks:
+          - name: TrueNas
+            icon: fa-solid fa-server
+            url: https://www.truenas.com
+          - name: Kerberos
+            icon: fa-solid fa-camera-web
+            url: https://kerberos.io
+          - name: jDownloader
+            icon: fa-solid fa-cloud-arrow-down
+            url: https://jdownloader.org
+      - title: Monitoring
+        bookmarks:
+          - name: Grafana
+            icon: fa-solid fa-server
+            url: https://grafana.com
+          - name: InfluxDb
+            icon: fa-solid fa-database
+            url: https://www.influxdata.com
+      - title: Tools
+        bookmarks:
+          - name: Bitwarden
+            icon: fa-solid fa-shield-halved
+            url: https://bitwarden.com
+  - title: Bookmarks
+    columns:
+      - title: Social Media
+        bookmarks:
+          - name: Facebook
+            icon: fa-brands fa-facebook
+            url: https://www.facebook.com
+          - name: Reddit
+            icon: fa-brands fa-reddit
+            url: https://www.reddit.com
+          - name: Voz
+            icon: fa-solid fa-circle-v
+            url: https://voz.vn
+          - name: Youtube
+            icon: fa-brands fa-youtube
+            url: https://www.youtube.com
+      - title: Shopping
+        bookmarks:
+          - name: Shopee
+            icon: fa-solid fa-bag-shopping
+            url: https://shopee.vn
+          - name: Lazada
+            icon: fa-solid fa-heart-half-stroke
+            url: https://www.lazada.com
+      - title: Tools
+        bookmarks:
+          - name: Maps
+            icon: fa-solid fa-map
+            url: https://www.google.com/maps

+ 20 - 11
src/themes/flame/index.html

@@ -6,15 +6,15 @@
     <title></title>
     <title></title>
     <meta name="description" content="" />
     <meta name="description" content="" />
     <meta name="viewport" content="width=device-width, initial-scale=1">
     <meta name="viewport" content="width=device-width, initial-scale=1">
-    <link rel="icon" type="image/png" href="assets/favicon.ico" />
-    <link rel="stylesheet" href="css/font.css">
-    <link rel="stylesheet" href="css/normalize.min.css">
-    <link rel="stylesheet" href="css/skeleton.min.css">
+    <link rel="icon" type="image/png" href="common/assets/favicon.ico" />
+    <link rel="stylesheet" href="theme/css/font.css">
+    <link rel="stylesheet" href="theme/css/normalize.min.css">
+    <link rel="stylesheet" href="theme/css/skeleton.min.css">
     <!-- <link rel="stylesheet" href="css/charts.min.css"> -->
     <!-- <link rel="stylesheet" href="css/charts.min.css"> -->
-    <link rel="stylesheet" href="css/all.min.css">
-    <link rel="stylesheet" href="css/core.css">
-    <link rel="stylesheet" href="css/magma.css">
-    <link rel="stylesheet" href="css/custom.css">
+    <link rel="stylesheet" href="theme/css/all.min.css">
+    <link rel="stylesheet" href="common/css/core.css">
+    <link rel="stylesheet" href="theme/css/magma.css">
+    <link rel="stylesheet" href="common/css/custom.css">
 </head>
 </head>
 
 
 <body>
 <body>
@@ -46,9 +46,18 @@
         <div id="footer" class="row"></div>
         <div id="footer" class="row"></div>
     </div>
     </div>
 
 
-    <script src="js/skycons.min.js"></script>
-    <script src="js/magma.js"></script>
-    <script src="js/custom.js"></script>
+    <script>
+        window.config = {
+            localization: {{ .Config.Localization }},
+            language: {{ .Config.Language }},
+            useMetric: {{ .Config.UseMetric }}
+        };
+    </script>
+
+    <script src="theme/js/skycons.min.js"></script>
+    <script src="common/js/core.js"></script>
+    <script src="theme/js/magma.js"></script>
+    <script src="common/js/custom.js"></script>
 </body>
 </body>
 
 
 </html>
 </html>

+ 16 - 38
src/themes/flame/js/magma.js

@@ -1,22 +1,24 @@
-async function loadConfig() {
-    window.config = await (await fetch("./config.json")).json();
-    // Set website language
-    document.documentElement.setAttribute("lang", window.config.website.language);
-    // Set website title
-    document.title = window.config.website.title;
-    // Set website description
-    document.querySelector('meta[name="description"]').setAttribute("content", window.config.website.description);
-}
+// async function loadConfig() {
+//     window.config = await (await fetch("./common/config.json")).json();
+//     // Set website language
+//     document.documentElement.setAttribute("lang", window.config.website.language);
+//     // Set website title
+//     document.title = window.config.website.title;
+//     // Set website description
+//     document.querySelector('meta[name="description"]').setAttribute("content", window.config.website.description);
+// }
 
 
 async function loadLanguage() {
 async function loadLanguage() {
     try {
     try {
-        window.language = await (await fetch(`./${window.config.website.language}.json`)).json();
+        window.language = await (await fetch(`./languages/${window.config.language}.json`)).json();
     } catch {
     } catch {
-        window.language = await (await fetch(`./en.json`)).json();
+        console.error("Language file not found");
+        window.language = await (await fetch(`./languages/en.json`)).json();
     }
     }
 }
 }
 
 
 async function loadWeather() {
 async function loadWeather() {
+    return;
     // Get info from api
     // Get info from api
     const weather = await (await fetch("./weather")).json();
     const weather = await (await fetch("./weather")).json();
     // Parse weather id
     // Parse weather id
@@ -52,7 +54,7 @@ async function loadWeather() {
     var skycons = new Skycons({ "color": window.cssRoot["--accentColor"] });
     var skycons = new Skycons({ "color": window.cssRoot["--accentColor"] });
     skycons.add("weather-icon", icon);
     skycons.add("weather-icon", icon);
     // Set weather info
     // Set weather info
-    if (window.config.website.useMetric) {
+    if (window.config.useMetric) {
         document.querySelector("#temp").innerText = Math.floor(weather.main.temp - 273.15) + "°C";
         document.querySelector("#temp").innerText = Math.floor(weather.main.temp - 273.15) + "°C";
     } else {
     } else {
         document.querySelector("#temp").innerText = Math.floor((weather.main.temp - 32) * 5 / 9) + "°F";
         document.querySelector("#temp").innerText = Math.floor((weather.main.temp - 32) * 5 / 9) + "°F";
@@ -62,7 +64,7 @@ async function loadWeather() {
 }
 }
 
 
 async function loadBookmarks() {
 async function loadBookmarks() {
-    const data = await (await fetch("./data.json")).json();
+    const data = await (await fetch("./common/data.json")).json();
     let contentHtml = "";
     let contentHtml = "";
 
 
     function splitToChunks(arr) {
     function splitToChunks(arr) {
@@ -129,29 +131,12 @@ async function loadBookmarks() {
     document.querySelector("#content").innerHTML = contentHtml;
     document.querySelector("#content").innerHTML = contentHtml;
 }
 }
 
 
-function loadCSS() {
-    for (let c = 0; c < document.styleSheets.length; c++) {
-        var declaration = document.styleSheets[c].cssRules[0];
-        if (declaration.selectorText === ":root") {
-            var allVar = declaration.style.cssText.split(";");
-            var cssRootKeys = {}
-            for (var i = 0; i < allVar.length; i++) {
-                var a = allVar[i].split(':');
-                if (a[0] !== "")
-                    cssRootKeys[a[0].trim()] = a[1].trim();
-            }
-            window.cssRoot = cssRootKeys;
-            return;
-        }
-    }
-}
-
 function setClock() {
 function setClock() {
     //Set clock
     //Set clock
     const clock = document.querySelector("#clock");
     const clock = document.querySelector("#clock");
     const clockOptions = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric' };
     const clockOptions = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric' };
     (function clockTick() {
     (function clockTick() {
-        clock.innerText = new Date().toLocaleTimeString(window.config.website.localization, clockOptions);
+        clock.innerText = new Date().toLocaleTimeString(window.config.localization, clockOptions);
         setTimeout(clockTick, 2000);
         setTimeout(clockTick, 2000);
     })();
     })();
     //Set greeting
     //Set greeting
@@ -172,17 +157,10 @@ function setClock() {
 }
 }
 
 
 async function startWebsite() {
 async function startWebsite() {
-    // Load bookmarks
     loadBookmarks();
     loadBookmarks();
-    // Load config
-    await loadConfig();
-    // Load language
     await loadLanguage();
     await loadLanguage();
-    // Set Clock
     setClock();
     setClock();
-    // Get CSS varriables
     loadCSS();
     loadCSS();
-    // Set weather
     loadWeather();
     loadWeather();
 }
 }
 startWebsite();
 startWebsite();