all repos — flounder @ 1dc7bca96c49c3edf181006277ec8baa5134e3e2

A small site builder for the Gemini protocol

Remove edit button for binary files
alex wennerberg alex@alexwennerberg.com
Thu, 29 Oct 2020 18:19:15 -0700
commit

1dc7bca96c49c3edf181006277ec8baa5134e3e2

parent

0c5bc7386da9f63a7a10c1c6036b081e06c3c765

2 files changed, 7 insertions(+), 0 deletions(-)

jump to
M main.gomain.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.htmltemplates/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"