add hire/resume pages, contact form, security middleware, and admin improvements

This commit is contained in:
Blake Ridgway
2026-03-08 21:36:47 -05:00
parent c916186d78
commit 261745a5b7
22 changed files with 1237 additions and 72 deletions

View File

@@ -2,6 +2,7 @@
package handler
import (
"fmt"
"html/template"
"log"
"net/http"
@@ -13,20 +14,22 @@ import (
// Handler holds shared dependencies for all HTTP handlers.
type Handler struct {
store *blog.Store
dataDir string
templates map[string]*template.Template
siteURL string
devMode bool
store *blog.Store
dataDir string
templates map[string]*template.Template
siteURL string
contactEmail string
devMode bool
}
// New creates a Handler. dataDir is the path to the data/ directory.
func New(store *blog.Store, dataDir string) *Handler {
h := &Handler{
store: store,
dataDir: dataDir,
siteURL: getenv("SITE_URL", "https://ridgwaysystems.org"),
devMode: os.Getenv("DEV") == "1",
store: store,
dataDir: dataDir,
siteURL: getenv("SITE_URL", "https://ridgwaysystems.org"),
contactEmail: getenv("CONTACT_EMAIL", "hire@ridgwaysystems.org"),
devMode: os.Getenv("DEV") == "1",
}
if !h.devMode {
h.templates = mustLoadTemplates()
@@ -69,10 +72,14 @@ func mustLoadTemplates() map[string]*template.Template {
{"infrastructure", "templates/infrastructure.html"},
{"status", "templates/status.html"},
{"about", "templates/about.html"},
{"hire", "templates/hire.html"},
{"resume", "templates/resume.html"},
{"error", "templates/error.html"},
{"admin-login", "templates/admin/login.html"},
{"admin-dashboard", "templates/admin/dashboard.html"},
{"admin-editor", "templates/admin/editor.html"},
{"admin-status", "templates/admin/status.html"},
{"admin-uploads", "templates/admin/uploads.html"},
}
for _, p := range pages {
@@ -98,8 +105,24 @@ func (h *Handler) render(w http.ResponseWriter, name string, data any) {
}
}
// errorData is passed to the error template.
type errorData struct {
Code int
Title string
Message string
}
func (h *Handler) renderErr(w http.ResponseWriter, code int, msg string) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(code)
w.Write([]byte("<html><body><h1>" + http.StatusText(code) + "</h1><p>" + msg + "</p><a href='/'>Home</a></body></html>"))
data := errorData{Code: code, Title: http.StatusText(code), Message: msg}
t := h.tmpl("error")
if t == nil {
fmt.Fprintf(w, "<html><body><h1>%d %s</h1><p>%s</p><a href='/'>Home</a></body></html>",
code, http.StatusText(code), msg)
return
}
if err := t.ExecuteTemplate(w, "base", data); err != nil {
log.Printf("renderErr %d: %v", code, err)
}
}