From 074393d3bfc59aa6cec29f5c1b9b4f5c3bdbc926 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Wed, 20 Dec 2023 07:08:53 +0100 Subject: [PATCH] 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 --- internal/reader/opml/opml.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/internal/reader/opml/opml.go b/internal/reader/opml/opml.go index 2f7147a0..8fe3af09 100644 --- a/internal/reader/opml/opml.go +++ b/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) != "" }