// 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" ) type Link struct { Href string `xml:"href,attr"` } type Feed struct { Owner string `xml:"owner,attr"` Link Link `xml:"link"` } type Bookmark struct { Href string `xml:"href,attr"` Title string `xml:"title"` Feeds []Feed `xml:"info>metadata,omitempty"` } type Folder struct { Title string `xml:"title"` Bookmarks []Bookmark `xml:"bookmark"` } type XBEL struct { XMLName xml.Name `xml:"xbel"` Version string `xml:"version,attr"` Folders []Folder `xml:"folder"` } func xbel(cats []string, data map[string][]map[string][]string) { folders := make([]Folder, 0, len(cats)) for _, cat := range cats { ents := data[cat] bs := make([]Bookmark, 0, len(ents)) for _, ent := range ents { b := Bookmark{Href: ent["URL"][0], Title: ent["Title"][0]} for _, url := range ent["Feed"] { b.Feeds = append(b.Feeds, Feed{Owner: "webfeed", Link: Link{url}}) } bs = append(bs, b) } folders = append(folders, Folder{Title: cat, Bookmarks: bs}) } x := XBEL{Version: "1.0", Folders: folders} out, err := xml.MarshalIndent(&x, "", " ") if err != nil { panic(err) } os.Stdout.WriteString("\n") os.Stdout.WriteString("\n") os.Stdout.Write(out) }