authors.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. const htmlFile = "gui/default/syncthing/core/aboutModalView.html"
  19. func main() {
  20. bs := readAll("AUTHORS")
  21. lines := strings.Split(string(bs), "\n")
  22. nameRe := regexp.MustCompile(`(.+?)\s+<`)
  23. authors := make([]string, 0, len(lines))
  24. for _, line := range lines {
  25. if m := nameRe.FindStringSubmatch(line); len(m) == 2 {
  26. authors = append(authors, " <li class=\"auto-generated\">"+m[1]+"</li>")
  27. }
  28. }
  29. sort.Strings(authors)
  30. replacement := strings.Join(authors, "\n")
  31. authorsRe := regexp.MustCompile(`(?s)id="contributor-list">.*?</ul>`)
  32. bs = readAll(htmlFile)
  33. bs = authorsRe.ReplaceAll(bs, []byte("id=\"contributor-list\">\n"+replacement+"\n </ul>"))
  34. if err := ioutil.WriteFile(htmlFile, bs, 0644); err != nil {
  35. log.Fatal(err)
  36. }
  37. }
  38. func readAll(path string) []byte {
  39. fd, err := os.Open(path)
  40. if err != nil {
  41. log.Fatal(err)
  42. }
  43. defer fd.Close()
  44. bs, err := ioutil.ReadAll(fd)
  45. if err != nil {
  46. log.Fatal(err)
  47. }
  48. return bs
  49. }