~samhh/samhh.com

9dcdf7f55dd82778d9ffd2f1e67bbea510b4ef3a — Sam A. Horvath-Hunt 5 months ago a1af5bb
Patch around malformed RSS date inputs in webring
4 files changed, 67 insertions(+), 0 deletions(-)

M .build.yml
M README.md
M makefile
A openring.patch
M .build.yml => .build.yml +2 -0
@@ 16,6 16,8 @@ tasks:
# `$PATH`.
- openring: |
    cd openring
    git checkout 28dc22a
    git am ../samhh.com/openring.patch
    go build -o openring
    sudo cp openring /usr/bin
- build: |

M README.md => README.md +2 -0
@@ 3,3 3,5 @@
The statically-generated source for [samhh.com](https://samhh.com).

Currently building against Hugo 0.89.

A patch is applied against openring to support RSS date formats not to spec.

M makefile => makefile +1 -0
@@ 8,6 8,7 @@ dev:
build:
	rm -rf public
	openring \
		-t 2006-01-02 \
		-s https://drewdevault.com/blog/index.xml \
		-s https://lexi-lambda.github.io/feeds/all.rss.xml \
		-s https://blog.ploeh.dk/rss.xml \

A openring.patch => openring.patch +62 -0
@@ 0,0 1,62 @@
From 58bbca2fbef6f59635db5dc9ba1bc4c8d7e4f29c Mon Sep 17 00:00:00 2001
From: "Sam A. Horvath-Hunt" <hello@samhh.com>
Date: Mon, 6 Dec 2021 14:41:45 +0000
Subject: [PATCH] Add custom time layout support

---
 openring.go | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/openring.go b/openring.go
index aa74469..718708b 100644
--- a/openring.go
+++ b/openring.go
@@ -19,8 +19,22 @@ import (
 	"github.com/microcosm-cc/bluemonday"
 )
 
+type timeLayoutSlice []string
 type urlSlice []*url.URL
 
+func (ts *timeLayoutSlice) String() string {
+	var str []string
+	for _, t := range *ts {
+		str = append(str, t)
+	}
+	return strings.Join(str, ", ")
+}
+
+func (ts *timeLayoutSlice) Set(val string) error {
+	*ts = append(*ts, val)
+	return nil
+}
+
 func (us *urlSlice) String() string {
 	var str []string
 	for _, u := range *us {
@@ -53,8 +67,10 @@ 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")
-		sources    []*url.URL
+		timeLayouts []string
+		sources     []*url.URL
 	)
+	getopt.Var((*timeLayoutSlice)(&timeLayouts), "t", "list of additional time formats")
 	getopt.Var((*urlSlice)(&sources), "s", "list of sources")
 
 	getopt.Usage = func() {
@@ -99,6 +115,10 @@ func main() {
 		panic(err)
 	}
 
+        for _, layout := range timeLayouts {
+          rss.TimeLayouts = append(rss.TimeLayouts, layout)
+        }
+
 	log.Println("Fetching feeds...")
 	var feeds []*rss.Feed
 	for _, source := range sources {
-- 
2.34.1