summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--repo.go7
-rw-r--r--templates.go17
-rw-r--r--templates/ref.gophermap10
3 files changed, 25 insertions, 9 deletions
diff --git a/repo.go b/repo.go
index 938bcc9..0805913 100644
--- a/repo.go
+++ b/repo.go
@@ -216,12 +216,7 @@ func (r Readme) GeminiEscapedContents() string {
}
func (r Readme) GopherEscapedContents(selector, host, port string) string {
- trailer := "\t"+selector+"\t"+host+"\t"+port+"\r\n"
- lines := strings.Split(r.RawContents, "\n")
- for i := range lines {
- lines[i] = "i"+strings.TrimRight(strings.ReplaceAll(lines[i], "\t", " "), "\r\n") + trailer
- }
- return strings.Join(lines, "")
+ return gopherRawtext(selector, host, port, r.RawContents)
}
func (r *Repository) Readme(ctx context.Context, ref string) (*Readme, error) {
diff --git a/templates.go b/templates.go
index 4c226f6..ff45997 100644
--- a/templates.go
+++ b/templates.go
@@ -2,7 +2,9 @@ package syw
import (
"embed"
+ "fmt"
"net/url"
+ "strings"
"text/template"
)
@@ -18,7 +20,8 @@ var (
gopherTemplate = template.Must(
template.New("gopher").Funcs(template.FuncMap{
"combine": gopherCombine,
- "join": gopherJoin,
+ "join": gopherJoin,
+ "rawtext": gopherRawtext,
}).ParseFS(
gopherTemplateFS,
"templates/*.gophermap",
@@ -32,6 +35,7 @@ func gopherCombine(base string, relative ...string) (string, error) {
if err != nil {
return "", err
}
+ fmt.Println("combining", base, relative)
for _, rel := range relative {
ru, err := url.Parse(rel)
@@ -41,7 +45,7 @@ func gopherCombine(base string, relative ...string) (string, error) {
bu = bu.ResolveReference(ru)
}
- return bu.String(), nil
+ return bu.Path, nil
}
func gopherJoin(base string, relative ...string) (string, error) {
@@ -53,6 +57,15 @@ func gopherJoin(base string, relative ...string) (string, error) {
return bu.JoinPath(relative...).Path, nil
}
+func gopherRawtext(selector, host, port, text string) string {
+ trailer := "\t" + selector + "\t" + host + "\t" + port + "\r\n"
+ lines := strings.Split(text, "\n")
+ for i := range lines {
+ lines[i] = "i" + strings.TrimRight(strings.ReplaceAll(lines[i], "\t", " "), "\r\n") + trailer
+ }
+ return strings.Join(lines, "")
+}
+
func addTemplates(base *template.Template, additions *template.Template) (*template.Template, error) {
base, err := base.Clone()
if err != nil {
diff --git a/templates/ref.gophermap b/templates/ref.gophermap
index 3e8d6f9..c7de102 100644
--- a/templates/ref.gophermap
+++ b/templates/ref.gophermap
@@ -15,7 +15,7 @@ i {{$.Selector}} {{$.Host}} {{$.Port}}
{{ if ne .Parents nil -}}
0🔩 Full Diff {{join $.Selector "../../diff" .ParentHash .Hash}} {{$.Host}} {{$.Port}}
{{ else -}}
-0🔩 Full Diff {{combine $.Selector "../diff/4b825dc642cb6eb9a060e54bf8d69288fbee4904" .Hash}} {{$.Host}} {{$.Port}}
+0🔩 Full Diff {{join $.Selector ".." ".." "diff" "4b825dc642cb6eb9a060e54bf8d69288fbee4904" .Hash}} {{$.Host}} {{$.Port}}
{{ end -}}
{{ range .Parents -}}
1👤 Parent {{slice . 0 8}} {{combine $.Selector .}} {{$.Host}} {{$.Port}}
@@ -30,5 +30,13 @@ i {{$.Selector}} {{$.Host}} {{$.Port}}
i {{$.Selector}} {{$.Host}} {{$.Port}}
iAuthored by {{.AuthorName}}<{{.AuthorEmail}}> on {{.AuthorDate.Format "Mon Jan _2 15:04:05 MST 2006"}} {{$.Selector}} {{$.Host}} {{$.Port}}
iCommitted by {{.CommitterName}}<{{.CommitterEmail}}> on {{.CommitDate.Format "Mon Jan _2 15:04:05 MST 2006"}} {{$.Selector}} {{$.Host}} {{$.Port}}
+i {{$.Selector}} {{$.Host}} {{$.Port}}
+{{ if eq .Parents nil -}}
+{{.Repo.Diffstat $.Ctx "4b825dc642cb6eb9a060e54bf8d69288fbee4904" .Hash | rawtext $.Selector $.Host $.Port }}
+{{ else -}}
+{{ with index .Parents 0 -}}
+{{$.Repo.Diffstat $.Ctx . $.Params.ref | rawtext $.Selector $.Host $.Port }}
+{{ end -}}
+{{ end -}}
{{ end -}}
.