Example #1
0
func exportOpml(user content.User) (resp responseError) {
	resp = newResponse()

	o := parser.OpmlXml{
		Version: "1.1",
		Head:    parser.OpmlHead{Title: "Feed subscriptions of " + user.String() + " from readeef"},
	}

	if feeds := user.AllTaggedFeeds(); user.HasErr() {
		resp.err = user.Err()
		return
	} else {
		body := parser.OpmlBody{}
		for _, f := range feeds {
			d := f.Data()

			tags := f.Tags()
			category := make([]string, len(tags))
			for i, t := range tags {
				category[i] = string(t.Data().Value)
			}
			body.Outline = append(body.Outline, parser.OpmlOutline{
				Text:     d.Title,
				Title:    d.Title,
				XmlUrl:   d.Link,
				HtmlUrl:  d.SiteLink,
				Category: strings.Join(category, ","),
				Type:     "rss",
			})
		}

		o.Body = body
	}

	var b []byte
	if b, resp.err = xml.MarshalIndent(o, "", "    "); resp.err != nil {
		return
	}

	resp.val["opml"] = xml.Header + string(b)

	return
}