diff --git a/example.md b/example.md
index 8c5c0eb742c679931b7cacb13d419e64e9411413..dbcbc5133864ea9b48de9b1d3be926009901a504 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 344efcab3bf3b5e1388d95237d1bbbbb00e3f62a..196dc94d5000f968230a1d9ac7f52bce36c25e5d 100644
--- a/parser.go
+++ b/parser.go
@@ -1,7 +1,6 @@
package main
import (
- "fmt"
"strconv"
"strings"
"time"
@@ -29,11 +28,6 @@ Provides []string // p
InstallIf []string // i
}
)
-
-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 8d84f2e684864cebc79d98effb421d48cdcf831e..bb8d5020633d21695dca5300b57d0142e3c34ab3 100644
--- a/template.go
+++ b/template.go
@@ -5,6 +5,7 @@ "errors"
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 @@ default:
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
+}