X-Git-Url: http://www.git.stargrave.org/?p=linksexp.git;a=blobdiff_plain;f=main.go;h=f9f7034f5fccca46aeeb259d4a6b508e7cc03bd1;hp=ffa32468ca023ed5a5dd8959ae49ce8a72506690;hb=HEAD;hpb=a803c543ca637462dc575afc5cd26c0a7ee6b461 diff --git a/main.go b/main.go index ffa3246..8078aa5 100644 --- a/main.go +++ b/main.go @@ -1,19 +1,17 @@ -/* -linksexp -- Texinfo/XBEL/OPML/urls autogeneration from recfile bookmark -Copyright (C) 2021 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 . -*/ +// 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 @@ -26,7 +24,7 @@ import ( "strings" "time" - "go.cypherpunks.ru/recfile" + "go.cypherpunks.su/recfile/v2" ) type ByTitle []map[string][]string @@ -34,13 +32,14 @@ type ByTitle []map[string][]string func (a ByTitle) Len() int { return len(a) } func (a ByTitle) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByTitle) Less(i, j int) bool { - return strings.Compare(a[i]["Title"][0], a[j]["Title"][0]) < 0 + return strings.Compare(a[i]["title"][0], a[j]["title"][0]) < 0 } 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) @@ -57,9 +56,12 @@ func main() { if m["%rec"] != nil { continue } - sort.Strings(m["Category"]) - cats := strings.Join(m["Category"], " ") - for _, f := range m["Feed"] { + sort.Strings(m["cat"]) + cats := strings.Join(m["cat"], " ") + for _, f := range m["feed"] { + if strings.HasPrefix(f, "gemini://") { + f = "https://gemini/" + f + } fmt.Println(f, cats) } } @@ -79,7 +81,7 @@ func main() { if m["%rec"] != nil { continue } - sort.Strings(m["Category"]) + sort.Strings(m["cat"]) data = append(data, m) } sort.Sort(ByTitle(data)) @@ -99,8 +101,8 @@ func main() { if m["%rec"] != nil { continue } - sort.Strings(m["Category"]) - if cs := m["Category"]; len(cs) == 0 { + sort.Strings(m["cat"]) + if cs := m["cat"]; len(cs) == 0 { data["Uncategorized"] = append(data["Uncategorized"], m) } else { for _, cat := range cs { @@ -120,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") @@ -137,24 +144,24 @@ func main() { ents := data[cat] for n, ent := range ents { catsOther := make([]string, 0) - for _, c := range ent["Category"] { + for _, c := range ent["cat"] { if c != cat { catsOther = append(catsOther, c) } } var note string - if len(ent["Note"]) > 0 { - note = "(" + strings.Trim(ent["Note"][0], " \n") + ")" + if len(ent["note"]) > 0 { + note = "(" + strings.Trim(ent["note"][0], " \n") + ")" } fmt.Printf( " @item %d @tab @url{%s,, %s} %s @tab %s @tab\n", n, - strings.ReplaceAll(ent["URL"][0], "@", "@@"), - strings.ReplaceAll(ent["Title"][0], "@", "@@"), + strings.ReplaceAll(ent["url"][0], "@", "@@"), + strings.ReplaceAll(ent["title"][0], "@", "@@"), note, strings.Join(catsOther, ", "), ) - switch feeds := ent["Feed"]; len(feeds) { + switch feeds := ent["feed"]; len(feeds) { case 0: fmt.Printf(" @emph{STATIC}\n") case 1: