Compare commits
12 Commits
79769661cd
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
1098e39ca0
|
|||
|
73684451b8
|
|||
|
1f6d647e93
|
|||
|
bdd8ceef96
|
|||
|
a4875f0d57
|
|||
|
cf61021c67
|
|||
|
09aa419694
|
|||
|
710fa11b07
|
|||
|
3e59c99b5d
|
|||
|
9b4c53778d
|
|||
|
13f38313ac
|
|||
|
050ff9060e
|
9
Makefile
9
Makefile
@@ -2,12 +2,9 @@ BINARY=kisurun
|
||||
BUILD_DIR=build
|
||||
|
||||
build:
|
||||
@echo "Building $(BINARY)..."
|
||||
go build -o $(BUILD_DIR)/$(BINARY) .
|
||||
@echo "Copying templates and static..."
|
||||
mkdir -p $(BUILD_DIR)/templates
|
||||
mkdir -p $(BUILD_DIR)/static
|
||||
cp -r templates/* $(BUILD_DIR)/templates/
|
||||
cp -r static/* $(BUILD_DIR)/static/
|
||||
cp -r templates $(BUILD_DIR)
|
||||
cp -r pages $(BUILD_DIR)
|
||||
cp -r static $(BUILD_DIR)
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
|
||||
49
main.go
49
main.go
@@ -4,59 +4,30 @@ import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"path/filepath"
|
||||
"os"
|
||||
)
|
||||
|
||||
func getTemplateDir() string {
|
||||
exePath, err := os.Executable()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
exeDir := filepath.Dir(exePath)
|
||||
|
||||
testPath := filepath.Join(exeDir, "templates")
|
||||
if _, err := os.Stat(testPath); err == nil {
|
||||
return testPath
|
||||
}
|
||||
// if running using: go run use wd
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return filepath.Join(wd, "templates")
|
||||
}
|
||||
|
||||
func pageHandler(w http.ResponseWriter, r *http.Request) {
|
||||
path := strings.Trim(r.URL.Path, "/")
|
||||
if path == "" {
|
||||
path = "home"
|
||||
}
|
||||
|
||||
|
||||
templateDir := getTemplateDir()
|
||||
|
||||
tmpl, err := template.ParseFiles(
|
||||
filepath.Join(templateDir, "layout.html"),
|
||||
filepath.Join(templateDir, "header.html"),
|
||||
filepath.Join(templateDir, "footer.html"),
|
||||
filepath.Join(templateDir, path+".html"),
|
||||
)
|
||||
path := r.URL.Path
|
||||
if path == "/" {
|
||||
path = "/home"
|
||||
}
|
||||
t, err := template.Must(template.ParseGlob("templates/*.html")).Clone()
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
err = tmpl.ExecuteTemplate(w, "layout", nil)
|
||||
if err != nil {
|
||||
if _, err := t.ParseFiles(filepath.Join("pages", path+".html")); err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if err := t.ExecuteTemplate(w, "layout", nil); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", pageHandler)
|
||||
|
||||
log.Println("Server running at http://localhost:14888")
|
||||
log.Fatal(http.ListenAndServe(":14888", nil))
|
||||
}
|
||||
|
||||
11
pages/home.html
Normal file
11
pages/home.html
Normal file
@@ -0,0 +1,11 @@
|
||||
{{define "content"}}
|
||||
<h2>
|
||||
My super duper epic site
|
||||
<p class="submissivetext">(contains nothing dont roast me again notbob im just a babeh)</p>
|
||||
</h2>
|
||||
<p>services i host</p>
|
||||
<ul>
|
||||
<li><a href="https://git.kisukalat.xyz/">git server</a></li>
|
||||
<li><a href="https://xmr.kisukalat.xyz/">xmr explorer</a></li>
|
||||
</ul>
|
||||
{{end}}
|
||||
@@ -1,5 +1,5 @@
|
||||
<footer>
|
||||
<ul>
|
||||
<ul style="padding-left: 0;">
|
||||
<li>
|
||||
Monero XMR: <code>44KiSSaf5h7MGd3GqAaNZc45DdwC7q9BmCtsZ9knfsCNj7PyipHfBvBUZVHiBUU8dMJJ82MfPBZdzVugUs7BnANT6SUyDsN</code>
|
||||
</li>
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
{{define "content"}}
|
||||
<h2>
|
||||
My super duper epic site
|
||||
<p class="submissivetext">(contains nothing dont roast me again notbob im just a babeh)</p>
|
||||
</h2>
|
||||
<p></p>
|
||||
{{end}}
|
||||
@@ -2,6 +2,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>{{block "title" .}}Kisukalat.xyz{{end}}</title>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user