1
0

CurrentPath() func was moved to index.templ and was renamed to currentPathToLink().

This commit is contained in:
Alexander Andreev 2024-12-30 15:00:22 +04:00
parent dc2729ff91
commit 034216efd4
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34
3 changed files with 16 additions and 21 deletions

View File

@ -107,5 +107,5 @@ func Index(w http.ResponseWriter, r *http.Request) {
return
}
web.Index(files.CurrentPath(path), version, &stats, &entries, r).Render(r.Context(), w)
web.Index(path, version, &stats, &entries, r).Render(r.Context(), w)
}

View File

@ -1,19 +0,0 @@
package files
import (
"strings"
)
func CurrentPath(path string) (curPath string) {
parts := strings.Split(path, "/")[1:]
for i, part := range parts {
var sb strings.Builder
sb.WriteString("/<a href=\"/")
sb.WriteString(strings.Join(parts[:i+1], "/"))
sb.WriteString("/\">")
sb.WriteString(part)
sb.WriteString("</a>")
curPath += sb.String()
}
return
}

View File

@ -5,7 +5,21 @@ import "net/http"
import "dwelling-files/pkg/files"
import "dwelling-files/pkg/utils"
import "strconv"
import "strings"
func currentPathToLink(path string) (curPath string) {
parts := strings.Split(path, "/")[1:]
for i, part := range parts {
var sb strings.Builder
sb.WriteString("/<a href=\"/")
sb.WriteString(strings.Join(parts[:i+1], "/"))
sb.WriteString("/\">")
sb.WriteString(part)
sb.WriteString("</a>")
curPath += sb.String()
}
return
}
templ Index(currentPath, progVer string, stat *files.DirStat, entries *[]files.DirEntry, r *http.Request) {
<!doctype html>
@ -39,7 +53,7 @@ templ Index(currentPath, progVer string, stat *files.DirStat, entries *[]files.D
</header>
<main>
<section>
<span><a href="/">{ i18n.T(ctx, "curpath-root") }</a>@templ.Raw(currentPath)</span>
<span><a href="/">{ i18n.T(ctx, "curpath-root") }</a>@templ.Raw(currentPathToLink(currentPath))</span>
<p>{ i18n.T(ctx, "stats.files") }: { strconv.FormatInt(stat.Files, 10) } ({ stat.FilesSize }); { i18n.T(ctx, "stats.directories") }: { strconv.FormatInt(stat.Directories, 10) }.</p>
<input type="text" name="filter" placeholder={ i18n.T(ctx, "stats.filter") } class="hidden">
</section>