]> Sergey Matveev's repositories - linksexp.git/commitdiff
txtar-ed SWG output support master
authorSergey Matveev <stargrave@stargrave.org>
Sun, 1 Jun 2025 15:12:20 +0000 (18:12 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 1 Jun 2025 15:12:20 +0000 (18:12 +0300)
README
go.mod
main.go
opml.go
swg.go [new file with mode: 0644]
xbel.go

diff --git a/README b/README
index d786a0492fd3ea101d203ef136fbe227aff3657e..07152dafec0308c3bdc85c916dcbb90367a8b623 100644 (file)
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-linksexp -- Texinfo/XBEL/OPML/urls autogeneration from recfile bookmark.
+linksexp -- Texinfo/XBEL/OPML/SWG/urls autogeneration from recfile bookmark.
 
 Given recfile (https://www.gnu.org/software/recutils/) bookmark file,
 this program can generate (export links):
@@ -6,4 +6,5 @@ this program can generate (export links):
 * either part of Texinfo source code output
 * or XBEL (http://xbel.sourceforge.net/, https://en.wikipedia.org/wiki/XBEL)
 * or OPML (http://dev.opml.org/, https://en.wikipedia.org/wiki/OPML)
+* or SWG (http://www.git.stargrave.org/?p=swg.git;a=blob;f=README)
 * or "urls" file for newsboat (https://newsboat.org/)
diff --git a/go.mod b/go.mod
index 91a50badb3affa66d016a19029a5754e07e7f976..7269adc29ef0198f60f10bf471c4b60a12227700 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -1,7 +1,5 @@
 module go.stargrave.org/linksexp
 
-go 1.21
-
-toolchain go1.22.5
+go 1.24.3
 
 require go.cypherpunks.su/recfile/v2 v2.0.0
diff --git a/main.go b/main.go
index 202d170698c676ccbcd616dd5f67dfcb8519ca8f..8078aa53811d7bce6e3c0152ba2b44a648f2482c 100644 (file)
--- a/main.go
+++ b/main.go
@@ -1,4 +1,4 @@
-// linksexp -- Texinfo/XBEL/OPML/urls autogeneration from recfile bookmark
+// linksexp -- Texinfo/XBEL/OPML/SWG/urls autogeneration from recfile bookmark
 // Copyright (C) 2021-2025 Sergey Matveev <stargrave@stargrave.org>
 //
 // This program is free software: you can redistribute it and/or modify
@@ -39,6 +39,7 @@ func main() {
        doXBEL := flag.Bool("xbel", false, "Make XBEL")
        doOPML := flag.Bool("opml", false, "Make OPML")
        doURLS := flag.Bool("urls", false, "Make newsboat urls")
+       doSWG := flag.Bool("swg", false, "Make SWG txtar")
        flag.Parse()
 
        r := recfile.NewReader(os.Stdin)
@@ -121,6 +122,11 @@ func main() {
                os.Exit(0)
        }
 
+       if *doSWG {
+               swg(cats, data)
+               os.Exit(0)
+       }
+
        fmt.Println("Updated:", time.Now().Format(time.RFC3339))
 
        fmt.Println("@menu")
diff --git a/opml.go b/opml.go
index a1a71d7fdb32a02e5100118b44b36124071b86ad..27b32754e2001c72b8358b2cee513f64f96e4e61 100644 (file)
--- a/opml.go
+++ b/opml.go
@@ -1,4 +1,4 @@
-// linksexp -- Texinfo/XBEL/OPML/urls autogeneration from recfile bookmark
+// linksexp -- Texinfo/XBEL/OPML/SWG/urls autogeneration from recfile bookmark
 // Copyright (C) 2021-2025 Sergey Matveev <stargrave@stargrave.org>
 //
 // This program is free software: you can redistribute it and/or modify
diff --git a/swg.go b/swg.go
new file mode 100644 (file)
index 0000000..8041dcc
--- /dev/null
+++ b/swg.go
@@ -0,0 +1,64 @@
+// linksexp -- Texinfo/XBEL/OPML/SWG/urls autogeneration from recfile bookmark
+// Copyright (C) 2021-2025 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
+
+import (
+       "fmt"
+       "sort"
+       "strings"
+)
+
+func swg(cats []string, data map[string][]map[string][]string) {
+       fmt.Println("-- index --")
+       for _, cat := range cats {
+               fmt.Printf("[Links/%s] (%d items)\n", cat, len(data[cat]))
+       }
+       for cat, ents := range data {
+               fmt.Println("--", cat, "--")
+               for n, ent := range ents {
+                       fmt.Printf("=> %s %d: %s\r\n", ent["url"][0], n, ent["title"][0])
+                       if len(ent["note"]) > 0 {
+                               for s := range strings.SplitSeq(ent["note"][0], "\n") {
+                                       if s == "" {
+                                               continue
+                                       }
+                                       fmt.Println("   ", s)
+                               }
+                       }
+                       {
+                               catsOther := make([]string, 0)
+                               for _, c := range ent["cat"] {
+                                       if c != cat {
+                                               catsOther = append(catsOther, "[Links/"+c+"]")
+                                       }
+                               }
+                               sort.Strings(catsOther)
+                               if len(catsOther) > 0 {
+                                       fmt.Println("   ", strings.Join(catsOther, " "))
+                               }
+                       }
+                       switch feeds := ent["feed"]; len(feeds) {
+                       case 0:
+                       case 1:
+                               fmt.Printf("    => %s feed\r\n", feeds[0])
+                       default:
+                               for i, feed := range feeds {
+                                       fmt.Printf("    => %s feed%d\r\n", feed, i)
+                               }
+                       }
+               }
+       }
+}
diff --git a/xbel.go b/xbel.go
index 9b46a1744e30d25dacc2b3a4e685797e0722dd21..c14f3a64d73569adaa6d60569ee48c905b754dd6 100644 (file)
--- a/xbel.go
+++ b/xbel.go
@@ -1,4 +1,4 @@
-// linksexp -- Texinfo/XBEL/OPML/urls autogeneration from recfile bookmark
+// linksexp -- Texinfo/XBEL/OPML/SWG/urls autogeneration from recfile bookmark
 // Copyright (C) 2021-2025 Sergey Matveev <stargrave@stargrave.org>
 //
 // This program is free software: you can redistribute it and/or modify