|
|
|
@ -5,12 +5,12 @@ import (
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io/fs"
|
|
|
|
|
"log"
|
|
|
|
|
"net/http"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
// "log"
|
|
|
|
|
"net/http"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"code.ndumas.com/ndumas/badges"
|
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
@ -30,7 +30,8 @@ func NewBadgeRenderer(fontDir string) (*BadgeRenderer, error) {
|
|
|
|
|
root := os.DirFS(fontDir)
|
|
|
|
|
err := fs.WalkDir(root, ".", func(path string, d fs.DirEntry, err error) error {
|
|
|
|
|
if strings.HasSuffix(path, ".ttf") {
|
|
|
|
|
br.Fonts[filepath.Base(path)] = path
|
|
|
|
|
absFont := filepath.Join(fontDir, path)
|
|
|
|
|
br.Fonts[filepath.Base(path)] = absFont
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
@ -133,18 +134,24 @@ func (br *BadgeRenderer) renderBadge(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
port int
|
|
|
|
|
fontsDir string
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
var (
|
|
|
|
|
port int
|
|
|
|
|
fontsDir string
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
flag.IntVar(&port, "port", 8484, "http listening port")
|
|
|
|
|
flag.StringVar(&fontsDir, "fonts", "fonts/", "directory containing ttf files")
|
|
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
|
|
br, err := NewBadgeRenderer(fontsDir)
|
|
|
|
|
absFontDir, err := filepath.Abs(fontsDir)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("error building absolute font dir path: %s\n", err)
|
|
|
|
|
}
|
|
|
|
|
log.Println("absFontDir:", absFontDir)
|
|
|
|
|
br, err := NewBadgeRenderer(absFontDir)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("couldn't create renderer", err)
|
|
|
|
|
return
|
|
|
|
|