Change homepage to dark mode

This commit is contained in:
Melon 2022-04-21 09:06:14 +01:00
parent ea80ac0b6a
commit 5c1af23f65
Signed by: melon
GPG Key ID: B0ADD5395BCDAAB6
2 changed files with 48 additions and 2 deletions

View File

@ -4,12 +4,14 @@ import (
"code.mrmelon54.xyz/sean/melon-tools/module/discord" "code.mrmelon54.xyz/sean/melon-tools/module/discord"
"code.mrmelon54.xyz/sean/melon-tools/module/gitea" "code.mrmelon54.xyz/sean/melon-tools/module/gitea"
"code.mrmelon54.xyz/sean/melon-tools/utils" "code.mrmelon54.xyz/sean/melon-tools/utils"
_ "embed"
"encoding/gob" "encoding/gob"
"fmt" "fmt"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"html/template"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -22,6 +24,9 @@ var (
discord.New(), discord.New(),
} }
sessionStore = sessions.NewCookieStore([]byte(os.Getenv("SESSION_KEY"))) sessionStore = sessions.NewCookieStore([]byte(os.Getenv("SESSION_KEY")))
//go:embed pages/index.go.html
indexTemplate string
) )
func main() { func main() {
@ -37,9 +42,25 @@ func main() {
router.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) { router.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
rw.Header().Set("Content-Type", "text/html") rw.Header().Set("Content-Type", "text/html")
rw.WriteHeader(http.StatusOK) rw.WriteHeader(http.StatusOK)
_, _ = rw.Write([]byte("Melon Tools<br/>\n"))
modTmp := make([]template.HTML, 0)
for _, v := range modules { for _, v := range modules {
_, _ = rw.Write([]byte(fmt.Sprintf("<a href=\"%s\">%s</a><br/>\n", v.GetEndpoint(), v.GetName()))) modTmp = append(modTmp, template.HTML(fmt.Sprintf("<a href=\"%s\">%s</a>", v.GetEndpoint(), v.GetName())))
}
tmp, err := template.New("homepage").Parse(indexTemplate)
if err != nil {
fmt.Println("Template parse error:", err)
return
}
err = tmp.Execute(rw, struct {
Modules []template.HTML
}{
Modules: modTmp,
})
if err != nil {
fmt.Println("Template execute error:", err)
return
} }
}) })

View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Melon Tools</title>
<style>
html, body {
background-color: #2a2c2d;
color: #d8d4d0;
}
a {
color: #4699fa;
}
</style>
</head>
<body>
<h1>Melon Tools</h1>
<ul>
{{range .Modules}}
<li>{{.}}</li>
{{end}}
</ul>
</body>
</html>