aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-03-31 21:18:58 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-03-31 21:18:58 +0200
commit66791d940bc60d004835307a86dd98a14cbc9553 (patch)
tree935f8fb7865bb9b4937b58134880f9dcae6eed0b
parenta46cf4152ac32d97e0ebd071b9eb1d3e42c7a493 (diff)
downloadapkdoc-66791d940bc60d004835307a86dd98a14cbc9553.tar.gz
apkdoc-66791d940bc60d004835307a86dd98a14cbc9553.tar.bz2
apkdoc-66791d940bc60d004835307a86dd98a14cbc9553.zip
feat: Provide the all fields to be used formatHEADmaster
-rw-r--r--example.md3
-rw-r--r--parser.go6
-rw-r--r--template.go13
3 files changed, 15 insertions, 7 deletions
diff --git a/example.md b/example.md
index 8c5c0eb..dbcbc51 100644
--- a/example.md
+++ b/example.md
@@ -3,6 +3,7 @@
{{ range $e := . }}
## {{ $e.Name }}
-{{ range $name, $value := ($e.Properties) }}- **{{$name}}**: {{ $value }}
+{{ range $name, $value := ($e.Properties) }}- **{{$name}}:** {{ $value }}
{{ end }}
+**Link:** {{Format $e "https://git.gabrielgio.me/apkbuilds/tree/apk/%{name}s?id=%{commit}s"}}
{{ end }}
diff --git a/parser.go b/parser.go
index 344efca..196dc94 100644
--- a/parser.go
+++ b/parser.go
@@ -1,7 +1,6 @@
package main
import (
- "fmt"
"strconv"
"strings"
"time"
@@ -30,11 +29,6 @@ type (
}
)
-func (e *Entry) FomartLink(format string) string {
- c := strings.Replace(*e.Commit, "-dirty", "", -1)
- return fmt.Sprintf(format, c, *e.Origin)
-}
-
func (e *Entry) Properties() map[string]string {
p := make(map[string]string)
diff --git a/template.go b/template.go
index 8d84f2e..bb8d502 100644
--- a/template.go
+++ b/template.go
@@ -5,6 +5,7 @@ import (
html "html/template"
"io"
"os"
+ "strings"
text "text/template"
)
@@ -16,6 +17,11 @@ var (
templateFunc = map[string]any{
"DerefI": func(i *int) int { return *i },
"DerefS": func(i *string) string { return *i },
+ "Format": func(e *Entry, format string) string {
+ p := e.Properties()
+ p["commit"] = strings.Replace(*e.Commit, "-dirty", "", -1)
+ return tsprintf(format, p)
+ },
}
)
@@ -43,3 +49,10 @@ func GetTemplate(templateType, filePath string) (Templater, error) {
return nil, errors.New("Invalid template type")
}
}
+
+func tsprintf(format string, params map[string]string) string {
+ for key, val := range params {
+ format = strings.Replace(format, "%{"+key+"}s", val, -1)
+ }
+ return format
+}