Skip to content

Commit

Permalink
Merge pull request #31 from gilmaimon/iconed-badges
Browse files Browse the repository at this point in the history
implement image in badges
  • Loading branch information
gilmaimon authored Jul 28, 2024
2 parents 4ad7744 + ba72aa7 commit 47c4d5e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Project Specific
tmp/
.idea/

# Logs
#logs
Expand Down
18 changes: 16 additions & 2 deletions server-v2/badges/svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package badges
import (
"github.com/essentialkaos/go-badge"
"server/libraries"
"strings"
)

type Generator struct {
Expand All @@ -20,9 +21,22 @@ func NewGenerator() (*Generator, error) {
}

func (g *Generator) GenerateBadge(library *libraries.ArduinoLibrary) []byte {
return g.badgeGenerator.GenerateFlat("Library Manager", library.Name+" "+library.Version, "#00C129")
return g.generateBadge(library.Name+" "+library.Version, "#00C129")
}

func (g *Generator) GenerateNotFoundBadge(libraryName string) []byte {
return g.badgeGenerator.GenerateFlat("Library Manager", libraryName, "#A2A2A2")
return g.generateBadge(libraryName, "#A2A2A2")
}

func (g *Generator) generateBadge(content string, color string) []byte {
label := "ZXOLibrary Manager"
badgeString := string(g.badgeGenerator.GenerateFlat(label, content, color))

// spacing
badgeString = strings.Replace(badgeString, "ZXO", "    ", 4)

// insert arduino image before svg enclosing
badgeString = strings.Replace(badgeString, "</svg>", `<image xmlns="http://www.w3.org/2000/svg" x="6" y="1" width="18" height="18" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAAA3CAYAAAD6+O8NAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH4wEKDB43az9p7AAAAvhJREFUeNrtW82O2jAQtk0RHGiQckEFqX2BvkHPfZCqfZXtY1TafYBeetu9rkR7Qa3ErQfUleAWkzhIsFJI9pSKUiC245/xar4TQvGM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