sync: parse complex AUTHORS.txt as described in README

This commit is contained in:
nemunaire 2018-08-19 22:40:08 +02:00 committed by Pierre-Olivier Mercier
parent 2a941a4fc7
commit da2a88a3a6
3 changed files with 17 additions and 2 deletions

View file

@ -3,6 +3,7 @@ package sync
import (
"fmt"
"path"
"regexp"
"strings"
"srs.epita.fr/fic-server/libfic"
@ -32,7 +33,17 @@ func getAuthors(i Importer, tname string) ([]string, error) {
if authors, err := getFileContent(i, path.Join(tname, "AUTHORS.txt")); err != nil {
return nil, err
} else {
return strings.Split(strings.TrimSpace(authors), "\n"), nil
var ret []string
re := regexp.MustCompile("^([^<]+)(?: +<(.*)>)?$")
for _, a := range strings.Split(strings.TrimSpace(authors), "\n") {
grp := re.FindStringSubmatch(a)
if len(grp) < 2 || grp[2] == "" {
ret = append(ret, a)
} else {
ret = append(ret, fmt.Sprintf("<a href=\"%s\">%s</a>", grp[2], grp[1]))
}
}
return ret, nil
}
}