diff options
Diffstat (limited to 'templates.go')
-rw-r--r-- | templates.go | 17 |
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 { |