template bits

This commit is contained in:
leah 2022-01-27 20:21:09 +00:00
parent be5840ff3a
commit 3dfa497689
5 changed files with 48 additions and 14 deletions

7
.gitignore vendored
View File

@ -16,5 +16,8 @@
# vendor/
# sensitive data that shouldn't be pushed
data/*
config.yml
data/
config.yml
# build bits
resources/build/

30
main.go
View File

@ -2,20 +2,24 @@ package main
import (
"fmt"
"html"
"io/ioutil"
"log"
"net/http"
"text/template"
"gopkg.in/yaml.v3"
)
// Config types
// ------------
type ServerConfig struct {
Name string
Homepage string
}
type AdminConfig struct {
WebRoot string
Port int
LogPath string
}
type AuthConfig struct {
GiteaURL string
@ -39,15 +43,31 @@ func loadConfig() (err error) {
return err
}
func handler(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
var tmpl string
if path == "/" {
tmpl = "templates/home.html"
} else {
tmpl = fmt.Sprintf("templates/%s", path)
}
t, _ := template.ParseFiles(tmpl)
t.Execute(w, config)
}
func main() {
err := loadConfig()
fmt.Print(config)
if err != nil {
log.Fatal("oh no !!!")
log.Fatalf("couldn't load config: %s", err)
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
})
http.Handle("/resources/",
http.StripPrefix("/resources/",
http.FileServer(http.Dir("./resources"))))
http.HandleFunc("/", handler)
err = http.ListenAndServe(":8080", nil)
if err != nil {

View File

@ -1,3 +1,3 @@
body {
color: purple;
}
@tailwind base;
@tailwind components;
@tailwind utilities;

7
tailwind.config.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
content: ["./templates/*.html"],
theme: {
extend: {},
},
plugins: [],
}

View File

@ -1,14 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>{ server.name } Admin Panel</title>
<title>{{.Server.Name}} Admin Panel</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' media='screen' href='main.css'>
<script src='main.js'></script>
<link rel='stylesheet' type='text/css' media='screen' href='/resources/main.css'>
</head>
<body>
<h1 class="text-3xl font-bold underline">
Hello world!
</h1>
</body>
</html>