web frontend for git (tangled's grandpa)
7
fork

Configure Feed

Select the types of activity you want to include in your feed.

routes: serve static content from /static

+24 -13
+3 -2
config.yaml
··· 8 8 mainBranch: 9 9 - master 10 10 - main 11 - template: 12 - dir: ./templates 11 + dirs: 12 + templates: ./templates 13 + static: ./static 13 14 meta: 14 15 title: git good 15 16 description: i think it's a skill issue
+4 -3
config/config.go
··· 13 13 Readme []string `yaml:"readme"` 14 14 MainBranch []string `yaml:"mainBranch"` 15 15 } `yaml:"repo"` 16 - Template struct { 17 - Dir string `yaml:"dir"` 18 - } `yaml:"template"` 16 + Dirs struct { 17 + Templates string `yaml:"templates"` 18 + Static string `yaml:"static"` 19 + } `yaml:"dirs"` 19 20 Meta struct { 20 21 Title string `yaml:"title"` 21 22 Description string `yaml:"description"`
+1
routes/handler.go
··· 56 56 }) 57 57 58 58 mux.HandleFunc("/", d.Index, "GET") 59 + mux.HandleFunc("/static/:file", d.ServeStatic, "GET") 59 60 mux.HandleFunc("/:name", dw.Multiplex, "GET", "POST") 60 61 mux.HandleFunc("/:name/tree/:ref/...", d.RepoTree, "GET") 61 62 mux.HandleFunc("/:name/blob/:ref/...", d.FileContent, "GET")
+12 -4
routes/routes.go
··· 42 42 if err != nil { 43 43 d.Write500(w) 44 44 log.Println(err) 45 + return 45 46 } 46 47 47 48 var desc string ··· 59 60 }) 60 61 } 61 62 62 - tpath := filepath.Join(d.c.Template.Dir, "*") 63 + tpath := filepath.Join(d.c.Dirs.Templates, "*") 63 64 t := template.Must(template.ParseGlob(tpath)) 64 65 65 66 data := make(map[string]interface{}) ··· 186 187 return 187 188 } 188 189 189 - tpath := filepath.Join(d.c.Template.Dir, "*") 190 + tpath := filepath.Join(d.c.Dirs.Templates, "*") 190 191 t := template.Must(template.ParseGlob(tpath)) 191 192 192 193 data := make(map[string]interface{}) ··· 219 220 return 220 221 } 221 222 222 - tpath := filepath.Join(d.c.Template.Dir, "*") 223 + tpath := filepath.Join(d.c.Dirs.Templates, "*") 223 224 t := template.Must(template.ParseGlob(tpath)) 224 225 225 226 data := make(map[string]interface{}) ··· 260 261 return 261 262 } 262 263 263 - tpath := filepath.Join(d.c.Template.Dir, "*") 264 + tpath := filepath.Join(d.c.Dirs.Templates, "*") 264 265 t := template.Must(template.ParseGlob(tpath)) 265 266 266 267 data := make(map[string]interface{}) ··· 275 276 return 276 277 } 277 278 } 279 + 280 + func (d *deps) ServeStatic(w http.ResponseWriter, r *http.Request) { 281 + f := flow.Param(r.Context(), "file") 282 + f = filepath.Clean(filepath.Join(d.c.Dirs.Static, f)) 283 + 284 + http.ServeFile(w, r, f) 285 + }
+4 -4
routes/template.go
··· 13 13 ) 14 14 15 15 func (d *deps) Write404(w http.ResponseWriter) { 16 - tpath := filepath.Join(d.c.Template.Dir, "*") 16 + tpath := filepath.Join(d.c.Dirs.Templates, "*") 17 17 t := template.Must(template.ParseGlob(tpath)) 18 18 w.WriteHeader(404) 19 19 if err := t.ExecuteTemplate(w, "404", nil); err != nil { ··· 22 22 } 23 23 24 24 func (d *deps) Write500(w http.ResponseWriter) { 25 - tpath := filepath.Join(d.c.Template.Dir, "*") 25 + tpath := filepath.Join(d.c.Dirs.Templates, "*") 26 26 t := template.Must(template.ParseGlob(tpath)) 27 27 w.WriteHeader(500) 28 28 if err := t.ExecuteTemplate(w, "500", nil); err != nil { ··· 31 31 } 32 32 33 33 func (d *deps) listFiles(files []git.NiceTree, data map[string]any, w http.ResponseWriter) { 34 - tpath := filepath.Join(d.c.Template.Dir, "*") 34 + tpath := filepath.Join(d.c.Dirs.Templates, "*") 35 35 t := template.Must(template.ParseGlob(tpath)) 36 36 37 37 data["files"] = files ··· 62 62 } 63 63 64 64 func (d *deps) showFile(content string, data map[string]any, w http.ResponseWriter) { 65 - tpath := filepath.Join(d.c.Template.Dir, "*") 65 + tpath := filepath.Join(d.c.Dirs.Templates, "*") 66 66 t := template.Must(template.ParseGlob(tpath)) 67 67 68 68 lc, err := countLines(strings.NewReader(content))