shithub: hugo

Download patch

ref: 076b618ff23206b075def741fbba1ffde22b72c3
parent: 10c2b41b85b92d2d6ef71dfef5955fd855afe0b0
author: Cyrill Schumacher <[email protected]>
date: Sun Feb 8 10:33:30 EST 2015

GetJson and GetCsv have now variadic URL parts so that you can submit pre or post parts of an URL. The parts will be joined to the final URL.

--- a/tpl/template_resources.go
+++ b/tpl/template_resources.go
@@ -173,9 +173,11 @@
 	return resGetLocal(url, hugofs.SourceFs)
 }
 
-// GetJson expects the url to a resource which can either be a local or a remote one.
+// GetJson expects one or n-parts of a URL to a resource which can either be a local or a remote one.
+// If you provide multiple parts they will be joined together to the final URL.
 // GetJson returns nil or parsed JSON to use in a short code.
-func GetJson(url string) interface{} {
+func GetJson(urlParts ...string) interface{} {
+	url := strings.Join(urlParts, "")
 	c, err := resGetResource(url)
 	if err != nil {
 		jww.ERROR.Printf("Failed to get json resource %s with error message %s", url, err)
@@ -204,11 +206,13 @@
 	return r.ReadAll()
 }
 
-// GetCsv expects the url to a resource which can either be a local or a remote one and the type
-// of the data separator which can be comma, semi-colon, pipe, but only one character.
+// GetCsv expects a data separator and one or n-parts of a URL to a resource which
+// can either be a local or a remote one.
+// The data separator can be a comma, semi-colon, pipe, etc, but only one character.
+// If you provide multiple parts for the URL they will be joined together to the final URL.
 // GetCsv returns nil or a slice slice to use in a short code.
-func GetCsv(url string, sep string) [][]string {
-
+func GetCsv(sep string, urlParts ...string) [][]string {
+	url := strings.Join(urlParts, "")
 	c, err := resGetResource(url)
 	if err != nil {
 		jww.ERROR.Printf("Failed to get csv resource %s with error message %s", url, err)