summaryrefslogtreecommitdiffstats
path: root/modules/templates/helper.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-06-08 09:59:16 +0100
committerGitHub <noreply@github.com>2022-06-08 16:59:16 +0800
commitac88f21ecc5612befe51f7ab6ffcb76c681daba5 (patch)
treecbe281221d0703da0f1ecce428888e036ef311d7 /modules/templates/helper.go
parentc1c07e533c9ca3be13b4af057b6b989402c12f6e (diff)
downloadgitea-ac88f21ecc5612befe51f7ab6ffcb76c681daba5.tar.gz
gitea-ac88f21ecc5612befe51f7ab6ffcb76c681daba5.zip
Automatically render wiki TOC (#19873)
Automatically add sidebar in the wiki view containing a TOC for the wiki page. Make the TOC collapsable Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/templates/helper.go')
-rw-r--r--modules/templates/helper.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index cc0fed7442..ef7b70c09f 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -18,6 +18,7 @@ import (
"reflect"
"regexp"
"runtime"
+ "strconv"
"strings"
texttmpl "text/template"
"time"
@@ -390,6 +391,66 @@ func NewFuncMap() []template.FuncMap {
"Join": strings.Join,
"QueryEscape": url.QueryEscape,
"DotEscape": DotEscape,
+ "Iterate": func(arg interface{}) (items []uint64) {
+ count := uint64(0)
+ switch val := arg.(type) {
+ case uint64:
+ count = val
+ case *uint64:
+ count = *val
+ case int64:
+ if val < 0 {
+ val = 0
+ }
+ count = uint64(val)
+ case *int64:
+ if *val < 0 {
+ *val = 0
+ }
+ count = uint64(*val)
+ case int:
+ if val < 0 {
+ val = 0
+ }
+ count = uint64(val)
+ case *int:
+ if *val < 0 {
+ *val = 0
+ }
+ count = uint64(*val)
+ case uint:
+ count = uint64(val)
+ case *uint:
+ count = uint64(*val)
+ case int32:
+ if val < 0 {
+ val = 0
+ }
+ count = uint64(val)
+ case *int32:
+ if *val < 0 {
+ *val = 0
+ }
+ count = uint64(*val)
+ case uint32:
+ count = uint64(val)
+ case *uint32:
+ count = uint64(*val)
+ case string:
+ cnt, _ := strconv.ParseInt(val, 10, 64)
+ if cnt < 0 {
+ cnt = 0
+ }
+ count = uint64(cnt)
+ }
+ if count <= 0 {
+ return items
+ }
+ for i := uint64(0); i < count; i++ {
+ items = append(items, i)
+ }
+ return items
+ },
}}
}