change data/config to yaml
This commit is contained in:
parent
2bbab83d99
commit
21f3b35db1
7 changed files with 134 additions and 202 deletions
|
@ -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
src/common/js/core.js
Normal file
17
src/common/js/core.js
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
32
src/main.go
32
src/main.go
|
@ -9,46 +9,36 @@ import (
|
|||
"github.com/help-14/magma/modules"
|
||||
)
|
||||
|
||||
var appConfig modules.Config
|
||||
|
||||
func main() {
|
||||
appConfig := modules.LoadConfig()
|
||||
appConfig = modules.LoadConfig()
|
||||
|
||||
commonfs := http.FileServer(http.Dir("./common"))
|
||||
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 + "/"
|
||||
themefs := http.FileServer(http.Dir("." + themePath))
|
||||
http.Handle("/theme/", http.StripPrefix("/theme/", themefs))
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
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) {
|
||||
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.Execute(w, nil)
|
||||
tmpl.Execute(w, struct {
|
||||
Config modules.WebsiteConfig
|
||||
}{appConfig.Website})
|
||||
}
|
||||
|
||||
// templ.Execute(file, struct {
|
||||
|
|
70
src/sample/data.yaml
Normal file
70
src/sample/data.yaml
Normal file
|
@ -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
|
|
@ -6,15 +6,15 @@
|
|||
<title></title>
|
||||
<meta name="description" content="" />
|
||||
<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/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>
|
||||
|
||||
<body>
|
||||
|
@ -46,9 +46,18 @@
|
|||
<div id="footer" class="row"></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>
|
||||
|
||||
</html>
|
|
@ -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() {
|
||||
try {
|
||||
window.language = await (await fetch(`./${window.config.website.language}.json`)).json();
|
||||
window.language = await (await fetch(`./languages/${window.config.language}.json`)).json();
|
||||
} 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() {
|
||||
return;
|
||||
// Get info from api
|
||||
const weather = await (await fetch("./weather")).json();
|
||||
// Parse weather id
|
||||
|
@ -52,7 +54,7 @@ async function loadWeather() {
|
|||
var skycons = new Skycons({ "color": window.cssRoot["--accentColor"] });
|
||||
skycons.add("weather-icon", icon);
|
||||
// Set weather info
|
||||
if (window.config.website.useMetric) {
|
||||
if (window.config.useMetric) {
|
||||
document.querySelector("#temp").innerText = Math.floor(weather.main.temp - 273.15) + "°C";
|
||||
} else {
|
||||
document.querySelector("#temp").innerText = Math.floor((weather.main.temp - 32) * 5 / 9) + "°F";
|
||||
|
@ -62,7 +64,7 @@ async function loadWeather() {
|
|||
}
|
||||
|
||||
async function loadBookmarks() {
|
||||
const data = await (await fetch("./data.json")).json();
|
||||
const data = await (await fetch("./common/data.json")).json();
|
||||
let contentHtml = "";
|
||||
|
||||
function splitToChunks(arr) {
|
||||
|
@ -129,29 +131,12 @@ async function loadBookmarks() {
|
|||
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() {
|
||||
//Set clock
|
||||
const clock = document.querySelector("#clock");
|
||||
const clockOptions = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric' };
|
||||
(function clockTick() {
|
||||
clock.innerText = new Date().toLocaleTimeString(window.config.website.localization, clockOptions);
|
||||
clock.innerText = new Date().toLocaleTimeString(window.config.localization, clockOptions);
|
||||
setTimeout(clockTick, 2000);
|
||||
})();
|
||||
//Set greeting
|
||||
|
@ -172,17 +157,10 @@ function setClock() {
|
|||
}
|
||||
|
||||
async function startWebsite() {
|
||||
// Load bookmarks
|
||||
loadBookmarks();
|
||||
// Load config
|
||||
await loadConfig();
|
||||
// Load language
|
||||
await loadLanguage();
|
||||
// Set Clock
|
||||
setClock();
|
||||
// Get CSS varriables
|
||||
loadCSS();
|
||||
// Set weather
|
||||
loadWeather();
|
||||
}
|
||||
startWebsite();
|
Loading…
Add table
Reference in a new issue