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:
Michael McLoughlin
2022-04-18 00:49:52 -07:00
committed by GitHub
parent 1cbd35f134
commit 3d25f4574c
5 changed files with 57 additions and 36 deletions

View File

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

View File

@@ -1,6 +1,6 @@
# Adopters
{{ range .Packages.Ranked }}
{{ avatar .Repository.Owner }} [{{ .Repository.Owner }} / **{{ .Repository.Name }}**]({{ .Repository.URL }})
{{ avatar .Repository.Owner 28 }} [{{ .Repository.Owner }} / **{{ .Repository.Name }}**]({{ .Repository.URL }})
{{- if .SubPackage }} / **{{ .SubPackage}}**{{ end }}
{{ .Metadata.Description }}

View File

@@ -107,7 +107,7 @@ Popular projects using `avo`:
{{ range .Packages.Top 10 -}}
{{ if lt .Metadata.Stars 100 }}{{break}}{{ end -}}
{{ avatar .Repository.Owner }} [{{ .Repository.Owner }} / **{{ .Repository.Name }}**]({{ .Repository.URL }})
{{ avatar .Repository.Owner 24 }} [{{ .Repository.Owner }} / **{{ .Repository.Name }}**]({{ .Repository.URL }})
{{- if .SubPackage }} / **{{ .SubPackage}}**{{ end }}
:star: {{ .Metadata.Stars }}
> {{ .Metadata.Description }}