build and test for indexes
parent
fc661f4b60
commit
c634cf4f11
|
@ -50,7 +50,9 @@ function render_index_item() {
|
||||||
title=${2}
|
title=${2}
|
||||||
thumbnail=${3}
|
thumbnail=${3}
|
||||||
cat ${WXRX_WEB_TEMPLATES}/item.template |
|
cat ${WXRX_WEB_TEMPLATES}/item.template |
|
||||||
url="${url}" title="${title}" thumbnail="${thumbnail}" envsubst
|
template_subst URL "${url}" |
|
||||||
|
template_subst HEADING "${title}" |
|
||||||
|
template_subst THUMBNAIL "${thumbnail}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# @param manifest file
|
# @param manifest file
|
||||||
|
@ -267,6 +269,39 @@ function generate_pages() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Renders an index file from input from STDIN
|
||||||
|
# Input should be tab-delimited TIMESTAMP, URL, THUMBNAIL_URL
|
||||||
|
# The output of `generate_pages` is expected to be used here
|
||||||
|
# @param Title (optional)
|
||||||
|
# @param Generated timestamp (optional)
|
||||||
|
# @input tab delimited items to add to index
|
||||||
|
# @output rendered markup to stdout
|
||||||
|
function render_index() {
|
||||||
|
title=${1:-Latest Satellite Passes}
|
||||||
|
generated_at=${2:-$(date '+%a %b %d %T %Z %Y')}
|
||||||
|
items=( )
|
||||||
|
while read -r line
|
||||||
|
do
|
||||||
|
timestamp=$(echo "${line}" | cut -f1)
|
||||||
|
url=$(echo "${line}" | cut -f2)
|
||||||
|
heading=$(date -d "@${timestamp}" '+%a %b %d %T %Z %Y')
|
||||||
|
thumbnail=$(echo "${line}" |cut -f3)
|
||||||
|
item=$(render_index_item "${url}" "${heading}" "${thumbnail}")
|
||||||
|
items+=( "${item}" )
|
||||||
|
done
|
||||||
|
|
||||||
|
content=$(echo "${items[@]}")
|
||||||
|
|
||||||
|
document_body=$(cat $(template_path "index") |
|
||||||
|
template_subst CONTENT "${content}")
|
||||||
|
|
||||||
|
cat $(template_path "document") |
|
||||||
|
template_subst CONTENT "${document_body}" |
|
||||||
|
template_subst TITLE "${title}" |
|
||||||
|
template_subst GENERATED_AT "${generated_at}"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function process_args() {
|
function process_args() {
|
||||||
## Options:
|
## Options:
|
||||||
while (( "$#" ));
|
while (( "$#" ));
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
<article>
|
<item>
|
||||||
<figure style="max-width: 200px; margin: 1rem auto 3rem;">
|
<heading>
|
||||||
<a href="{{URL}}"><img src="{{THUMBNAIL}}" style="width: 100%;" alt="Decoded satellite image thumbnail" /></a>
|
{{HEADING}}
|
||||||
<figcaption>{{HEADING}}</figcaption>
|
</heading>
|
||||||
</figure>
|
<url>
|
||||||
</article>
|
{{URL}}
|
||||||
|
</url>
|
||||||
|
<thumbnail>
|
||||||
|
{{THUMBNAIL}}
|
||||||
|
</thumbnail>
|
||||||
|
</item>
|
||||||
|
|
|
@ -69,6 +69,7 @@ EOF
|
||||||
test_generate_pages() {
|
test_generate_pages() {
|
||||||
stdoutF=${SHUNIT_TMPDIR}/stdout
|
stdoutF=${SHUNIT_TMPDIR}/stdout
|
||||||
stderrF=${SHUNIT_TMPDIR}/stderr
|
stderrF=${SHUNIT_TMPDIR}/stderr
|
||||||
|
expectedF=${SHUNIT_TMPDIR}/expected
|
||||||
WXRX_WEB_PUBDIR=${SHUNIT_TMPDIR}/test_generate_website/public
|
WXRX_WEB_PUBDIR=${SHUNIT_TMPDIR}/test_generate_website/public
|
||||||
WXRX_WEB_TEMPLATES=${fixture_dir}/test_generate_website/templates
|
WXRX_WEB_TEMPLATES=${fixture_dir}/test_generate_website/templates
|
||||||
data_dir=${fixture_dir}/test_generate_website
|
data_dir=${fixture_dir}/test_generate_website
|
||||||
|
@ -95,4 +96,26 @@ EOF
|
||||||
popd >/dev/null
|
popd >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_render_index() {
|
||||||
|
stdoutF=${SHUNIT_TMPDIR}/stdout
|
||||||
|
stderrF=${SHUNIT_TMPDIR}/stderr
|
||||||
|
expectedF=${SHUNIT_TMPDIR}/expected
|
||||||
|
WXRX_WEB_TEMPLATES=${fixture_dir}/test_generate_website/templates
|
||||||
|
source ${unit}
|
||||||
|
|
||||||
|
render_index "Expected Title" "Generated Timestamp" << EOF >${stdoutF} 2>${stderrF}
|
||||||
|
1643805264 bar-passes/noaa_15-1643805264.html bar-passes/noaa_15-1643805264-MCIR.png
|
||||||
|
1643805264 foo-passes/noaa_15-1643805264.html foo-passes/noaa_15-1643805264-MCIR.png
|
||||||
|
1643805264 noaa_15-1643805264.html noaa_15-1643805264-MCIR.png
|
||||||
|
EOF
|
||||||
|
|
||||||
|
rtrn=$?
|
||||||
|
assertTrue "expected 0 return status" ${rtrn}
|
||||||
|
assertNotNull "expected output" "`cat ${stdoutF}`"
|
||||||
|
assertNull "unexpected stderr" "`cat ${stderrF}`"
|
||||||
|
assertNotNull 'expected a title in output' "`grep -F 'Expected Title' ${stdoutF}`"
|
||||||
|
assertNotNull 'expected generated date in output' "`grep -F 'Generated Timestamp' ${stdoutF}`"
|
||||||
|
assertNotNull 'expected url' "`grep -F 'bar-passes/noaa_15-1643805264.html' ${stdoutF}`"
|
||||||
|
}
|
||||||
|
|
||||||
. shunit2
|
. shunit2
|
||||||
|
|
Loading…
Reference in New Issue