From: Sergey Matveev Date: Sun, 1 Jun 2025 15:12:20 +0000 (+0300) Subject: txtar-ed SWG output support X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=bb19e2e82e0f5ab5a092b19c14fcddd383d9f448;p=linksexp.git txtar-ed SWG output support --- diff --git a/README b/README index d786a04..07152da 100644 --- 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 91a50ba..7269adc 100644 --- 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 202d170..8078aa5 100644 --- 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 // // 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 a1a71d7..27b3275 100644 --- 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 // // This program is free software: you can redistribute it and/or modify diff --git a/swg.go b/swg.go new file mode 100644 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 +// +// 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 ( + "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 9b46a17..c14f3a6 100644 --- 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 // // This program is free software: you can redistribute it and/or modify