aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-07 18:50:12 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-07 18:50:12 +0800
commitd60a53a06add1248e7d6ed9e6636d212ed43662a (patch)
treede643c87114e726b4d9f17210d729b7a19d2f8a4
parentfedauth: Add rudimentary tangled support (diff)
downloadforge-d60a53a06add1248e7d6ed9e6636d212ed43662a.tar.gz
forge-d60a53a06add1248e7d6ed9e6636d212ed43662a.tar.zst
forge-d60a53a06add1248e7d6ed9e6636d212ed43662a.zip
http/templates: Add query_escape and path_escape
Diffstat (limited to '')
-rw-r--r--http_template_funcs.go9
-rw-r--r--resources.go2
2 files changed, 11 insertions, 0 deletions
diff --git a/http_template_funcs.go b/http_template_funcs.go
index 119a800..a7ebb1e 100644
--- a/http_template_funcs.go
+++ b/http_template_funcs.go
@@ -6,6 +6,7 @@ package main
import (
"path"
"strings"
+ "net/url"
)
func first_line(s string) string {
@@ -16,3 +17,11 @@ func first_line(s string) string {
func base_name(s string) string {
return path.Base(s)
}
+
+func path_escape(s string) string {
+ return url.PathEscape(s)
+}
+
+func query_escape(s string) string {
+ return url.QueryEscape(s)
+}
diff --git a/resources.go b/resources.go
index 20d4484..ff1286f 100644
--- a/resources.go
+++ b/resources.go
@@ -36,6 +36,8 @@ func load_templates() (err error) {
templates, err = template.New("templates").Funcs(template.FuncMap{
"first_line": first_line,
"base_name": base_name,
+ "path_escape": path_escape,
+ "query_escape": query_escape,
}).ParseFS(resources_fs, "templates/*")
return err
}