flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit 1dc7bca96c49c3edf181006277ec8baa5134e3e2
parent 0c5bc7386da9f63a7a10c1c6036b081e06c3c765
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Thu, 29 Oct 2020 18:19:15 -0700

Remove edit button for binary files

Diffstat:
Mmain.go | 5+++++
Mtemplates/my_site.html | 2++
2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/main.go b/main.go @@ -9,10 +9,12 @@ import ( "io" "io/ioutil" "log" + "mime" "os" "path" "path/filepath" "sort" + "strings" "sync" "time" ) @@ -24,6 +26,7 @@ type File struct { Name string UpdatedTime time.Time TimeAgo string + IsText bool } type User struct { @@ -107,10 +110,12 @@ func getUserFiles(user string) ([]*File, error) { 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 diff --git a/templates/my_site.html b/templates/my_site.html @@ -12,7 +12,9 @@ <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"