summaryrefslogtreecommitdiff
path: root/templates.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-09-17 16:52:47 -0600
committertjpcc <tjp@ctrl-c.club>2023-09-17 16:52:47 -0600
commitfd79efff7504853ab4b7070ee186f4b7a346d21d (patch)
treec3890df1ed1d27395251f2f927e02c156a2f3db6 /templates.go
parenta7ce20fee62a52794bf8bf940d0fd1f4134158b1 (diff)
fix diffs and add diffstats in gopher
Diffstat (limited to 'templates.go')
-rw-r--r--templates.go17
1 files changed, 15 insertions, 2 deletions
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 {