Archived
1
0

Adds a function to find all categories

This commit is contained in:
Jip J. Dekker 2016-04-13 20:17:14 +02:00
parent 502bff67dd
commit cb01d278b3

View File

@ -18,6 +18,7 @@ import (
"os"
"os/exec"
"path/filepath"
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/alecthomas/template"
@ -58,6 +59,7 @@ var bookTempl = `
func MakeBook(path string, opts *settings.Settings) {
// Everything needs to be compiled
CompileDir(path, opts)
fmt.Println(scoreCategories(&scores))
// Compile the book template
var templ = template.Must(template.New("songBook").Parse(bookTempl))
@ -97,3 +99,19 @@ func MakeBook(path string, opts *settings.Settings) {
err = os.Remove(texPath)
helpers.Check(err, "could not remove songbook latex template")
}
// scoreCategories returns a slice of all categories used
// in the given slice of scores
func scoreCategories(scores *[]settings.Score) []string {
catMap := make(map[string]struct{})
for i := range *scores {
for _, cat := range (*scores)[i].Categories {
catMap[cat] = struct{}{}
}
}
categories := make([]string, 0, len(catMap))
for cat := range catMap {
categories = append(categories, cat)
}
return categories
}