doc: format stars count (#281)
Use the k format for thousands, just like Github itself.
This commit is contained in:
committed by
GitHub
parent
224b6bf249
commit
4ca3d8a29f
@@ -10,6 +10,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
@@ -45,6 +46,7 @@ func mainerr() (err error) {
|
||||
"include": include,
|
||||
"snippet": snippet,
|
||||
"avatar": avatar,
|
||||
"stars": stars,
|
||||
})
|
||||
|
||||
// Load template.
|
||||
@@ -191,3 +193,12 @@ func avatar(owner string, size int) (string, error) {
|
||||
format := `<img src="%s" width="%d" height="%d" hspace="4" valign="middle" />`
|
||||
return fmt.Sprintf(format, src.String(), size, size), nil
|
||||
}
|
||||
|
||||
// stars formats a Github star count, rounding to thousands in the same style as Github.
|
||||
func stars(n int) string {
|
||||
if n < 1000 {
|
||||
return strconv.Itoa(n)
|
||||
}
|
||||
k := math.Round(float64(n)/100.0) / 10.0
|
||||
return strconv.FormatFloat(k, 'f', -1, 64) + "k"
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ Popular projects using `avo`:
|
||||
{{ range .Projects.Top 10 -}}
|
||||
{{ if lt .Metadata.Stars 100 }}{{break}}{{ end -}}
|
||||
{{ avatar .Repository.Owner 24 }} [{{ .Repository.Owner }} / **{{ .Repository.Name }}**]({{ .Repository.URL }})
|
||||
:star: {{ .Metadata.Stars }}
|
||||
:star: {{ stars .Metadata.Stars }}
|
||||
> {{ .Metadata.Description }}
|
||||
|
||||
{{ end -}}
|
||||
|
||||
Reference in New Issue
Block a user