Browse Source

pkg/template: fix Gravatar URLs are badly generated (#5157)

pull/5181/head
Unknwon 7 years ago
parent
commit
5c2de3a9ea
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 2
      gogs.go
  2. 1
      pkg/template/template.go
  3. 8
      pkg/tool/tool.go
  4. 2
      templates/.VERSION
  5. 4
      templates/user/profile.tmpl

2
gogs.go

@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/pkg/setting" "github.com/gogits/gogs/pkg/setting"
) )
const APP_VER = "0.11.45.0416" const APP_VER = "0.11.46.0418"
func init() { func init() {
setting.AppVer = APP_VER setting.AppVer = APP_VER

1
pkg/template/template.go

@ -61,6 +61,7 @@ func NewFuncMap() []template.FuncMap {
return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms" return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms"
}, },
"AvatarLink": tool.AvatarLink, "AvatarLink": tool.AvatarLink,
"AppendAvatarSize": tool.AppendAvatarSize,
"Safe": Safe, "Safe": Safe,
"Sanitize": bluemonday.UGCPolicy().Sanitize, "Sanitize": bluemonday.UGCPolicy().Sanitize,
"Str2html": Str2html, "Str2html": Str2html,

8
pkg/tool/tool.go

@ -207,6 +207,14 @@ func AvatarLink(email string) (url string) {
return url return url
} }
// AppendAvatarSize appends avatar size query parameter to the URL in the correct format.
func AppendAvatarSize(url string, size int) string {
if strings.Contains(url, "?") {
return url + "&s=" + com.ToStr(size)
}
return url + "?s=" + com.ToStr(size)
}
// Seconds-based time units // Seconds-based time units
const ( const (
Minute = 60 Minute = 60

2
templates/.VERSION

@ -1 +1 @@
0.11.45.0416 0.11.46.0418

4
templates/user/profile.tmpl

@ -6,11 +6,11 @@
<div class="ui card"> <div class="ui card">
{{if eq .LoggedUserName .Owner.Name}} {{if eq .LoggedUserName .Owner.Name}}
<a class="image poping up" href="{{AppSubURL}}/user/settings/avatar" id="profile-avatar" data-content="{{.i18n.Tr "user.change_avatar"}}" data-variation="inverted tiny" data-position="bottom center"> <a class="image poping up" href="{{AppSubURL}}/user/settings/avatar" id="profile-avatar" data-content="{{.i18n.Tr "user.change_avatar"}}" data-variation="inverted tiny" data-position="bottom center">
<img src="{{.Owner.RelAvatarLink}}?s=290" title="{{.Owner.Name}}"/> <img src="{{AppendAvatarSize .Owner.RelAvatarLink 290}}" title="{{.Owner.Name}}"/>
</a> </a>
{{else}} {{else}}
<span class="image"> <span class="image">
<img src="{{.Owner.RelAvatarLink}}?s=290" title="{{.Owner.Name}}"/> <img src="{{AppendAvatarSize .Owner.RelAvatarLink 290}}" title="{{.Owner.Name}}"/>
</span> </span>
{{end}} {{end}}
<div class="content"> <div class="content">

Loading…
Cancel
Save