Remove edit button for binary files
alex wennerberg alex@alexwennerberg.com
Thu, 29 Oct 2020 18:19:15 -0700
2 files changed,
7 insertions(+),
0 deletions(-)
M
main.go
→
main.go
@@ -9,10 +9,12 @@ "github.com/gorilla/sessions"
"io" "io/ioutil" "log" + "mime" "os" "path" "path/filepath" "sort" + "strings" "sync" "time" )@@ -24,6 +26,7 @@ Creator string
Name string UpdatedTime time.Time TimeAgo string + IsText bool } type User struct {@@ -107,10 +110,12 @@ if err != nil {
return nil, err } for _, file := range files { + isText := strings.HasPrefix(mime.TypeByExtension(path.Ext(file.Name())), "text") result = append(result, &File{ Name: file.Name(), Creator: user, UpdatedTime: file.ModTime(), + IsText: isText, }) } return result, nil
M
templates/my_site.html
→
templates/my_site.html
@@ -12,7 +12,9 @@ {{ range .Files }}
<div> <a href="//{{$authUser}}.{{$domain}}/{{.Name}}"> {{ .Name }}</a> + {{ if .IsText }} <a href="/edit/{{.Name}}">edit</a> + {{ end }} <form action="/delete/{{.Name}}" method="POST" class="inline"> <input class="button delete"