flounder

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

commit 2b6bd994fd8d356226f5d5e365f5628280a5c318
parent f4409a3c4640d6bbbfc06eb3c0b80b3148e1598d
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Thu,  5 Nov 2020 18:50:07 -0800

Add emoji favicons

Diffstat:
Mgo.mod | 2+-
Mhttp.go | 18+++++++++++++++++-
Mtemplates/user_page.html | 16++++++++++++++--
3 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/go.mod b/go.mod @@ -3,7 +3,7 @@ module git.sr.ht/flounder go 1.15 require ( - git.sr.ht/~adnano/go-gemini v0.1.6-0.20201105050458-53390dad6bb1 // indirect + git.sr.ht/~adnano/go-gemini v0.1.6-0.20201105050458-53390dad6bb1 github.com/BurntSushi/toml v0.3.1 github.com/gorilla/handlers v1.5.1 github.com/gorilla/sessions v1.2.1 diff --git a/http.go b/http.go @@ -390,6 +390,19 @@ func adminHandler(w http.ResponseWriter, r *http.Request) { } } +func getFavicon(user string) string { + faviconPath := path.Join(c.FilesDirectory, filepath.Clean(user), "favicon.txt") + content, err := ioutil.ReadFile(faviconPath) + if err != nil { + return "" + } + strcontent := []rune(string(content)) + if len(strcontent) > 0 { + return string(strcontent[0]) + } + return "" +} + // Server a user's file func userFile(w http.ResponseWriter, r *http.Request) { userName := filepath.Clean(strings.Split(r.Host, ".")[0]) // clean probably unnecessary @@ -413,10 +426,13 @@ func userFile(w http.ResponseWriter, r *http.Request) { file, _ := os.Open(fileName) htmlString := textToHTML(gmi.ParseText(file)) + favicon := getFavicon(userName) + log.Println(favicon) data := struct { SiteBody template.HTML + Favicon string PageTitle string - }{template.HTML(htmlString), userName} + }{template.HTML(htmlString), favicon, userName} t.ExecuteTemplate(w, "user_page.html", data) } else { http.ServeFile(w, r, fileName) diff --git a/templates/user_page.html b/templates/user_page.html @@ -1,3 +1,15 @@ -{{template "header" .}} +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8" /> + <title>{{.PageTitle }}</title> + <meta name="viewport" content="width=device-width" /> + <link rel="stylesheet" type="text/css" href="/style.css" /> + <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>{{.Favicon}}</text></svg>"> + </head> + <body> +<main> {{.SiteBody}} -{{template "footer" .}} +</main> +</body> +</html>