diff --git a/.gitignore b/.gitignore index f4a37a5..8586097 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,7 @@ -# ---> Go -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib - # Test binary, build with `go test -c` *.test -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - *.jpg *.png -*.woff \ No newline at end of file +*.woff +cmd/phga.de/phga.de diff --git a/build/app/Dockerfile b/build/app/Dockerfile new file mode 100644 index 0000000..9450438 --- /dev/null +++ b/build/app/Dockerfile @@ -0,0 +1,7 @@ +FROM golang:1.16.2 + +ENV GO111MODULE=off +RUN go get -u -d g.phga.de/phga/phga.de/... +WORKDIR /go/src/g.phga.de/phga/phga.de/cmd/phga.de +RUN go build +CMD ["./phga.de"] diff --git a/build/docker-compose.yml b/build/docker-compose.yml new file mode 100644 index 0000000..3d23c72 --- /dev/null +++ b/build/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3' + +services: + tt: + build: + context: ./app + dockerfile: Dockerfile + restart: always + ports: + - 8099:8080 + volumes: + - /srv/phga.de/web/data:/go/src/g.phga.de/phga/phga.de/web/data + - /srv/phga.de/web/static/fonts:/go/src/g.phga.de/phga/phga.de/web/static/fonts \ No newline at end of file diff --git a/exhibit.service b/build/old/phga.de.service similarity index 100% rename from exhibit.service rename to build/old/phga.de.service diff --git a/exhibit.go b/cmd/phga.de/phga.de.go similarity index 73% rename from exhibit.go rename to cmd/phga.de/phga.de.go index 2052ec9..6b64a96 100644 --- a/exhibit.go +++ b/cmd/phga.de/phga.de.go @@ -9,11 +9,12 @@ import ( "io/ioutil" "log" "net/http" + "path" "regexp" ) // could be enabled after the implementation is complete. -// var t = template.Must(template.ParseFiles("tmpl/layouts/base.html", "tmpl/index.html", "tmpl/blog.html", "tmpl/about.html", "tmpl/contact.html", )) +// var t = template.Must(getTemplate("layouts/base.html", "index.html", "blog.html", "about.html", "contact.html", )) // A regex used to identify valid Img requests var validImg = regexp.MustCompile("^/info/([\\w_\\- ]+)") var exhibit Exhibition @@ -28,7 +29,7 @@ func main() { http.HandleFunc("/contact", handleContact) http.HandleFunc("/info/", handleInfo) // provide the inc directory to the useragent - http.Handle("/inc/", http.StripPrefix("/inc/", http.FileServer(http.Dir("inc")))) + http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("../../web/static")))) // listen on port 8080 (I use nginx to proxy this local server) log.Fatalln(http.ListenAndServe(":8080", nil)) } @@ -51,24 +52,24 @@ type Exhibition struct { // Funcions follow that handle the requests func handleIndex(w http.ResponseWriter, r *http.Request) { // that should also be somewhere else when there is another gallery - exhibit.parseExhibitions("./data") + exhibit.parseExhibitions("../../web/data") // Parses all required html files to provide the actual html that is shipped. - t, _ := template.ParseFiles("tmpl/layouts/index.html", "tmpl/gallery.html", "tmpl/header.html") + t, _ := getTemplate("layouts/index.html", "gallery.html", "header.html") t.Execute(w, exhibit) } func handleBlog(w http.ResponseWriter, r *http.Request) { - t, _ := template.ParseFiles("tmpl/layouts/base.html", "tmpl/soon.html", "tmpl/header.html") + t, _ := getTemplate("layouts/base.html", "soon.html", "header.html") t.Execute(w, nil) } func handleAbout(w http.ResponseWriter, r *http.Request) { - t, _ := template.ParseFiles("tmpl/layouts/base.html", "tmpl/about.html", "tmpl/header.html") + t, _ := getTemplate("layouts/base.html", "about.html", "header.html") t.Execute(w, nil) } func handleContact(w http.ResponseWriter, r *http.Request) { - t, _ := template.ParseFiles("tmpl/layouts/base.html", "tmpl/contact.html", "tmpl/header.html") + t, _ := getTemplate("layouts/base.html", "contact.html", "header.html") t.Execute(w, nil) } @@ -125,3 +126,21 @@ func (ex *Exhibition) parseExhibitions(dir string) { } } } + +func getTemplate(files ...string) (*template.Template, error) { + tmplFolder := "../../web/templates/" + for i, f := range files { + files[i] = tmplFolder + f + } + // Name has to be the basename of at least one of the template files + t := template.New(path.Base(files[0])) + // Add custom helper funcs to template + // t.Funcs(template.FuncMap{ + // "UnwrapOID": unwrapObjectID, + // "GetSurveys": getSurveys, + // }) + + t, err := t.ParseFiles(files...) + + return t, err +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..7c82fd2 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module g.phga.de/phga/phga.de + +go 1.16 diff --git a/data/dg1.json b/web/data/dg1.json similarity index 100% rename from data/dg1.json rename to web/data/dg1.json diff --git a/inc/css/main.css b/web/static/css/main.css similarity index 99% rename from inc/css/main.css rename to web/static/css/main.css index a79c65d..8f333f9 100644 --- a/inc/css/main.css +++ b/web/static/css/main.css @@ -1,5 +1,5 @@ @font-face { - src: url("/inc/fonts/HKGrotesk-Regular.woff"); + src: url("/static/fonts/HKGrotesk-Regular.woff"); font-family: hkg; } diff --git a/inc/fonts/OFL-FAQ.txt b/web/static/fonts/OFL-FAQ.txt similarity index 100% rename from inc/fonts/OFL-FAQ.txt rename to web/static/fonts/OFL-FAQ.txt diff --git a/inc/js/main.js b/web/static/js/main.js similarity index 98% rename from inc/js/main.js rename to web/static/js/main.js index dce7eeb..0cb4aa3 100644 --- a/inc/js/main.js +++ b/web/static/js/main.js @@ -101,7 +101,7 @@ function showOverlay(overlay, imgName) { window.addEventListener("resize", resize); img.addEventListener("load", () => {zoom(0.4, imgName)}); - img.src = `/inc/images/${imgName}.jpg`; + img.src = `/static/images/${imgName}.jpg`; img.id = imgName; img.alt = imgName; diff --git a/inc/js/text.js b/web/static/js/text.js similarity index 100% rename from inc/js/text.js rename to web/static/js/text.js diff --git a/inc/js/zoom.js b/web/static/js/zoom.js similarity index 100% rename from inc/js/zoom.js rename to web/static/js/zoom.js diff --git a/inc/logo/avatar.svg b/web/static/logo/avatar.svg similarity index 100% rename from inc/logo/avatar.svg rename to web/static/logo/avatar.svg diff --git a/inc/logo/logo.svg b/web/static/logo/logo.svg similarity index 100% rename from inc/logo/logo.svg rename to web/static/logo/logo.svg diff --git a/tmpl/about.html b/web/templates/about.html similarity index 89% rename from tmpl/about.html rename to web/templates/about.html index 55d5bc0..427e90f 100644 --- a/tmpl/about.html +++ b/web/templates/about.html @@ -22,7 +22,7 @@ Adresse