doc: rounded avatars (#256)
Use weserv service to format avatars with circle masks. Make size configurable. Tweak readme and adopters pages. Updates #101
This commit is contained in:
committed by
GitHub
parent
1cbd35f134
commit
3d25f4574c
@@ -10,8 +10,10 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
@@ -166,7 +168,26 @@ func snippet(filename, start, end string) (string, error) {
|
||||
}
|
||||
|
||||
// avatar returns HTML for a Github user avatar.
|
||||
func avatar(owner string) (string, error) {
|
||||
format := `<img src="https://github.com/%s.png?size=24" width="24" height="24" hspace="4" valign="middle" />`
|
||||
return fmt.Sprintf(format, owner), nil
|
||||
func avatar(owner string, size int) (string, error) {
|
||||
// Origin avatar URL from Github.
|
||||
u := fmt.Sprintf("https://github.com/%s.png", owner)
|
||||
|
||||
// Use images.weserv.nl service to resize and apply circle mask.
|
||||
v := url.Values{}
|
||||
v.Set("url", u)
|
||||
v.Set("w", strconv.Itoa(size))
|
||||
v.Set("h", strconv.Itoa(size))
|
||||
v.Set("fit", "cover")
|
||||
v.Set("mask", "circle")
|
||||
v.Set("maxage", "7d")
|
||||
|
||||
src := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "images.weserv.nl",
|
||||
RawQuery: v.Encode(),
|
||||
}
|
||||
|
||||
// Build <img> tag.
|
||||
format := `<img src="%s" width="%d" height="%d" hspace="4" valign="middle" />`
|
||||
return fmt.Sprintf(format, src.String(), size, size), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user