Merge pull request #12 from drExciter/url_encode_repos

URL encode repo variable in templates to support images with slash in…
This commit is contained in:
Roman Vynar 2018-07-04 15:58:02 +03:00 committed by GitHub
commit 0889821117
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 3 deletions

11
main.go
View File

@ -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}

View File

@ -48,7 +48,7 @@
<tbody>
{{range repo := repos}}
<tr>
<td><a href="/{{ namespace }}/{{ repo }}">{{ repo }}</a></td>
<td><a href="/{{ namespace }}/{{ repo |url_encoded_path }}">{{ repo }}</a></td>
<td>{{ tagCounts[namespace+"/"+repo] }}</td>
</tr>
{{end}}

View File

@ -8,7 +8,7 @@
{{if namespace != "library"}}
<li><a href="/{{ namespace }}">{{ namespace }}</a></li>
{{end}}
<li><a href="/{{ namespace }}/{{ repo }}">{{ repo }}</a></li>
<li><a href="/{{ namespace }}/{{ repo }}">{{ repo |url_decoded_path }}</a></li>
<li class="active">{{ tag }}</li>
</ol>
<table class="table table-striped table-bordered">

View File

@ -33,7 +33,7 @@
{{if namespace != "library"}}
<li><a href="/{{ namespace }}">{{ namespace }}</a></li>
{{end}}
<li class="active">{{ repo }}</li>
<li class="active">{{ repo |url_decoded_path }}</li>
</ol>
<table id="datatable" class="table table-striped table-bordered">