From 99fefccd70d3d006a9f3ddccc45eda559af1f197 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Tue, 25 Mar 2025 03:03:25 +0800 Subject: [PATCH] Fix group path trailing slash --- http_template_funcs.go | 4 ++++ resources.go | 1 + templates/_group_path.tmpl | 2 +- templates/group.tmpl | 2 +- diff --git a/http_template_funcs.go b/http_template_funcs.go index 8d67aff0ded146be4e13c05074763cbb8bd91e84..b94e5284388878747ad883b6fb42f424b9043d86 100644 --- a/http_template_funcs.go +++ b/http_template_funcs.go @@ -37,3 +37,7 @@ } var z T return z } + +func minus(a, b int) int { + return a - b +} diff --git a/resources.go b/resources.go index 18f9849b7964efeb91bebef63cc4800f269483f7..df992ba643bd12f3f604119e75e06580cbcf9dd3 100644 --- a/resources.go +++ b/resources.go @@ -49,6 +49,7 @@ "base_name": baseName, "path_escape": pathEscape, "query_escape": queryEscape, "dereference_error": dereferenceOrZero[error], + "minus": minus, }) err = fs.WalkDir(resourcesFS, "templates", func(path string, d fs.DirEntry, err error) error { diff --git a/templates/_group_path.tmpl b/templates/_group_path.tmpl index 3a14edc0fd4a97149a4759c82ca1d837347263fe..8904563968696b57abc9dbd7be4fcc858edaafab 100644 --- a/templates/_group_path.tmpl +++ b/templates/_group_path.tmpl @@ -4,5 +4,5 @@ SPDX-FileContributor: Runxi Yu */}} {{- define "group_path_plain" -}} {{- $p := . -}} -{{- range $i, $s := . -}}{{- $s -}}{{- if ne $i (len $p) -}}/{{- end -}}{{- end -}} +{{- range $i, $s := . -}}{{- $s -}}{{- if ne $i (minus (len $p) 1) -}}/{{- end -}}{{- end -}} {{- end -}} diff --git a/templates/group.tmpl b/templates/group.tmpl index 98d4c765f5c8743c830e271ee6c99b6843a12b90..3a4a7d1dcc90edc44db1f3258e7c11e0501509e5 100644 --- a/templates/group.tmpl +++ b/templates/group.tmpl @@ -13,7 +13,7 @@ {{- template "header" . -}}
-

{{- range $i, $s := .group_path -}}{{- $s -}}{{- if ne $i (len $group_path) }} / {{ end -}}{{- end -}} +

{{- range $i, $s := .group_path -}}{{- $s -}}{{- if ne $i (minus (len $group_path) 1) }} / {{ end -}}{{- end -}} {{- if .description -}}

{{- .description -}}

{{- end -}} -- 2.48.1