Rethink...
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
# Run the application
|
||||
run:
|
||||
go run ./cmd
|
||||
|
||||
# Build the application binary into a bin/ folder
|
||||
build:
|
||||
go build -o bin/website ./cmd
|
||||
@echo "Project built in bin directory"
|
||||
|
||||
# Clean up binaries and build artifacts
|
||||
clean:
|
||||
rm -rf bin/
|
||||
@echo "Build artifacts removed."
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"jh/website/internal/handlers"
|
||||
)
|
||||
|
||||
func main() {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// Resolve static dir relative to the binary's location
|
||||
mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
||||
|
||||
// Routes
|
||||
mux.HandleFunc("GET /", handlers.Home)
|
||||
|
||||
log.Println("Server starting on http://localhost:8080")
|
||||
if err := http.ListenAndServe(":8080", mux); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package handlers
|
||||
|
||||
import "net/http"
|
||||
|
||||
type HomeData struct {
|
||||
Title string
|
||||
}
|
||||
|
||||
func Home(w http.ResponseWriter, r *http.Request) {
|
||||
data := HomeData{Title: "Home"}
|
||||
view(w, r, "home", data)
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Renders a full page by combining the base template with a page template
|
||||
// Parsed together so the page can define blocks needed for base template
|
||||
func render(w http.ResponseWriter, _ *http.Request, page string, data any) {
|
||||
files := []string{
|
||||
filepath.Join("internal", "templates", "layouts", "base.html"),
|
||||
filepath.Join("internal", "templates", "pages", page+".html"),
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles(files...)
|
||||
if err != nil {
|
||||
http.Error(w, "template error: " + err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
|
||||
if err := tmpl.ExecuteTemplate(w, "base", data); err != nil {
|
||||
http.Error(w, "render error: " + err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func view(w http.ResponseWriter, r *http.Request, page string, data any) {
|
||||
render(w, r, page, data)
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
{{define "base"}}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{.Title}}</title>
|
||||
<link rel="stylesheet" href="/static/css/reset.css">
|
||||
<link rel="stylesheet" href="/static/css/index.css">
|
||||
<link rel="stylesheet" href="/static/js/index.js" defer>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<nav>
|
||||
<a href="/">Home</a>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
{{template "content" .}}
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<p>© <span id="year"></span></p>
|
||||
</footer>
|
||||
|
||||
</body>
|
||||
<script>
|
||||
document.querySelector('#year').innerHTML = new Date().getFullYear();
|
||||
</script>
|
||||
</html>
|
||||
{{end}}
|
||||
@@ -1,7 +0,0 @@
|
||||
{{define "content"}}
|
||||
<section class="hero">
|
||||
<h1>Hi, I'm Jason</h1>
|
||||
<p>PHP & Go developer. I build web applications and tools.</p>
|
||||
<a href="https://codeberg.org/yourname" target="_blank" rel="noopener">Codeberg</a>
|
||||
</section>
|
||||
{{end}}
|
||||
Reference in New Issue
Block a user