diff options
| author | Fuwn <[email protected]> | 2023-09-27 03:07:27 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-09-27 03:07:27 -0700 |
| commit | 3215f81f46aca11000560d3a8fcacb349d2e75f3 (patch) | |
| tree | 87f2df16f18aba888fe09f63f0ef3fc5c46a3d57 | |
| parent | fix(suzuri): remove extra leading whitespace (diff) | |
| download | suzuri-3215f81f46aca11000560d3a8fcacb349d2e75f3.tar.xz suzuri-3215f81f46aca11000560d3a8fcacb349d2e75f3.zip | |
feat(suzuri): rss generator
| -rw-r--r-- | README.md | 5 | ||||
| -rwxr-xr-x | suzuri | 40 |
2 files changed, 44 insertions, 1 deletions
@@ -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 @@ -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 |