~tdarb/shinobi-script

7e2f8bd312d648ff1c8d3cfdc747d2e5634100d7 — Matthew Graybosch 1 year, 9 months ago 98bfa1f patch-1
pre-formatted text in full-text RSS feed

- text inside the CDATA tag is now wrapped with <pre> tags
- <pre> tag has inline CSS to specify reasonable wrapping
- tail command to retrieve post text now pipes into sed to escape HTML tags.
- added test posts
- added makefile for local testing
4 files changed, 70 insertions(+), 6 deletions(-)

A makefile
A posts/test1.txt
A posts/test2.txt
M script.sh -rw-r--r-- => -rwxr-xr-x
A makefile => makefile +9 -0
@@ 0,0 1,9 @@
.DEFAULT: build

.PHONY: build
build:
	./script.sh > feed.xml

serve: build
	python3 -m http.server --directory .


A posts/test1.txt => posts/test1.txt +6 -0
@@ 0,0 1,6 @@
Tue, 10 May 2022
THIS IS A TEST

I needed a dummy post to test mods I made to Bradley Taunt's shinobi RSS script.

In particular, I wanted to try wrapping the post text in <pre> tags for that plain-text look.

A posts/test2.txt => posts/test2.txt +45 -0
@@ 0,0 1,45 @@
Tues, 10 May 2022
THIS IS A TEST WITH A CODE EXAMPLE

This is another test, and includes a code example.

Bradley Taunt had advised against including code samples with his full-text feed version of the shinobi RSS script, but hopefully my patch will make that limitation irrelevant.

```shell
#!/bin/sh
DOMAIN="YOUR-DOMAIN"
POST_DIR="posts/"
AUTHOR="YOUR-EMAIL (YOUR-NAME)"
TIME="00:00:00 EST"

echo "<rss version=\"2.0\">
  <channel>
    <title>YOUR-BLOG-TITLE</title>
    <link>$DOMAIN</link>
    <description>YOUR-BLOG-DESCRIPTION</description>
    <copyright>YOUR-COPYRIGHT-INFO</copyright>
    <ttl>60</ttl>";

for file in $POST_DIR*; do

echo "<item>
  <pubDate>$(head -n 1 $file) $TIME</pubDate>
  <title>$(head -n 2 $file | tail -n 1)</title>
  <link>$DOMAIN/$file</link>
  <description>
    <![CDATA[
<pre style='white-space: pre-wrap; word-break: break-word;'>$(tail -n +4 $file | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g')</pre>]]>
	    </description>
        <author>$AUTHOR</author>
        <guid>$DOMAIN/$file</guid>
	</item>";
done

echo "  </channel>
</rss>";

```

> "Now you know it works. Any questions?"
>
> ~Stephen King, *The Stand*

M script.sh => script.sh +10 -6
@@ 13,14 13,18 @@ echo "<rss version=\"2.0\">
    <ttl>60</ttl>";

for file in $POST_DIR*; do
    echo "    <item>
        <pubDate>$(head -n 1 $file) $TIME</pubDate>
        <title>$(head -n 2 $file | tail -n 1)</title>
        <link>$DOMAIN/$file</link>
        <description><![CDATA[$(tail -n +4 $file | sed 's/$/<br>/')]]></description>

echo "<item>
  <pubDate>$(head -n 1 $file) $TIME</pubDate>
  <title>$(head -n 2 $file | tail -n 1)</title>
  <link>$DOMAIN/$file</link>
  <description>
    <![CDATA[
<pre style='white-space: pre-wrap; word-break: break-word;'>$(tail -n +4 $file | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g')</pre>]]>
	    </description>
        <author>$AUTHOR</author>
        <guid>$DOMAIN/$file</guid>
      </item>";
	</item>";
done

echo "  </channel>