Compare commits
4 commits
92a06fb740
...
0d822e2a38
Author | SHA1 | Date | |
---|---|---|---|
0d822e2a38 |
|||
d0115cdaf4 |
|||
d91a386881 |
|||
634326190c |
3 changed files with 17 additions and 1 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func ReadConfig(file string, config interface{}) error {
|
||||
|
@ -102,6 +103,15 @@ func HumanDuration(i int) string {
|
|||
return fmt.Sprintf("%d %s", i, w)
|
||||
}
|
||||
|
||||
// TimeDiff to return the number of seconds between this time and now
|
||||
func TimeDiff(ts time.Time) int {
|
||||
diff := int(time.Since(ts).Seconds())
|
||||
if diff < 0 {
|
||||
return diff * -1
|
||||
}
|
||||
return diff
|
||||
}
|
||||
|
||||
func ReturnError(logger *slog.Logger, message string, err error) int {
|
||||
if err != nil {
|
||||
logger.Error(message, slog.Any("error", err))
|
||||
|
|
|
@ -106,6 +106,7 @@ func (s *Server) Start() error {
|
|||
// Web pages
|
||||
funcs := template.FuncMap{
|
||||
"HumanDuration": internal.HumanDuration,
|
||||
"TimeDiff": internal.TimeDiff,
|
||||
"lower": strings.ToLower,
|
||||
"string": func(b []byte) string { return string(b) },
|
||||
}
|
||||
|
|
|
@ -19,13 +19,18 @@
|
|||
<div class="d-flex flex-wrap py-2">
|
||||
<span class="fs-4 d-flex mb-3 mb-md-0 me-md-auto text-decoration-none">Note {{.Note.ID}}</span>
|
||||
<ul class="nav nav-pills align-items-center">
|
||||
<li class="nav-item">
|
||||
<li class="nav-item px-2">
|
||||
<a href="" id="rawURL">raw</a>
|
||||
<script>document.getElementById("rawURL").href = window.location.href.replace(".html", "");</script>
|
||||
</li>
|
||||
<li class="nav-item px-2">
|
||||
{{.Note.Language}}
|
||||
</li>
|
||||
{{if eq .Note.DeleteAfterRead false}}
|
||||
<li class="nav-item px-2">
|
||||
expires in {{HumanDuration (TimeDiff .Note.ExpiresAt)}}
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
{{if .DisableEditor}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue