A flake.lock => flake.lock +27 -0
@@ 0,0 1,27 @@
+{
+ "nodes": {
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1699099776,
+ "narHash": "sha256-X09iKJ27mGsGambGfkKzqvw5esP1L/Rf8H3u3fCqIiU=",
+ "owner": "nixos",
+ "repo": "nixpkgs",
+ "rev": "85f1ba3e51676fa8cc604a3d863d729026a6b8eb",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nixos",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "nixpkgs": "nixpkgs"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
A flake.nix => flake.nix +35 -0
@@ 0,0 1,35 @@
+{
+ description = "Sharpie monorepo";
+
+ inputs = {
+ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+ };
+
+ outputs = inputs@{ self, nixpkgs, ... }:
+ let
+ # System types to support.
+ supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ];
+
+ # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
+ forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
+
+ # Nixpkgs instantiated for supported system types.
+ nixpkgsFor = forAllSystems (system: import nixpkgs {
+ inherit system;
+ });
+ in
+ {
+ packages = forAllSystems (system:
+ let
+ pkgs = nixpkgsFor."${system}";
+ in
+ {
+ default = pkgs.buildGoModule {
+ name = "openring";
+ src = ./.;
+
+ vendorHash = "sha256-Uw9ygbfx2HQwQPZiGzRFsXJfzd752s19d4S4QA0S9fo=";
+ };
+ });
+ };
+}
M go.mod => go.mod +1 -0
@@ 5,6 5,7 @@ go 1.12
require (
git.sr.ht/~sircmpwn/getopt v0.0.0-20190621174457-292febf82fd0
github.com/SlyMarbo/rss v1.0.1
+ github.com/gilliek/go-opml v1.0.0 // indirect
github.com/mattn/go-runewidth v0.0.4
github.com/microcosm-cc/bluemonday v1.0.2
)
M go.sum => go.sum +2 -0
@@ 7,6 7,8 @@ github.com/SlyMarbo/rss v1.0.1/go.mod h1:JNF+T33oj4m5WLCQXpBTCgO+SxRbYVgdiiimHNg
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ=
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394/go.mod h1:Q8n74mJTIgjX4RBBcHnJ05h//6/k6foqmgE45jTQtxg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/gilliek/go-opml v1.0.0 h1:X8xVjtySRXU/x6KvaiXkn7OV3a4DHqxY8Rpv6U/JvCY=
+github.com/gilliek/go-opml v1.0.0/go.mod h1:fOxmtlzyBvUjU6bjpdjyxCGlWz+pgtAHrHf/xRZl3lk=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s=
M openring.go => openring.go +33 -3
@@ 10,13 10,14 @@
// Copyright: 2020 skuzzymiglet <skuzzymiglet@gmail.com>
// Copyright: 2021 Gianluca Arbezzano <ciao@gianarb.it>
// Copyright: 2021 sourque <contact@sourque.com>
+// Copyright: 2023 Victor Freire <victor@freire.dev.br>
package main
import (
"bufio"
"html"
"html/template"
- "io/ioutil"
+ "io"
"log"
"net/url"
"os"
@@ 27,6 28,7 @@ import (
"git.sr.ht/~sircmpwn/getopt"
"github.com/SlyMarbo/rss"
+ "github.com/gilliek/go-opml/opml"
"github.com/mattn/go-runewidth"
"github.com/microcosm-cc/bluemonday"
)
@@ 50,6 52,22 @@ func (us *urlSlice) Set(val string) error {
return nil
}
+// flattenOutlines receives a list of outlines and flattlen them
+func flattenOutlines(inputs []opml.Outline) []opml.Outline {
+ var acc []opml.Outline
+ for _, x := range inputs {
+ if len(x.Outlines) == 0 {
+ // we don't need it anymore
+ x.Outlines = nil
+ acc = append(acc, x)
+ } else {
+ acc = append(acc, flattenOutlines(x.Outlines)...)
+ }
+ }
+
+ return acc
+}
+
type Article struct {
Date time.Time
Link string
@@ 65,12 83,13 @@ func main() {
perSource = getopt.Int("p", 1, "articles to take from each source")
summaryLen = getopt.Int("l", 256, "length of summaries")
urlsFile = getopt.String("S", "", "file with URLs of sources")
+ opmlFile = getopt.String("O", "", "OPML file")
sources []*url.URL
)
getopt.Var((*urlSlice)(&sources), "s", "list of sources")
getopt.Usage = func() {
- log.Fatalf("Usage: %s [-s https://source.rss...] < in.html > out.html",
+ log.Fatalf("Usage: %s [-O opml.xml] [-s https://source.rss...] < in.html > out.html",
os.Args[0])
}
@@ 91,7 110,18 @@ func main() {
file.Close()
}
- input, err := ioutil.ReadAll(os.Stdin)
+ if *opmlFile != "" {
+ doc, err := opml.NewOPMLFromFile(*opmlFile)
+ if err != nil {
+ panic(err)
+ }
+ outlines := flattenOutlines(doc.Body.Outlines)
+ for _, x := range outlines {
+ (*urlSlice)(&sources).Set(x.XMLURL)
+ }
+ }
+
+ input, err := io.ReadAll(os.Stdin)
if err != nil {
panic(err)
}