From d60a53a06add1248e7d6ed9e6636d212ed43662a Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Fri, 7 Mar 2025 18:50:12 +0800 Subject: http/templates: Add query_escape and path_escape --- http_template_funcs.go | 9 +++++++++ resources.go | 2 ++ 2 files changed, 11 insertions(+) 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 } -- cgit v1.2.3