better escaping for RSS

This commit is contained in:
/dev/urandom 2022-01-19 12:20:44 +03:00
parent 21c3f52d5a
commit 16f64b74b9
2 changed files with 13 additions and 9 deletions

View file

@ -40,15 +40,15 @@ all: $(OUTDIR)/blog/index.html $(OUTDIR)/dc/blog/index.html $(OUTDIR)/blog/main.
upload: upload:
./upload.sh ./upload.sh
$(OUTDIR)/dc/blog/index.html: $(_BLOG_PAGES) $(TPLDIR)/blog_header.md $(TPLDIR)/blog_footer.md $(TPLDIR)/dreamcast.tpl $(OUTDIR)/dc/blog/index.html: $(_BLOG_PAGES) $(TPLDIR)/blog_header.md $(TPLDIR)/blog_footer.md $(TPLDIR)/dreamcast.tpl blogindex.sh
@mkdir -p $(@D) @mkdir -p $(@D)
./blogindex.sh | $(THEME) $(DC_THEME_FLAGS) -t $(TPLDIR)/dreamcast.tpl -p blog/index.html -o $@ ./blogindex.sh | $(THEME) $(DC_THEME_FLAGS) -t $(TPLDIR)/dreamcast.tpl -p blog/index.html -o $@
$(OUTDIR)/blog/index.html: $(_BLOG_PAGES) $(TPLDIR)/blog_header.md $(TPLDIR)/blog_footer.md $(TPLDIR)/default.tpl $(OUTDIR)/blog/index.html: $(_BLOG_PAGES) $(TPLDIR)/blog_header.md $(TPLDIR)/blog_footer.md $(TPLDIR)/default.tpl blogindex.sh
@mkdir -p $(@D) @mkdir -p $(@D)
./blogindex.sh | $(THEME) $(THEME_FLAGS) -t $(TPLDIR)/default.tpl -p blog/index.html -o $@ ./blogindex.sh | $(THEME) $(THEME_FLAGS) -t $(TPLDIR)/default.tpl -p blog/index.html -o $@
$(OUTDIR)/blog/main.rss: $(_BLOG_PAGES) $(OUTDIR)/blog/main.rss: $(_BLOG_PAGES) blogindex.sh
@mkdir -p $(@D) @mkdir -p $(@D)
./blogindex.sh -r > $@ ./blogindex.sh -r > $@

View file

@ -16,6 +16,10 @@ FILES=`ls $DIRECTORY/*.md -1 | sort`
RETURNDATE="" RETURNDATE=""
function rss_escape {
echo "$1" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g'
}
function printcut { function printcut {
# argument 1: filename # argument 1: filename
@ -64,9 +68,9 @@ cat << RSSHEADER
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel> <channel>
<atom:link href="https://devurandom.xyz/blog/main.rss" rel="self" type="application/rss+xml" /> <atom:link href="https://devurandom.xyz/blog/main.rss" rel="self" type="application/rss+xml" />
<title>rnd's blog</title> <title>$(rss_escape "${RSSTITLE}")</title>
<link>https://devurandom.xyz/blog</link> <link>$(rss_escape "${BASEURL}/blog")</link>
<description>The RSS feed of articles published on the blog thingy</description> <description>$(rss_escape "${RSSDESC}")</description>
RSSHEADER RSSHEADER
else else
cat tpl/blog_header.md cat tpl/blog_header.md
@ -86,7 +90,7 @@ for f in $FILES; do
if [ $RSSMODE ]; then if [ $RSSMODE ]; then
echo "<item>" echo "<item>"
echo "<title>$TITLE</title>" echo "<title>$(rss_escape "$TITLE")</title>"
echo "<link>https://devurandom.xyz/blog/$OUTPAGE</link>" echo "<link>https://devurandom.xyz/blog/$OUTPAGE</link>"
echo "<guid>https://devurandom.xyz/blog/$OUTPAGE</guid>" echo "<guid>https://devurandom.xyz/blog/$OUTPAGE</guid>"
if [ $MTIME -gt 0 ]; then if [ $MTIME -gt 0 ]; then
@ -96,9 +100,9 @@ for f in $FILES; do
fi fi
echo "<pubDate>$RDATE</pubDate>" echo "<pubDate>$RDATE</pubDate>"
fi fi
DESCRIPTION="`printcut $f`" DESCRIPTION="$(printcut $f)"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "<description>$DESCRIPTION</description>" echo "<description>$(rss_escape "$DESCRIPTION")</description>"
fi fi
echo "</item>" echo "</item>"
else else