[FFmpeg-devel] [PATCH 1/3] web: move RSS generation to a seperate shell script
Stefano Sabatini
stefasab at gmail.com
Mon Nov 25 20:03:28 CET 2013
On date Sunday 2013-11-24 15:47:37 -0800, Timothy Gu encoded:
> Easier to read.
>
> Signed-off-by: Timothy Gu <timothygu99 at gmail.com>
> ---
> Makefile | 20 +++-----------------
> rss-gen.sh | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 57 insertions(+), 17 deletions(-)
> create mode 100755 rss-gen.sh
>
> diff --git a/Makefile b/Makefile
> index db2ac28..36e9818 100644
> --- 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
> index 0000000..bbb245b
> --- /dev/null
> +++ b/rss-gen.sh
> @@ -0,0 +1,54 @@
> +#!/bin/sh
> +
> +die() {
> + echo 'This utility parses & converts generated FFmpeg news HTML page into' >&2
> + echo 'RSS format.' >&2
> + echo >&2
> + echo 'Usage: $0 <mode> <htdocs/output.rss> [<input.html>]' >&2
> + echo '"mode" can be begin, middle, or end. If mode is middle, then input' >&2
> + echo 'HTML is required.' >&2
> + exit 1
> +}
cat >&2 << EOT
This utility ...
EOT
exit 1
more readable and idiomatic
> +
> +# 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
> + echo '<?xml version="1.0" encoding="UTF-8" ?>' > $RSS
> + echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">' >> $RSS
> + echo '<channel>' >> $RSS
> + echo ' <title>FFmpeg RSS</title>' >> $RSS
> + echo ' <link>http://ffmpeg.org</link>' >> $RSS
> + echo ' <description>FFmpeg RSS</description>' >> $RSS
> + echo ' <atom:link href="http://ffmpeg.org/main.rss" rel="self" type="application/rss+xml" />' >> $RSS
> +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
> + echo '</channel>' >> $RSS
> + echo '</rss>' >> $RSS
> +else
> + echo 'Unknown mode' >&2
> + die
> +fi
same here, you can use the EOT construct
--
FFmpeg = Formidable and Faithful Mere Philosofic Erratic Genius
More information about the ffmpeg-devel
mailing list