// linksexp -- Texinfo/XBEL/OPML/urls autogeneration from recfile bookmark // Copyright (C) 2021-2024 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, version 3 of the License. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . package main import ( "encoding/xml" "os" "strings" ) type Outline struct { Type string `xml:"type,attr"` Text string `xml:"text,attr"` XmlUrl string `xml:"xmlUrl,attr"` HtmlUrl string `xml:"htmlUrl,attr"` Category string `xml:"category,attr,omitempty"` } type OPML struct { XMLName xml.Name `xml:"opml"` Version string `xml:"version,attr"` Head string `xml:"head"` Outlines []Outline `xml:"body>outline"` } func opml(data []map[string][]string) { outlines := make([]Outline, 0, len(data)) for _, ent := range data { for _, feed := range ent["Feed"] { outlines = append(outlines, Outline{ Type: "rss", Text: ent["Title"][0], HtmlUrl: ent["URL"][0], XmlUrl: feed, Category: strings.Join(ent["Category"], ","), }) } } x := OPML{Version: "2.0", Outlines: outlines} out, err := xml.MarshalIndent(&x, "", " ") if err != nil { panic(err) } os.Stdout.WriteString("\n") os.Stdout.Write(out) }