Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/awesome/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func runGenerate(args []string) error {
rm, known := meta.Repos[e.Repo]
title := "Stars not fetched yet"
if known {
title = fmt.Sprintf("%s has %d stars on GitHub", e.Repo, rm.Stars)
title = fmt.Sprintf("%s has %d %s on GitHub", e.Repo, rm.Stars, render.StarWord(rm.Stars))
}
pill := badge.Stars(render.StarsText(rm.Stars, known), title)
if err := os.WriteFile(filepath.Join(p.root, render.StarsPath(e.Repo)), pill, 0o644); err != nil {
Expand Down
11 changes: 10 additions & 1 deletion internal/render/readme.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,20 @@ func README(l *list.List, m *list.Metadata, now time.Time) []byte {
func item(r ranked) string {
alt := "new"
if r.known {
alt = FormatStars(r.stars) + " stars"
alt = FormatStars(r.stars) + " " + StarWord(r.stars)
}
return fmt.Sprintf(`<img src="%s" alt="%s" align="absmiddle"> [%s](%s) - %s`, StarsPath(r.entry.Repo), alt, r.entry.DisplayName(), r.entry.URL(), r.entry.Description)
}

// StarWord is the noun that follows a star count: "star" for exactly one,
// "stars" otherwise.
func StarWord(n int) string {
if n == 1 {
return "star"
}
return "stars"
}

// FormatStars renders 1234 as "1.2k" and 80123 as "80k".
func FormatStars(n int) string {
switch {
Expand Down
9 changes: 9 additions & 0 deletions internal/render/readme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ func TestFormatStars(t *testing.T) {
}
}

func TestStarWord(t *testing.T) {
cases := map[int]string{0: "stars", 1: "star", 2: "stars", 1000: "stars"}
for n, want := range cases {
if got := StarWord(n); got != want {
t.Errorf("StarWord(%d) = %q, want %q", n, got, want)
}
}
}

func TestSlugify(t *testing.T) {
cases := map[string]string{"Web Frameworks": "web-frameworks", "Web & HTTP": "web--http", "gRPC/RPC": "grpcrpc"}
for in, want := range cases {
Expand Down
Loading