forked from progfay/shields-with-icon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (49 loc) · 1.16 KB
/
Copy pathmain.go
File metadata and controls
58 lines (49 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"image/color"
"log"
"net/url"
"os"
"strings"
"github.com/progfay/colorcontrast"
)
var (
white = color.White
black = color.Gray{Y: 34}
)
func formatShield(icon Icon) (string, error) {
color, err := hexToColor(icon.Hex)
if err != nil {
return "", err
}
var foreground, background string
if colorcontrast.CalcContrastRatio(white, *color) >= 2.5 {
foreground = colorToHex(white)
background = colorToHex(*color)
} else {
foreground = colorToHex(*color)
background = colorToHex(black)
}
return fmt.Sprintf("",
strings.ReplaceAll(strings.ReplaceAll(icon.Title, "[", "\\["), "]", "\\]"),
url.QueryEscape(icon.Title),
url.QueryEscape(background),
url.QueryEscape(icon.Title),
url.QueryEscape(foreground),
), nil
}
func main() {
icons, err := getIcons()
if err != nil {
log.Panicln(err)
}
for _, icon := range icons {
shield, err := formatShield(icon)
if err != nil {
log.Panicln(err)
}
fmt.Fprintln(os.Stdout, shield)
fmt.Fprintf(os.Stderr, "## %[1]s\n```markdown\n%[1]s\n```\n", shield)
}
}