mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-20 05:53:05 +00:00
Simplify querify
This commit is contained in:
parent
fbf48824ae
commit
39fe42cf6b
2 changed files with 5 additions and 5 deletions
|
@ -1746,19 +1746,19 @@ func sha1(in interface{}) (string, error) {
|
||||||
return hex.EncodeToString(hash[:]), nil
|
return hex.EncodeToString(hash[:]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// querify converts the given parameters into a url.Values object
|
// querify encodes the given parameters “URL encoded” form ("bar=baz&foo=quux") sorted by key.
|
||||||
func querify(params ...interface{}) (url.Values, error) {
|
func querify(params ...interface{}) (string, error) {
|
||||||
qs := url.Values{}
|
qs := url.Values{}
|
||||||
vals, err := dictionary(params...)
|
vals, err := dictionary(params...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return url.Values{}, fmt.Errorf("querify keys must be strings")
|
return "", fmt.Errorf("querify keys must be strings")
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, value := range vals {
|
for name, value := range vals {
|
||||||
qs.Add(name, url.QueryEscape(fmt.Sprintf("%v", value)))
|
qs.Add(name, url.QueryEscape(fmt.Sprintf("%v", value)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return qs, nil
|
return qs.Encode(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -103,7 +103,7 @@ modBool: {{modBool 15 3}}
|
||||||
mul: {{mul 2 3}}
|
mul: {{mul 2 3}}
|
||||||
plainify: {{ plainify "Hello <strong>world</strong>, gophers!" }}
|
plainify: {{ plainify "Hello <strong>world</strong>, gophers!" }}
|
||||||
pluralize: {{ "cat" | pluralize }}
|
pluralize: {{ "cat" | pluralize }}
|
||||||
querify: {{ (querify "foo" 1 "bar" 2 "baz" "with spaces").Encode | safeHTML }}
|
querify: {{ (querify "foo" 1 "bar" 2 "baz" "with spaces") | safeHTML }}
|
||||||
readDir: {{ range (readDir ".") }}{{ .Name }}{{ end }}
|
readDir: {{ range (readDir ".") }}{{ .Name }}{{ end }}
|
||||||
readFile: {{ readFile "README.txt" }}
|
readFile: {{ readFile "README.txt" }}
|
||||||
relURL 1: {{ "http://gohugo.io/" | relURL }}
|
relURL 1: {{ "http://gohugo.io/" | relURL }}
|
||||||
|
|
Loading…
Add table
Reference in a new issue