gtx


Branch: develop

Author
thewhodidthis <thewhodidthis@fastmail.com>
Date
Jan. 31 '23 14:43:28
Commit
9269865922021021c41faf885a80d1c09158e9b3
Parent
8f77a680fb1953e5140bc7c9dfba6b6ff936a661
Changes
diff --git a/diff_parsers.go b/diff_parsers.go
deleted file mode 100644
index eac48ab..0000000
--- a/diff_parsers.go
+++ /dev/null
@@ -1,87 +0,0 @@
-package main
-
-import (
-	"fmt"
-	"html/template"
-	"regexp"
-	"strings"
-)
-
-// Match diff body @@ del, ins line numbers.
-var aline = regexp.MustCompile(`\-(.*?),`)
-var bline = regexp.MustCompile(`\+(.*?),`)
-
-// Match diff body keywords.
-var xline = regexp.MustCompile(`^(deleted|index|new|rename|similarity)`)
-
-// Helps target file specific diff blocks.
-var diffanchor = regexp.MustCompile(`b\/(.*?)$`)
-
-func diffbodyparser(d diff) template.HTML {
-	var results []string
-	feed := strings.Split(strings.TrimSuffix(template.HTMLEscapeString(d.Body), "\n"), "\n")
-
-	var a, b string
-
-	for _, line := range feed {
-		if strings.HasPrefix(line, "diff") {
-			line = diffanchor.ReplaceAllString(line, `b/<a id="$1">$1</a>`)
-			line = fmt.Sprintf("<strong>%s</strong>", line)
-		}
-
-		line = xline.ReplaceAllString(line, "<em>$1</em>")
-
-		if strings.HasPrefix(line, "@@") {
-			if a != "" && !strings.HasPrefix(a, "---") {
-				repl := fmt.Sprintf(`<a href="commit/%s/%s.html#L$1">-$1</a>,`, d.Parent, a)
-				line = aline.ReplaceAllString(line, repl)
-			}
-
-			if b != "" && !strings.HasPrefix(b, "+++") {
-				repl := fmt.Sprintf(`<a href="commit/%s/%s.html#L$1">+$1</a>,`, d.Commit.Hash, b)
-				line = bline.ReplaceAllString(line, repl)
-			}
-		}
-
-		if strings.HasPrefix(line, "---") {
-			a = strings.TrimPrefix(line, "--- a/")
-			line = fmt.Sprintf("<mark>%s</mark>", line)
-		} else if strings.HasPrefix(line, "-") {
-			line = fmt.Sprintf("<del>%s</del>", line)
-		}
-
-		if strings.HasPrefix(line, "+++") {
-			b = strings.TrimPrefix(line, "+++ b/")
-			line = fmt.Sprintf("<mark>%s</mark>", line)
-		} else if strings.HasPrefix(line, "+") {
-			line = fmt.Sprintf("<ins>%s</ins>", line)
-		}
-
-		results = append(results, line)
-	}
-
-	return template.HTML(strings.Join(results, "\n"))
-}
-
-func diffstatbodyparser(o overview) template.HTML {
-	var results []string
-	feed := strings.Split(strings.TrimSuffix(o.Body, "\n"), "\n")
-
-	for i, line := range feed {
-		if i < len(feed)-1 {
-			// Link files to corresponding diff.
-			columns := strings.Split(line, "|")
-			files := strings.Split(columns[0], "=>")
-
-			a := strings.TrimSpace(files[len(files)-1])
-			b := fmt.Sprintf(`<a href="commit/%s/diff-%s.html#%s">%s</a>`, o.Hash, o.Parent, a, a)
-			l := strings.LastIndex(line, a)
-
-			line = line[:l] + strings.Replace(line[l:], a, b, 1)
-		}
-
-		results = append(results, line)
-	}
-
-	return template.HTML(strings.Join(results, "\n"))
-}
diff --git a/flags.go b/flags.go
deleted file mode 100644
index 42b9b8b..0000000
--- a/flags.go
+++ /dev/null
@@ -1,19 +0,0 @@
-package main
-
-import "strings"
-
-// https://stackoverflow.com/questions/28322997/how-to-get-a-list-of-values-into-a-flag-in-golang/
-type manyflag []string
-
-func (f *manyflag) Set(value string) error {
-	// Make sure there are no duplicates.
-	if !contains(*f, value) {
-		*f = append(*f, value)
-	}
-
-	return nil
-}
-
-func (f *manyflag) String() string {
-	return strings.Join(*f, ", ")
-}
diff --git a/helper.go b/helper.go
index 67954e7..beb1236 100644
--- a/helper.go
+++ b/helper.go
@@ -1,6 +1,21 @@
 package main
 
