From: Christian Heller <c.heller@plomlompom.de> Date: Sat, 19 Nov 2016 21:01:58 +0000 (+0100) Subject: Rename generated meta files, test for them. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/booking/processes?a=commitdiff_plain;h=5a17d0898d72bc8574601f57f26af8d3e0da2288;p=redo-blog Rename generated meta files, test for them. --- diff --git a/processor/author.do b/processor/author.do deleted file mode 100644 index ed14e3f..0000000 --- a/processor/author.do +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -if [ ! -f "$1" ]; then - printf "Joe Sixpack" -fi diff --git a/processor/author.meta.do b/processor/author.meta.do new file mode 100644 index 0000000..ed14e3f --- /dev/null +++ b/processor/author.meta.do @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ ! -f "$1" ]; then + printf "Joe Sixpack" +fi diff --git a/processor/default.html.do b/processor/default.html.do index 3ff4132..2a457a5 100644 --- a/processor/default.html.do +++ b/processor/default.html.do @@ -3,11 +3,12 @@ # Pull in global dependencies. . ./helpers.sh intermediate_file="${1%.html}.intermediate" -redo-ifchange title +title_file=title.meta +redo-ifchange "$title_file" redo-ifchange "$intermediate_file" # Build entry data. -blog_title=`read_and_escape_file title | head -1` +blog_title=`read_and_escape_file "$title_file" | head -1` title_html=`cat "$intermediate_file" | head -1` title_plaintext=`echo "$title_html" | html2text` title_plaintext_escaped=`escape_html "$title_plaintext"` diff --git a/processor/feed.xml.do b/processor/feed.xml.do index 2cdb7b2..14ead59 100644 --- a/processor/feed.xml.do +++ b/processor/feed.xml.do @@ -2,21 +2,25 @@ # Pull in global dependencies. . ./helpers.sh -redo-ifchange url -redo-ifchange author -redo-ifchange uuid -redo-ifchange title +url_file=url.meta +author_file=author.meta +uuid_file=uuid.meta +title_file=title.meta +redo-ifchange "$url_file" +redo-ifchange "$author_file" +redo-ifchange "$uuid_file" +redo-ifchange "$title_file" # Build some variables. XML-escape even file contents that should not contain # dangerous characters, just to avoid any XML trouble. -base_url=`cat url | head -1` +base_url=`cat "$url_file" | head -1` url_protocol=`echo $base_url | cut -d ':' -f 1` url_basepath=`echo $base_url | cut -d '/' -f 3-` url_basepath_escaped=`escape_url "$url_basepath"` basepath="$url_protocol""://""$url_basepath_escaped" -title=`read_and_escape_file title | head -1` -author=`read_and_escape_file author | head -1` -uuid=`read_and_escape_file uuid | head -1` +title=`read_and_escape_file "$title_file" | head -1` +author=`read_and_escape_file "$author_file" | head -1` +uuid=`read_and_escape_file "$uuid_file" | head -1` # Write majority of feed head. cat << EOF @@ -47,13 +51,13 @@ for file in $files; do # Build some variables and dependencies. intermediate_file="${file%.*}.intermediate" htmlfile=`escape_url "${file%.*}.html"` + uuid_file="${file%.*}.uuid" redo-ifchange "$intermediate_file" - redo-ifchange "$uuidfile" + redo-ifchange "$uuid_file" title=`read_and_escape_file "$intermediate_file" | head -1` - uuidfile="${file%.*}.uuid" - uuid=`read_and_escape_file "$uuidfile" | head -1` + uuid=`read_and_escape_file "$uuid_file" | head -1` body=`read_and_escape_file "$intermediate_file" | sed 1d` - published=`stat -c%y "$uuidfile"` + published=`stat -c%y "$uuid_file"` published_rfc3339=`date -u "+%Y-%m-%dT%TZ" -d "$published"` # Write entry. diff --git a/processor/index.html.do b/processor/index.html.do index 8bf6751..2b71ffb 100644 --- a/processor/index.html.do +++ b/processor/index.html.do @@ -2,7 +2,8 @@ # Pull in global dependencies. . ./helpers.sh -redo-ifchange title +title_file=title.meta +redo-ifchange "$title_file" # Write index head. cat << EOF @@ -10,7 +11,7 @@ cat << EOF <html> <head> EOF -blog_title=`read_and_escape_file title | head -1` +blog_title=`read_and_escape_file "$title_file" | head -1` printf "<title>%s</title>\n</head>\n<body>\n" "$blog_title" printf "<h1>%s</h1>\n<ul>\n" "$blog_title" diff --git a/processor/title.do b/processor/title.do deleted file mode 100644 index 082accf..0000000 --- a/processor/title.do +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -if [ ! -f "$1" ]; then - printf "Yet another blog" -fi diff --git a/processor/title.meta.do b/processor/title.meta.do new file mode 100644 index 0000000..082accf --- /dev/null +++ b/processor/title.meta.do @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ ! -f "$1" ]; then + printf "Yet another blog" +fi diff --git a/processor/url.do b/processor/url.do deleted file mode 100644 index 4e4079f..0000000 --- a/processor/url.do +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -if [ ! -f "$1" ]; then - printf "http://example.org/" -fi diff --git a/processor/url.meta.do b/processor/url.meta.do new file mode 100644 index 0000000..4e4079f --- /dev/null +++ b/processor/url.meta.do @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ ! -f "$1" ]; then + printf "http://example.org/" +fi diff --git a/processor/uuid.do b/processor/uuid.do deleted file mode 100644 index ba9e919..0000000 --- a/processor/uuid.do +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -if [ ! -f "$1" ]; then - uuidgen -fi diff --git a/processor/uuid.meta.do b/processor/uuid.meta.do new file mode 100644 index 0000000..ba9e919 --- /dev/null +++ b/processor/uuid.meta.do @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ ! -f "$1" ]; then + uuidgen +fi diff --git a/test.sh b/test.sh index 97d0fbf..4daff6b 100755 --- a/test.sh +++ b/test.sh @@ -18,3 +18,18 @@ for file in test/test_files/*.html; do echo "== test FAILURE ==" fi done +for file in test/test_files/*meta; do + if [ "$file" = "test/test_files/uuid.meta" ]; then + true + # TODO: validate UUID + else + cmp_file=`echo "$file" | sed 's/test_files/test_dir/'` + printf "== %s diff test ==\n" "$cmp_file" + diff "$file" "$cmp_file" + if [ "$?" = "0" ]; then + echo "== test SUCCESS ==" + else + echo "== test FAILURE ==" + fi + fi +done diff --git a/test/test_files/author.meta b/test/test_files/author.meta new file mode 100644 index 0000000..5f36248 --- /dev/null +++ b/test/test_files/author.meta @@ -0,0 +1 @@ +Joe Sixpack \ No newline at end of file diff --git a/test/test_files/title.meta b/test/test_files/title.meta new file mode 100644 index 0000000..4d35b7e --- /dev/null +++ b/test/test_files/title.meta @@ -0,0 +1 @@ +Yet another blog \ No newline at end of file diff --git a/test/test_files/url.meta b/test/test_files/url.meta new file mode 100644 index 0000000..673d303 --- /dev/null +++ b/test/test_files/url.meta @@ -0,0 +1 @@ +http://example.org/ \ No newline at end of file diff --git a/test/test_files/uuid.meta b/test/test_files/uuid.meta new file mode 100644 index 0000000..09e4abd --- /dev/null +++ b/test/test_files/uuid.meta @@ -0,0 +1 @@ +438b364d-e7e9-4225-952e-1e9ae312026f