aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-09-27 03:07:27 -0700
committerFuwn <[email protected]>2023-09-27 03:07:27 -0700
commit3215f81f46aca11000560d3a8fcacb349d2e75f3 (patch)
tree87f2df16f18aba888fe09f63f0ef3fc5c46a3d57
parentfix(suzuri): remove extra leading whitespace (diff)
downloadsuzuri-3215f81f46aca11000560d3a8fcacb349d2e75f3.tar.xz
suzuri-3215f81f46aca11000560d3a8fcacb349d2e75f3.zip
feat(suzuri): rss generator
-rw-r--r--README.md5
-rwxr-xr-xsuzuri40
2 files changed, 44 insertions, 1 deletions
diff --git a/README.md b/README.md
index b7f5b6d..adb5fab 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@ Obtain your sumi.news token via the `s` cookie on sumi.news.
### `--help`
```text
-usage: sumi token [folder]
+usage: suzuri token [folder]
positional arguments:
token sumi.news session token
@@ -34,6 +34,7 @@ environment variables:
SUZURI_REVERSE reverse the output feed
SUZURI_MINIMAL output only linked titles
SUZURI_RAW output raw markdown
+ SUZURI_RSS output raw application/rss+xml
```
Optionally, omit the token and folder arguments and export the environment
@@ -51,6 +52,8 @@ variables `SUZURI_TOKEN` and `SUZURI_FOLDER`.
- Pipe it into [`gum`'s](https://github.com/charmbracelet/gum) `choose` subcommand
- Display the most recent feed item in your status-bar
- Echo out the most recent feed item when you start your shell
+- Generate an RSS feed of your feeds to read with local tooling; e.g.,
+ [newsboat](https://newsboat.org/).
## Licence
diff --git a/suzuri b/suzuri
index d1c5f94..a14670b 100755
--- a/suzuri
+++ b/suzuri
@@ -18,6 +18,7 @@ environment variables:
SUZURI_REVERSE reverse the output feed
SUZURI_MINIMAL output only linked titles
SUZURI_RAW output raw markdown
+ SUZURI_RSS output raw application/rss+xml
EOF
exit
@@ -46,6 +47,45 @@ if [[ -n "${SUZURI_MINIMAL}" ]]; then
body="$(echo "${body}" | grep -oP '^## \K.*' | sed "s/##//" || true)"
fi
+if [[ -n "${SUZURI_RSS}" ]]; then
+ IFS=$'\n' read -r -d '' -a items <<<"${body}"
+
+ cat <<EOF
+<rss version="2.0">
+ <channel>
+ <title>sumi.news</title>
+ <link>https://sumi.news</link>
+ <description>Read the entire Internet at once – all the news, RSS, and newsletters on one page.</description>
+ <generator>suzuri</generator>
+ <language>en-US</language>
+ <lastBuildDate>$(date +'%a, %d %b %Y %H:%M:%S %z')</lastBuildDate>
+ <pubDate>$(date +'%a, %d %b %Y %H:%M:%S %z')</pubDate>
+EOF
+
+ for item in "${items[@]}"; do
+ if [[ ${item} =~ ^\[(.+)\] ]]; then
+ title="${BASH_REMATCH[1]}"
+ fi
+
+ regex="\((http[^)]+)\)"
+ if [[ ${item} =~ ${regex} ]]; then
+ url="${BASH_REMATCH[1]}"
+ fi
+
+ cat <<EOF
+ <item>
+ <title>${title}</title>
+ <link>${url}</link>
+ <pubDate>$(date -d "today" '+%a, %d %b %Y 00:00:00 %z')</pubDate>
+ </item>
+EOF
+ done
+
+ echo "</channel></rss>"
+
+ exit
+fi
+
if [[ -n "${SUZURI_RAW}" ]]; then
echo "${body}"
else