Browse Source

fix: Include type for OPML subscriptions

As per [OPML 2.0 specification]:

> Each sub-element of the body of the OPML document is a node of type rss or an outline element that contains nodes of type rss.

> Required attributes: type, text, xmlUrl.

[OPML 2.0 specification]: http://opml.org/spec2.opml#subscriptionLists
Jan Tojnar 2 years ago
parent
commit
074393d3bf
1 changed files with 17 additions and 0 deletions
  1. 17 0
      internal/reader/opml/opml.go

+ 17 - 0
internal/reader/opml/opml.go

@@ -34,6 +34,23 @@ type opmlOutline struct {
 	Outlines opmlOutlineCollection `xml:"outline,omitempty"`
 }
 
+func (outline opmlOutline) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
+	type opmlOutlineXml opmlOutline
+
+	outlineType := ""
+	if outline.IsSubscription() {
+		outlineType = "rss"
+	}
+
+	return e.EncodeElement(struct {
+		opmlOutlineXml
+		Type string `xml:"type,attr,omitempty"`
+	}{
+		opmlOutlineXml: opmlOutlineXml(outline),
+		Type:           outlineType,
+	}, start)
+}
+
 func (o *opmlOutline) IsSubscription() bool {
 	return strings.TrimSpace(o.FeedURL) != ""
 }