nandi/gleanpublic Fork 0
222591d
Commits
Clone
git clone https://git.rickub.com/nandi/glean.git
git clone ssh://git@rickub.com/nandi/glean.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Group OPML feeds by category in exportUnverified

Julien Robert committed 2026-04-22T18:00:33+02:00 Browse files
222591d parent: 1aed63a
modified internal/feed/opml.go +28 -1
@@ -104,6 +104,8 @@ func GenerateOPML(feeds []FeedURL, title string) ([]byte, error) {
104104 }
105105 opml.Head.Title = title
106106
107+ categoryMap := make(map[string][]Outline)
108+ var categories []string
107109 for _, f := range feeds {
108110 outline := Outline{
109111 Text: f.Title,
@@ -111,7 +113,23 @@ func GenerateOPML(feeds []FeedURL, title string) ([]byte, error) {
111113 XMLURL: f.URL,
112114 HTMLURL: f.SiteURL,
113115 }
114- opml.Body.Outlines = append(opml.Body.Outlines, outline)
116+ if f.Category != "" {
117+ categoryMap[f.Category] = append(categoryMap[f.Category], outline)
118+ if !contains(categories, f.Category) {
119+ categories = append(categories, f.Category)
120+ }
121+ } else {
122+ opml.Body.Outlines = append(opml.Body.Outlines, outline)
123+ }
124+ }
125+
126+ for _, cat := range categories {
127+ parent := Outline{
128+ Text: cat,
129+ Title: cat,
130+ Outlines: categoryMap[cat],
131+ }
132+ opml.Body.Outlines = append(opml.Body.Outlines, parent)
115133 }
116134
117135 var buf bytes.Buffer
@@ -125,3 +143,12 @@ func GenerateOPML(feeds []FeedURL, title string) ([]byte, error) {
125143
126144 return buf.Bytes(), nil
127145 }
146+
147+func contains(slice []string, s string) bool {
148+ for _, v := range slice {
149+ if v == s {
150+ return true
151+ }
152+ }
153+ return false
154+}
@@ -104,6 +104,8 @@ func GenerateOPML(feeds []FeedURL, title string) ([]byte, error) {
104 }104 }
105 opml.Head.Title = title105 opml.Head.Title = title
106 106
107+ categoryMap := make(map[string][]Outline)
108+ var categories []string
107 for _, f := range feeds {109 for _, f := range feeds {
108 outline := Outline{110 outline := Outline{
109 Text: f.Title,111 Text: f.Title,
@@ -111,7 +113,23 @@ func GenerateOPML(feeds []FeedURL, title string) ([]byte, error) {
111 XMLURL: f.URL,113 XMLURL: f.URL,
112 HTMLURL: f.SiteURL,114 HTMLURL: f.SiteURL,
113 }115 }
114- opml.Body.Outlines = append(opml.Body.Outlines, outline)116+ if f.Category != "" {
117+ categoryMap[f.Category] = append(categoryMap[f.Category], outline)
118+ if !contains(categories, f.Category) {
119+ categories = append(categories, f.Category)
120+ }
121+ } else {
122+ opml.Body.Outlines = append(opml.Body.Outlines, outline)
123+ }
124+ }
125+
126+ for _, cat := range categories {
127+ parent := Outline{
128+ Text: cat,
129+ Title: cat,
130+ Outlines: categoryMap[cat],
131+ }
132+ opml.Body.Outlines = append(opml.Body.Outlines, parent)
115 }133 }
116 134
117 var buf bytes.Buffer135 var buf bytes.Buffer
@@ -125,3 +143,12 @@ func GenerateOPML(feeds []FeedURL, title string) ([]byte, error) {
125 143
126 return buf.Bytes(), nil144 return buf.Bytes(), nil
127 }145 }
146+
147+func contains(slice []string, s string) bool {
148+ for _, v := range slice {
149+ if v == s {
150+ return true
151+ }
152+ }
153+ return false
154+}
modified internal/server/feeds_handler.go +3 -2
@@ -277,8 +277,9 @@ func (s *Server) handleOPMLDownload(w http.ResponseWriter, r *http.Request) {
277277 var feedURLs []feed.FeedURL
278278 for _, sub := range subs {
279279 feedURLs = append(feedURLs, feed.FeedURL{
280- URL: sub.FeedURL,
281- Title: sub.FeedTitle,
280+ URL: sub.FeedURL,
281+ Title: sub.FeedTitle,
282+ Category: sub.Category.String,
282283 })
283284 }
284285
@@ -277,8 +277,9 @@ func (s *Server) handleOPMLDownload(w http.ResponseWriter, r *http.Request) {
277 var feedURLs []feed.FeedURL277 var feedURLs []feed.FeedURL
278 for _, sub := range subs {278 for _, sub := range subs {
279 feedURLs = append(feedURLs, feed.FeedURL{279 feedURLs = append(feedURLs, feed.FeedURL{
280- URL: sub.FeedURL,280+ URL: sub.FeedURL,
281- Title: sub.FeedTitle,281+ Title: sub.FeedTitle,
282+ Category: sub.Category.String,
282 })283 })
283 }284 }
284 285