web: move RSS generation to a seperate shell script
authorTimothy Gu <timothygu99@gmail.com>
Mon, 25 Nov 2013 22:25:05 +0000 (14:25 -0800)
committerLou Logan <lou@lrcd.com>
Thu, 28 Nov 2013 01:13:14 +0000 (16:13 -0900)
Easier to read.

Signed-off-by: Timothy Gu <timothygu99@gmail.com>
Reviewed-by: Stefano Sabatini <stefasab@gmail.com>
Makefile
rss-gen.sh [new file with mode: 0755]

index db2ac28..36e9818 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,22 +18,8 @@ htdocs/%.html: src/% src/%_title $(PAGE_DEPS)
        src/template_footer > $@
 
 htdocs/main.rss: htdocs/index.html
-       echo '<?xml version="1.0" encoding="UTF-8" ?>' > $@
-       echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">' >> $@
-       echo '<channel>' >> $@
-       echo '    <title>FFmpeg RSS</title>' >> $@
-       echo '    <link>http://ffmpeg.org</link>' >> $@
-       echo '    <description>FFmpeg RSS</description>' >> $@
-       echo '    <atom:link href="http://ffmpeg.org/main.rss" rel="self" type="application/rss+xml" />' >> $@
-       grep '<a *id=".*" *></a><h3>.*20..,.*</h3>' $< | sed 'sX<a *id="\(.*\)" *> *</a> *<h3>\(.*20..\), *\(.*\)</h3>X\
-    <item>\
-        <title>\2, \3</title>\
-        <link>http://ffmpeg.org/index.html#\1</link>\
-        <guid>http://ffmpeg.org/index.html#\1</guid>\
-    </item>\
-X' >> $@
-       echo '</channel>' >> $@
-       echo '</rss>' >> $@
-
+       ./rss-gen.sh start $@
+       $(foreach html, $^, ./rss-gen.sh middle $@ $(html);)
+       ./rss-gen.sh end   $@
 
 .PHONY: all clean
diff --git a/rss-gen.sh b/rss-gen.sh
new file mode 100755 (executable)
index 0000000..a2edb07
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+die() {
+    cat <<EOT >&2
+Usage: $0 <mode> <htdocs/output.rss> [<input.html>]
+
+This utility parses & converts generated FFmpeg news HTML page into RSS format.
+"mode" can be begin, middle, or end. If mode is middle, then input HTML is
+required.
+EOT
+    exit 1
+}
+
+# Sanity checks and parsing command line
+
+MODE=$1
+RSS=$2
+HTML=$3
+
+HTML_NODIR=${HTML##*/}
+
+if test $# -lt 2; then
+    echo 'Too few arguments' >&2
+    die
+elif test $# -gt 3; then
+    echo 'Too many arguments' >&2
+    die
+elif test $MODE = "middle" && test $# -ne 3; then
+    echo 'No HTML specified' >&2
+    die
+fi
+
+if test $MODE = "start"; then
+    cat << EOT > $RSS
+<?xml version="1.0" encoding="UTF-8" ?>
+<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
+<channel>
+    <title>FFmpeg RSS</title>
+    <link>http://ffmpeg.org</link>
+    <description>FFmpeg RSS</description>
+    <atom:link href="http://ffmpeg.org/main.rss" rel="self" type="application/rss+xml" />
+EOT
+elif test $MODE = "middle"; then
+    grep '<a *id=".*" *></a><h3>.*20..,.*</h3>' $HTML | sed 'sX<a *id="\(.*\)" *> *</a> *<h3>\(.*20..\), *\(.*\)</h3>X\
+    <item>\
+        <title>\2, \3</title>\
+        <link>http://ffmpeg.org/'$HTML_NODIR'#\1</link>\
+        <guid>http://ffmpeg.org/'$HTML_NODIR'#\1</guid>\
+    </item>\
+X' >> $RSS
+elif test $MODE = "end"; then
+    cat << EOT >> $RSS
+</channel>
+</rss>
+EOT
+else
+    echo 'Unknown mode' >&2
+    die
+fi