summaryrefslogtreecommitdiff
path: root/gemini/gemtext/sub.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-08-25 20:46:28 -0600
committertjpcc <tjp@ctrl-c.club>2023-08-26 09:26:23 -0600
commit4b42fce53b80c8eb1796c4fb4c3966fb4c759677 (patch)
tree5f99d8c99ba24e00b354de9402c7c8ba8276ea9a /gemini/gemtext/sub.go
parent4c4dba9ba1e91ab44fcd21c50c6df62a19cfd9e1 (diff)
GmisubToAtom: update docs and names, add tests
Diffstat (limited to 'gemini/gemtext/sub.go')
-rw-r--r--gemini/gemtext/sub.go34
1 files changed, 18 insertions, 16 deletions
diff --git a/gemini/gemtext/sub.go b/gemini/gemtext/sub.go
index a99bed2..1247643 100644
--- a/gemini/gemtext/sub.go
+++ b/gemini/gemtext/sub.go
@@ -10,16 +10,28 @@ import (
"time"
)
-type gemSub struct {
+// GmisubToAtom converts a gemini document to Atom format.
+//
+// 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)
+ }
+ return `<?xml version="1.0" encoding="utf-8"?>` + "\n" + buf.String()
+}
+
+type gmiSub struct {
ID template.URL
Title string
Subtitle string
Updated string
- Entries []gemSubEntry
+ Entries []gmiSubEntry
}
-type gemSubEntry struct {
+type gmiSubEntry struct {
ID template.URL
Updated string
Title string
@@ -27,8 +39,8 @@ type gemSubEntry struct {
var linkElemRE = regexp.MustCompile(`(\d{4})-([0-1]\d)-([0-3]\d)`)
-func parseGemSub(doc Document, location *url.URL) *gemSub {
- sub := &gemSub{ID: template.URL(location.String())}
+func parseGemSub(doc Document, location *url.URL) *gmiSub {
+ sub := &gmiSub{ID: template.URL(location.String())}
updated := time.Time{}
for i, line := range doc {
@@ -75,7 +87,7 @@ func parseGemSub(doc Document, location *url.URL) *gemSub {
entryUpdated := time.Date(year, time.Month(month), day, 12, 0, 0, 0, time.UTC)
entryTitle := strings.TrimLeft(strings.TrimPrefix(strings.TrimLeft(label[10:], " \t"), "-"), " \t")
- sub.Entries = append(sub.Entries, gemSubEntry{
+ sub.Entries = append(sub.Entries, gmiSubEntry{
ID: template.URL(line.(LinkLine).URL()),
Updated: entryUpdated.Format(time.RFC3339),
Title: entryTitle,
@@ -91,16 +103,6 @@ func parseGemSub(doc Document, location *url.URL) *gemSub {
return sub
}
-func GemsubToAtom(doc Document, location url.URL) string {
- buf := &bytes.Buffer{}
- if err := atomTmpl.Execute(buf, parseGemSub(doc, &location)); err != nil {
- panic(err)
- }
- return `<?xml version="1.0" encoding="utf-8"?>` + "\n" + buf.String()
-}
-
-
-
var atomTmpl = template.Must(template.New("atom").Parse(`
<feed xmlns="http://www.w3.org/2005/Atom">
<id>{{.ID}}</id>