From 8aa9ac86f750b70ce5c456fcd55e6464c67e2953 Mon Sep 17 00:00:00 2001 From: drExciter Date: Thu, 21 Jun 2018 09:44:10 +0200 Subject: [PATCH] URL encode repo variable in templates to support images with slash in the name --- main.go | 11 +++++++++++ templates/repositories.html | 2 +- templates/tag_info.html | 2 +- templates/tags.html | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 7364637..06e04b5 100644 --- a/main.go +++ b/main.go @@ -122,6 +122,17 @@ func main() { } return res }) + view.AddGlobal("url_encoded_path", func(m interface{}) string { + return url.PathEscape(m.(string)) + + }) + view.AddGlobal("url_decoded_path", func(m interface{}) string { + res, err := url.PathUnescape(m.(string)) + if err != nil { + return m.(string) + } + return res + }) e := echo.New() e.Renderer = &template{View: view} diff --git a/templates/repositories.html b/templates/repositories.html index b49492a..c4c9150 100644 --- a/templates/repositories.html +++ b/templates/repositories.html @@ -48,7 +48,7 @@ {{range repo := repos}} - {{ repo }} + {{ repo }} {{ tagCounts[namespace+"/"+repo] }} {{end}} diff --git a/templates/tag_info.html b/templates/tag_info.html index e9b7cfa..e522383 100644 --- a/templates/tag_info.html +++ b/templates/tag_info.html @@ -8,7 +8,7 @@ {{if namespace != "library"}}
  • {{ namespace }}
  • {{end}} -
  • {{ repo }}
  • +
  • {{ repo |url_decoded_path }}
  • {{ tag }}
  • diff --git a/templates/tags.html b/templates/tags.html index c185578..fb24c70 100644 --- a/templates/tags.html +++ b/templates/tags.html @@ -33,7 +33,7 @@ {{if namespace != "library"}}
  • {{ namespace }}
  • {{end}} -
  • {{ repo }}
  • +
  • {{ repo |url_decoded_path }}