]> Sergey Matveev's repositories - linksexp.git/blobdiff - main.go
Unify copyright comment format
[linksexp.git] / main.go
diff --git a/main.go b/main.go
index 0657c0a12783583a30ffd98c156a0d2b1247790a..5681d3f02b024e8dca187b3ce476ef19b3085d5d 100644 (file)
--- a/main.go
+++ b/main.go
@@ -1,19 +1,17 @@
-/*
-linksexp -- Texinfo/XBEL/OPML autogeneration from recfile bookmark
-Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
-
-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 <http://www.gnu.org/licenses/>.
-*/
+// linksexp -- Texinfo/XBEL/OPML/urls autogeneration from recfile bookmark
+// Copyright (C) 2021-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// 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 <http://www.gnu.org/licenses/>.
 
 package main
 
@@ -40,9 +38,35 @@ func (a ByTitle) Less(i, j int) bool {
 func main() {
        doXBEL := flag.Bool("xbel", false, "Make XBEL")
        doOPML := flag.Bool("opml", false, "Make OPML")
+       doURLS := flag.Bool("urls", false, "Make newsboat urls")
        flag.Parse()
 
        r := recfile.NewReader(os.Stdin)
+
+       if *doURLS {
+               for {
+                       m, err := r.NextMapWithSlice()
+                       if err == io.EOF {
+                               break
+                       }
+                       if err != nil {
+                               panic(err)
+                       }
+                       if m["%rec"] != nil {
+                               continue
+                       }
+                       sort.Strings(m["Category"])
+                       cats := strings.Join(m["Category"], " ")
+                       for _, f := range m["Feed"] {
+                               if strings.HasPrefix(f, "gemini://") {
+                                       f = "https://gemini/" + f
+                               }
+                               fmt.Println(f, cats)
+                       }
+               }
+               os.Exit(0)
+       }
+
        if *doOPML {
                data := make([]map[string][]string, 0)
                for {
@@ -98,10 +122,19 @@ func main() {
        }
 
        fmt.Println("Updated:", time.Now().Format(time.RFC3339))
-       fmt.Println("@table @strong")
+
+       fmt.Println("@menu")
+       fmt.Println("Categories:")
+       for _, cat := range cats {
+               fmt.Printf("* %s (%d items): LinksCat%s\n", cat, len(data[cat]), cat)
+       }
+       fmt.Println("@end menu")
+
        for _, cat := range cats {
-               fmt.Println("@item", cat)
+               fmt.Println("@node", "LinksCat"+cat)
+               fmt.Println("@section Links category:", cat)
                fmt.Println("@multitable @columnfractions .05 .8 .1 .05")
+               fmt.Println("@headitem @tab @tab Other categories @tab Feed URLs")
                ents := data[cat]
                for n, ent := range ents {
                        catsOther := make([]string, 0)
@@ -112,25 +145,33 @@ func main() {
                        }
                        var note string
                        if len(ent["Note"]) > 0 {
-                               note = "(" + ent["Note"][0] + ")"
+                               note = "(" + strings.Trim(ent["Note"][0], " \n") + ")"
                        }
                        fmt.Printf(
-                               "  @item %d @tab @url{%s, %s} %s @tab %s @tab\n",
-                               n, ent["URL"][0], ent["Title"][0], note,
+                               "  @item %d @tab @url{%s,, %s} %s @tab %s @tab\n",
+                               n,
+                               strings.ReplaceAll(ent["URL"][0], "@", "@@"),
+                               strings.ReplaceAll(ent["Title"][0], "@", "@@"),
+                               note,
                                strings.Join(catsOther, ", "),
                        )
                        switch feeds := ent["Feed"]; len(feeds) {
                        case 0:
                                fmt.Printf("    @emph{STATIC}\n")
                        case 1:
-                               fmt.Printf("    @url{%s, feed}\n", feeds[0])
+                               fmt.Printf(
+                                       "    @url{%s, feed}\n",
+                                       strings.ReplaceAll(feeds[0], "@", "@@"),
+                               )
                        default:
                                for i, feed := range feeds {
-                                       fmt.Printf("    @url{%s, feed%d}\n", feed, i)
+                                       fmt.Printf(
+                                               "    @url{%s, feed%d}\n",
+                                               strings.ReplaceAll(feed, "@", "@@"), i,
+                                       )
                                }
                        }
                }
                fmt.Println("@end multitable")
        }
-       fmt.Println("@end table")
 }