small pixel drawing of a pufferfish vore

add nice time duration printout, muck with some css
Jes Olson j3s@c3f.net
Sun, 14 May 2023 04:21:35 -0700
commit

9b564eaf6d4fb3234fe6e64c539fe17ff714ff28

parent

7965b082597186c72969920a3a37a7f8b3cd5f0e

4 files changed, 39 insertions(+), 8 deletions(-)

jump to
M files/feeds.tmpl.htmlfiles/feeds.tmpl.html

@@ -2,8 +2,8 @@ {{ define "feeds" }}

{{ template "head" . }} {{ template "nav" . }} <h3>Settings</h3> -<p><a href="/{{ .Username }}">vore.website/{{ .Username }}</a> -<a href="/changelog">vore changelog</a> +<p>your timeline: <a href="/{{ .Username }}">vore.website/{{ .Username }}</a> +vore changelog: <a href="/changelog">changelog</a> {{ len .Data }} subscriptions: </p>
M files/style.cssfiles/style.css

@@ -4,7 +4,7 @@ max-width: 600px;

margin: 20px auto; /* make sure the scrollbar is always shown so the width doesnt change between pages */ - font-size: calc(14px + 0.5vw); + font-size: calc(12px + 0.5vw); overflow-y: scroll; }
M files/user.tmpl.htmlfiles/user.tmpl.html

@@ -13,14 +13,14 @@ {{ end }}

{{ end }} <ul> {{ range .Data.Items }} -<a href="{{ .Link }}"> <li> + <a href="{{ .Link }}"> {{ .Title }} - <span class=puny> - {{ .Link | printDomain }} - </span> + </a> + <span class=puny>(<a href="//{{ .Link | printDomain }}">{{ .Link | printDomain }}</a>)</span> + <br> + <span class=puny title="{{ .Date }}">published {{ .Date | timeSince }} ago</span> </li> -</a> {{ end }} </ul>
M site.gosite.go

@@ -299,6 +299,7 @@ // handler should do tbh.

func (s *Site) renderPage(w http.ResponseWriter, r *http.Request, page string, data any) { funcMap := template.FuncMap{ "printDomain": s.printDomain, + "timeSince": s.timeSince, "trimSpace": strings.TrimSpace, }

@@ -352,6 +353,36 @@ trimmedStr = strings.TrimPrefix(trimmedStr, "http://")

trimmedStr = strings.TrimPrefix(trimmedStr, "https://") return strings.Split(trimmedStr, "/")[0] +} + +func (s *Site) timeSince(t time.Time) string { + now := time.Now() + duration := now.Sub(t) + + minutes := int(duration.Minutes()) + hours := int(duration.Hours()) + days := int(duration.Hours() / 24) + weeks := int(duration.Hours() / (24 * 7)) + months := int(duration.Hours() / (24 * 7 * 4)) + years := int(duration.Hours() / (24 * 7 * 4 * 12)) + + if years > 100 { + return fmt.Sprintf("far too long") + } else if years > 1 { + return fmt.Sprintf("%d years", years) + } else if months > 1 { + return fmt.Sprintf("%d months", months) + } else if weeks > 1 { + return fmt.Sprintf("%d weeks", weeks) + } else if days > 1 { + return fmt.Sprintf("%d days", days) + } else if hours > 1 { + return fmt.Sprintf("%d hours", hours) + } else if minutes > 1 { + return fmt.Sprintf("%d mins", minutes) + } else { + return fmt.Sprintf("just now") + } } // renderErr sets the correct http status in the header,