summaryrefslogtreecommitdiff
path: root/gemini/gemtext/sub.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-08-26 09:22:03 -0600
committertjpcc <tjp@ctrl-c.club>2023-08-26 09:26:23 -0600
commit343cdecabd46e2b505f3f92c8281753df1ee0fee (patch)
treeaa9cd52017e3d044f8ffe9e68fdcae0f21c9fdec /gemini/gemtext/sub.go
parent4b42fce53b80c8eb1796c4fb4c3966fb4c759677 (diff)
GmisubToAtom: output result to any io.Writer rather than return a string
Diffstat (limited to 'gemini/gemtext/sub.go')
-rw-r--r--gemini/gemtext/sub.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/gemini/gemtext/sub.go b/gemini/gemtext/sub.go
index 1247643..365d41b 100644
--- a/gemini/gemtext/sub.go
+++ b/gemini/gemtext/sub.go
@@ -3,6 +3,7 @@ package gemtext
import (
"bytes"
"html/template"
+ "io"
"net/url"
"regexp"
"strconv"
@@ -14,12 +15,17 @@ import (
//
// It identifies feed fields and entries according to the specification at
// gemini://gemini.circumlunar.space/docs/companion/subscription.gmi
-func GmisubToAtom(doc Document, location url.URL) string {
- buf := &bytes.Buffer{}
- if err := atomTmpl.Execute(buf, parseGemSub(doc, &location)); err != nil {
- panic(err)
+func GmisubToAtom(doc Document, location url.URL, out io.Writer) error {
+ if _, err := out.Write([]byte(`<?xml version="1.0" encoding="utf-8"?>`)); err != nil {
+ return err
}
- return `<?xml version="1.0" encoding="utf-8"?>` + "\n" + buf.String()
+ if _, err := out.Write([]byte{'\n'}); err != nil {
+ return err
+ }
+ if err := atomTmpl.Execute(out, parseGemSub(doc, &location)); err != nil {
+ return err
+ }
+ return nil
}
type gmiSub struct {