From 4a7e6b16af76404a45b27b297f208c941c348d53 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Fri, 26 Mar 2021 17:42:02 -0700 Subject: [PATCH] Add API card type --- resources/templates/cards/api.html | 35 ++++++++++++++++++++++++++++++ simpledash-sample.toml | 14 ++++++++++-- template.go | 6 +++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 resources/templates/cards/api.html diff --git a/resources/templates/cards/api.html b/resources/templates/cards/api.html new file mode 100644 index 0000000..7c85a25 --- /dev/null +++ b/resources/templates/cards/api.html @@ -0,0 +1,35 @@ +{{- $format := splitList "\n" (trim .Data.format) -}} +{{- $title := replace " " "" .Title -}} +
+ + {{if ne .Icon ""}} + {{template "icon" .Icon}}  + {{end}} + {{.Title}} + +
+
+

Loading...

+ {{range $_, $accessStr := $format}} + {{- $id := printf `%s_%s` $title (b64enc $accessStr) -}} +

+ {{end}} +
+{{if .Data.footer}} + +{{end}} + \ No newline at end of file diff --git a/simpledash-sample.toml b/simpledash-sample.toml index 8bb816d..7023970 100644 --- a/simpledash-sample.toml +++ b/simpledash-sample.toml @@ -1,7 +1,7 @@ title = "SimpleDash" theme = "dark" loginRequired = false -allowProxy = ["https://www.metaweather.com/"] +allowProxy = ["https://www.metaweather.com/", "https://ifconfig.co/json"] [session] name = "simpledash-session" @@ -12,6 +12,16 @@ allowProxy = ["https://www.metaweather.com/"] title = "Weather" data = {"woeid" = "2442047"} + [[users._public_.card]] + type = "api" + title = "Server IP (API card example)" + url = "https://ifconfig.co/json" + data = {"format" = """ +

${data.ip}

+ Country: ${data.country} (${data.country_iso}) + Time zone: ${data.time_zone} + """} + [users.admin] passwordHash = "$2a$10$w00dzQ1PP6nwXLhuzV2pFOUU6m8bcZXtDX3UVxpOYq3fTSwVMqPge" showPublic = true @@ -42,4 +52,4 @@ allowProxy = ["https://www.metaweather.com/"] type = "collection" title = "Science" icon = "ic:outline-science" - data = {"Google Scholar" = {"url" = "https://robinhood.com/", "target" = "sameTab"}} \ No newline at end of file + data = {"Google Scholar" = {"url" = "https://scholar.google.com/", "target" = "sameTab"}} \ No newline at end of file diff --git a/template.go b/template.go index 91ae0fe..87f8cdb 100644 --- a/template.go +++ b/template.go @@ -28,11 +28,17 @@ func wrapProxy(url string) string { return fmt.Sprint("/proxy/", b64url) } +// Wrap string in template.JS to unescape JS code +func unescapeJS(s string) template.JS { + return template.JS(s) +} + // Function to get template function map func getFuncMap() template.FuncMap { // Return function map with template functions return template.FuncMap{ "dyn_template": dynamicTemplate, "proxy": wrapProxy, + "unescJS": unescapeJS, } }