projects package with data and page handlers for one and all

This commit is contained in:
ethan merchant 2024-11-03 02:41:25 -05:00
parent c04cbc2a24
commit d716bcf70e

View file

@ -0,0 +1,62 @@
package projects
import (
"dofdev/tem"
"net/http"
"github.com/gorilla/mux"
)
type Project struct {
Name string
Desc string
}
var Projects = map[string]Project{
"braille_xr": {
Name: "braille_xr",
Desc: "refreshable braille display for rendering and input with handtracking",
},
"tungtap": {
Name: "tungtap",
Desc: "easily augment your system's keyboard",
},
}
func Handler(w http.ResponseWriter, r *http.Request) {
data := struct {
Projects map[string]Project
}{
Projects: Projects,
}
tem.Render(
w, r,
"projects.html",
"projects",
"dof driven projects",
data,
)
}
func ProjectHandler(w http.ResponseWriter, r *http.Request) {
hash := mux.Vars(r)["hash"]
project, ok := Projects[hash]
if !ok {
w.WriteHeader(http.StatusNotFound)
return
}
data := struct {
Project Project
}{
Project: project,
}
tem.Render(
w, r,
"project.html",
project.Name,
project.Desc,
data,
)
}