flounder

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

commit c22ee7e5f475466e3b1350eec310ee1bf57b2834
parent 6eb2c61905096c7f23a55571c4253b62f6214560
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 31 Oct 2021 00:55:33 -0700

Add updated files page

only html for now

Diffstat:
Mdb.go | 10++++++++--
Mgemini.go | 2+-
Mhttp.go | 25++++++++++++++++++++++++-
Mtemplates/index.html | 2+-
Atemplates/updates.html | 20++++++++++++++++++++
5 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/db.go b/db.go @@ -174,9 +174,15 @@ func getUsers() ([]User, error) { return users, nil } -func getIndexFiles(admin bool) ([]*File, error) { // TODO cache this function +// admin tells you whether to show hidden files etc +// make sure user is a clean string +func getUpdatedFiles(admin bool, user string) ([]*File, error) { // TODO cache this function result := []*File{} - err := filepath.Walk(c.FilesDirectory, func(thepath string, info os.FileInfo, err error) error { + dir := c.FilesDirectory + if user != "" { + dir = path.Join(dir, user) + } + err := filepath.Walk(dir, func(thepath string, info os.FileInfo, err error) error { if err != nil { log.Printf("Failure accessing a path %q: %v\n", thepath, err) return err // think about diff --git a/gemini.go b/gemini.go @@ -58,7 +58,7 @@ func gmiIndex(w gmi.ResponseWriter, r *gmi.Request) { if err != nil { log.Fatal(err) } - files, err := getIndexFiles(false) + files, err := getUpdatedFiles(false, "") users, err := getActiveUserNames() if err != nil { log.Println(err) diff --git a/http.go b/http.go @@ -63,7 +63,7 @@ func rootHandler(w http.ResponseWriter, r *http.Request) { } user := getAuthUser(r) - indexFiles, err := getIndexFiles(user.IsAdmin) + indexFiles, err := getUpdatedFiles(user.IsAdmin, "") if err != nil { serverError(w, err) return @@ -86,6 +86,28 @@ func rootHandler(w http.ResponseWriter, r *http.Request) { } } +func updatesHandler(w http.ResponseWriter, r *http.Request) { + // user + authUser := getAuthUser(r) + username := filepath.Clean(r.URL.Path[len("/updates/"):]) + files, err := getUpdatedFiles(authUser.IsAdmin, username) + if err != nil { + serverError(w, err) + return + } + data := struct { + Config Config + AuthUser AuthUser + User string + Files []*File + }{c, authUser, username, files} + err = t.ExecuteTemplate(w, "updates.html", data) + if err != nil { + serverError(w, err) + return + } +} + func editFileHandler(w http.ResponseWriter, r *http.Request) { user := getAuthUser(r) if !user.LoggedIn { @@ -795,6 +817,7 @@ func runHTTPServer() { serveMux.HandleFunc(hostname+"/my_site/flounder-archive.zip", archiveHandler) serveMux.HandleFunc(hostname+"/admin", adminHandler) serveMux.HandleFunc(hostname+"/edit/", editFileHandler) + serveMux.HandleFunc(hostname+"/updates/", updatesHandler) serveMux.HandleFunc(hostname+"/upload", uploadFilesHandler) serveMux.Handle(hostname+"/login", limit(http.HandlerFunc(loginHandler))) serveMux.Handle(hostname+"/register", limit(http.HandlerFunc(registerHandler))) diff --git a/templates/index.html b/templates/index.html @@ -18,7 +18,7 @@ Welcome to {{.Config.SiteTitle}}! For more information and site updates, check o <br> <h2>All users:</h2> {{ range .Users}} -<a href="//{{.}}.{{$.Config.Host}}" class='person-link'>{{.}}</a> +<a href="//{{$.Config.Host}}/updates/{{.}}" class='person-link'>{{.}}</a> {{end}} <hr class="thin"> Made with <a href="https://github.com/alexwennerberg/flounder">Flounder</a>. <a href="https://www.buymeacoffee.com/alexwennerberg">Donate!</a> diff --git a/templates/updates.html b/templates/updates.html @@ -0,0 +1,20 @@ +{{template "header" .}} +<h1>🐟{{.Config.SiteTitle}}!</h1> +{{template "nav.html" .}} +<br> +<p> +<h2>Recently updated files from <a href="//{{.User}}.{{.Config.Host}}">{{.User}}.{{.Config.Host}}</a></h2> +{{ range .Files }} +<div class="indent-wrap"> + <a href="//{{.Creator}}.{{$.Config.Host}}" class='person-link'> + {{ .Creator }}</a> + <em>{{.TimeAgo}}</em> + <a href="//{{.Creator}}.{{$.Config.Host}}/{{.Name}}"> + {{ .Name}} + </a> {{ if eq .Creator $.AuthUser.Username }} (<a href="//{{$.Config.Host}}/edit/{{.Name}}">edit</a>){{ end}} +</div> +{{end}} +<br> +<hr class="thin"> +Made with <a href="https://github.com/alexwennerberg/flounder">Flounder</a>. <a href="https://www.buymeacoffee.com/alexwennerberg">Donate!</a> +{{template "footer" .}}