From 9c4b8766cbdc2a4c63a03292b58cf35d981e1321 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 2 Nov 2016 23:37:00 -0400 Subject: simplemde --- src/edit/main.go | 5 +++-- src/edit/util.go | 7 ++++--- src/edit/views.go | 11 +++++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/edit/main.go b/src/edit/main.go index a7ec7bd..66e9a36 100644 --- a/src/edit/main.go +++ b/src/edit/main.go @@ -9,6 +9,7 @@ import ( func ServeIndex(out http.ResponseWriter, in *http.Request) { if in.URL.Path != "/" { http.NotFound(out, in) + return } http.Redirect(out, in, "/files/", http.StatusMovedPermanently) } @@ -16,9 +17,9 @@ func ServeIndex(out http.ResponseWriter, in *http.Request) { func main() { socket, err := util.StreamListener(os.Args[1], os.Args[2]) errcheck(err) - errcheck(os.Chdir("/srv/http/edit.team4272.com/www.git")) + errcheck(os.Setenv("GIT_DIR", "/srv/http/edit.team4272.com/www.git")) http.Handle("/", util.SaneHTTPHandler{http.HandlerFunc(ServeIndex)}) - http.Handle("/static/", util.SaneHTTPHandler{http.FileServer(http.Dir("static"))}) + http.Handle("/static/", util.SaneHTTPHandler{http.StripPrefix("/static", http.FileServer(http.Dir("static")))}) http.Handle("/files/", util.SaneHTTPHandler{http.StripPrefix("/files", http.HandlerFunc(ServeGit))}) errcheck(http.Serve(socket, nil)) } diff --git a/src/edit/util.go b/src/edit/util.go index 5835b10..b1950ed 100644 --- a/src/edit/util.go +++ b/src/edit/util.go @@ -33,15 +33,16 @@ func getctype(name string, content []byte) string { if ctype == "" { ctype = http.DetectContentType(content) } - return ctype -} -func istext(ctype string) bool { i := strings.Index(ctype, ";") if i == -1 { i = len(ctype) } ctype = strings.TrimSpace(strings.ToLower(ctype[0:i])) + return ctype +} + +func istext(ctype string) bool { return strings.HasPrefix(ctype, "text/") || strings.HasSuffix(ctype, "+xml") } diff --git a/src/edit/views.go b/src/edit/views.go index 0998d4a..1d3176d 100644 --- a/src/edit/views.go +++ b/src/edit/views.go @@ -65,18 +65,25 @@ func renderViewBlob(w io.Writer, upath string, file GitFile) error { if err != nil { return err } + ctype := getctype(upath, content) // Component render var buf bytes.Buffer err = tmplViewBlob.Execute(&buf, map[string]string{ "path": upath, - "ctype": getctype(upath, content), + "ctype": ctype, "content": string(content), }) if err != nil { return err } + head := "" + if ctype == "text/markdown" { + head += "\n" + head += "\n" + head += "\n" + } // Page render - return renderPage(w, upath, "", buf.String()) + return renderPage(w, upath, head, buf.String()) } func renderModified(w io.Writer, upath string) error { -- cgit v1.2.3