summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gemini/gemtext/sub.go34
-rw-r--r--gemini/gemtext/sub_test.go2
2 files changed, 19 insertions, 17 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>
diff --git a/gemini/gemtext/sub_test.go b/gemini/gemtext/sub_test.go
index 8bba682..26f98ed 100644
--- a/gemini/gemtext/sub_test.go
+++ b/gemini/gemtext/sub_test.go
@@ -51,7 +51,7 @@ func TestGemsubToAtom(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- xml := GemsubToAtom(doc, *loc)
+ xml := GmisubToAtom(doc, *loc)
if xml != test.output {
t.Fatal("mismatched output")
}