-type void struct{}
+import (
+	"fmt"
+	"html/template"
+	"regexp"
+	"strings"
+)
+
+// Helps target file specific diff blocks.
+var diffanchor = regexp.MustCompile(`b\/(.*?)$`)
+
+// Match diff body @@ del, ins line numbers.
+var aline = regexp.MustCompile(`\-(.*?),`)
+var bline = regexp.MustCompile(`\+(.*?),`)
+
+// Match diff body keywords.
+var xline = regexp.MustCompile(`^(deleted|index|new|rename|similarity)`)
 
 // Helps decide if value contained in slice.
 // https://stackoverflow.com/questions/38654383/how-to-search-for-an-element-in-a-golang-slice
@@ -29,3 +44,72 @@ func dedupe(input []string) []string {
 
 	return list
 }
+
+func diffbodyparser(d diff) template.HTML {
+	var results []string
+	feed := strings.Split(strings.TrimSuffix(template.HTMLEscapeString(d.Body), "\n"), "\n")
+
+	var a, b string
+
+	for _, line := range feed {
+		if strings.HasPrefix(line, "diff") {
+			line = diffanchor.ReplaceAllString(line, `b/<a id="$1">$1</a>`)
+			line = fmt.Sprintf("<strong>%s</strong>", line)
+		}
+
+		line = xline.ReplaceAllString(line, "<em>$1</em>")
+
+		if strings.HasPrefix(line, "@@") {
+			if a != "" && !strings.HasPrefix(a, "---") {
+				repl := fmt.Sprintf(`<a href="commit/%s/%s.html#L$1">-$1</a>,`, d.Parent, a)
+				line = aline.ReplaceAllString(line, repl)
+			}
+
+			if b != "" && !strings.HasPrefix(b, "+++") {
+				repl := fmt.Sprintf(`<a href="commit/%s/%s.html#L$1">+$1</a>,`, d.Commit.Hash, b)
+				line = bline.ReplaceAllString(line, repl)
+			}
+		}
+
+		if strings.HasPrefix(line, "---") {
+			a = strings.TrimPrefix(line, "--- a/")
+			line = fmt.Sprintf("<mark>%s</mark>", line)
+		} else if strings.HasPrefix(line, "-") {
+			line = fmt.Sprintf("<del>%s</del>", line)
+		}
+
+		if strings.HasPrefix(line, "+++") {
+			b = strings.TrimPrefix(line, "+++ b/")
+			line = fmt.Sprintf("<mark>%s</mark>", line)
+		} else if strings.HasPrefix(line, "+") {
+			line = fmt.Sprintf("<ins>%s</ins>", line)
+		}
+
+		results = append(results, line)
+	}
+
+	return template.HTML(strings.Join(results, "\n"))
+}
+
+func diffstatbodyparser(o overview) template.HTML {
+	var results []string
+	feed := strings.Split(strings.TrimSuffix(o.Body, "\n"), "\n")
+
+	for i, line := range feed {
+		if i < len(feed)-1 {
+			// Link files to corresponding diff.
+			columns := strings.Split(line, "|")
+			files := strings.Split(columns[0], "=>")
+
+			a := strings.TrimSpace(files[len(files)-1])
+			b := fmt.Sprintf(`<a href="commit/%s/diff-%s.html#%s">%s</a>`, o.Hash, o.Parent, a, a)
+			l := strings.LastIndex(line, a)
+
+			line = line[:l] + strings.Replace(line[l:], a, b, 1)
+		}
+
+		results = append(results, line)
+	}
+
+	return template.HTML(strings.Join(results, "\n"))
+}
diff --git a/branch_filter.go b/parsers.go
similarity index 100%
rename from branch_filter.go
rename to parsers.go
diff --git a/types.go b/types.go
index 7966a44..1c3ea83 100644
--- a/types.go
+++ b/types.go
@@ -2,9 +2,12 @@ package main
 
 import (
 	"path/filepath"
+	"strings"
 	"time"
 )
 
+type void struct{}
+
 // Data is the generic content map passed on to the page template.
 type Data map[string]interface{}
 type page struct {
@@ -80,3 +83,19 @@ type author struct {
 	Email string
 	Name  string
 }
+
+// https://stackoverflow.com/questions/28322997/how-to-get-a-list-of-values-into-a-flag-in-golang/
+type manyflag []string
+
+func (f *manyflag) Set(value string) error {
+	// Make sure there are no duplicates.
+	if !contains(*f, value) {
+		*f = append(*f, value)
+	}
+
+	return nil
+}
+
+func (f *manyflag) String() string {
+	return strings.Join(*f, ", ")
+}