authors.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (C) 2015 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at http://mozilla.org/MPL/2.0/.
  6. // +build ignore
  7. // Generates the list of contributors in gui/index.html based on contents of
  8. // AUTHORS.
  9. package main
  10. import (
  11. "io/ioutil"
  12. "log"
  13. "os"
  14. "regexp"
  15. "sort"
  16. "strings"
  17. )
  18. func main() {
  19. bs := readAll("AUTHORS")
  20. lines := strings.Split(string(bs), "\n")
  21. nameRe := regexp.MustCompile(`(.+?)\s+<`)
  22. authors := make([]string, 0, len(lines))
  23. for _, line := range lines {
  24. if m := nameRe.FindStringSubmatch(line); len(m) == 2 {
  25. authors = append(authors, " <li class=\"auto-generated\">"+m[1]+"</li>")
  26. }
  27. }
  28. sort.Strings(authors)
  29. replacement := strings.Join(authors, "\n")
  30. authorsRe := regexp.MustCompile(`(?s)id="contributor-list">.*?</ul>`)
  31. bs = readAll("gui/index.html")
  32. bs = authorsRe.ReplaceAll(bs, []byte("id=\"contributor-list\">\n"+replacement+"\n </ul>"))
  33. if err := ioutil.WriteFile("gui/index.html", bs, 0644); err != nil {
  34. log.Fatal(err)
  35. }
  36. }
  37. func readAll(path string) []byte {
  38. fd, err := os.Open(path)
  39. if err != nil {
  40. log.Fatal(err)
  41. }
  42. defer fd.Close()
  43. bs, err := ioutil.ReadAll(fd)
  44. if err != nil {
  45. log.Fatal(err)
  46. }
  47. return bs
  48. }