Don't create a index.rst or index.md in the redo-managed directory, that will
break things.
-The article title is derived in .md files from a first line prefixed with `% `,
+The article title is derived in .md files from a first line prefixed with `%`,
while all other headings are treated as sub-headings. In .rst files, the title
is derived from a heading that must be at the top of the document, and be of an
adornment style (such as underlining with `=`) that must be used only once in
# Pull in global dependencies.
. ./helpers.sh
metadata_dir=metadata
+uuid_file="${metadata_dir}/${1%.html}.uuid"
+redo-ifchange "$uuid_file"
intermediate_file="${metadata_dir}/${1%.html}.intermediate"
redo-ifchange "$intermediate_file"
title_file="${metadata_dir}"/title
title_html=$(printf "%s" "$title_html" | prep_sed)
title_plaintext=$(escape_html "$title_plaintext" | prep_sed)
body=$(cat "$intermediate_file" | sed 1d | prep_sed)
+datetime_created_unix=$(stat -c%y "${uuid_file}")
+datetime_created_rfc3339=$(date -u "+%Y-%m-%dT%TZ" -d "${datetime_created_unix}")
+datetime_created_friendly=$(date -u "+%Y-%m-%d %T (UTC)" -d "${datetime_created_unix}")
# Put data into template.
template=$(cat "$template_file")
sed 's/%BLOG_TITLE%/'"$blog_title"'/g' | \
sed 's/%ARTICLE_TITLE_ESCAPED%/'"$title_plaintext"'/g' | \
sed 's/%ARTICLE_TITLE_HTML%/'"$title_html"'/g' | \
+sed 's/%DATETIME_CREATED_RFC3339%/'"$datetime_created_rfc3339"'/g' | \
+sed 's/%DATETIME_CREATED_FRIENDLY%/'"$datetime_created_friendly"'/g' | \
sed 's/%BODY%/'"$body"'/g' | \
tr '\a' '%'
<body>
<a href="index.html">%BLOG_TITLE%</a>
<article>
+<header>
<h1>%ARTICLE_TITLE_HTML%</h1>
+<p><time datetime="%DATETIME_CREATED_RFC3339%">%DATETIME_CREATED_FRIENDLY%</time></p>
+</header>
%BODY%
</article>
</body>
# Pull in dependencies.
. ../helpers.sh
src_file=$(get_source_file "$1")
+uuid_file="${1%.index_snippet}.uuid"
+redo-ifchange "$uuid_file"
intermediate_file="${1%.index_snippet}.intermediate"
redo-ifchange "$intermediate_file"
html_file="${src_file%.*}.html"
# Build entry data.
title=$(cat "$intermediate_file" | head -1 | prep_sed)
link=$(escape_url "${1%.index_snippet}.html" | prep_sed)
+datetime_created_unix=$(stat -c%y "${uuid_file}")
+date_created=$(date -u "+%Y-%m-%d" -d "${datetime_created_unix}")
# Put data into template.
template=$(cat "$template_file")
printf "%s\n" "$template" | \
sed 's/%TITLE%/'"$title"'/g' | \
sed 's/%LINK%/'"$link"'/g' | \
+sed 's/%DATE_CREATED%/'"$date_created"'/g' | \
tr '\a' '%'
if [ ! -f "$1" ]; then
cat << EOF
-<li><a href="%LINK%">%TITLE%</a></li>
+<li><a href="%LINK%">%TITLE%</a> (<time>%DATE_CREATED%</time>)</li>
EOF
fi
# Set up test directory.
expected_files_dir="test/test_files"
-expected_files_dir_escaped="test\\/test_files"
generated_files_dir="test/test_dir"
-generated_files_dir_escaped="test\\/test_dir"
rm -rf "$generated_files_dir"
./add_dir.sh "$generated_files_dir"
working_dir=$(pwd)
redo
cd "$working_dir"
-# Simple file comparison tests and UUID tests.
+# Compare metadata files.
uuid_test "$generated_files_dir""/metadata/uuid"
-for file in "$expected_files_dir"/*.html "$expected_files_dir"/metadata/*; do
- sed_expression='s/'"$expected_files_dir_escaped"'/'"$generated_files_dir_escaped"'/'
- cmp_file=`echo "$file" | sed "$sed_expression"`
- if [ ! "$file" = "$expected_files_dir""/index.html" ] && \
- echo "$file" | grep -q "\.html$"; then
- basename=$(basename "$cmp_file")
- uuid_test "${generated_files_dir}/metadata/${basename%.html}.uuid"
- fi
+for file in "$expected_files_dir"/metadata/*; do
+ basename=$(basename "$file")
+ cmp_file="$generated_files_dir/metadata/$basename"
diff_test "$file" "$cmp_file"
done
-# To compare feed.xml, ignore all variable date and uuid strings.
+# Compare generated HTML files. Ignore variable dates.
+for file in "$expected_files_dir"/*.html.ignoring; do
+ basename=$(basename "$file")
+ cmp_file="$generated_files_dir/${basename%.ignoring}"
+ if [ ! "$file" = "$expected_files_dir""/index.html.ignoring" ]; then
+ uuid_test "${generated_files_dir}/metadata/${basename%.html.ignoring}.uuid"
+ fi
+ generated_file="$cmp_file".ignoring
+ cat "$cmp_file" | \
+ sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}/IGNORE/g' | \
+ sed 's/IGNORET[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}Z/IGNORE/g' | \
+ sed 's/IGNORE [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\} (UTC)/IGNORE/g' \
+ > "$generated_file"
+ diff_test "$file" "$generated_file"
+done
+
+# Compare feed files. Ignore variable dates and UUIDs.
original_file="$generated_files_dir""/feed.xml"
generated_file="$original_file".ignoring
expected_file="$expected_files_dir""/feed.xml.ignoring"
cat "$original_file" | \
- sed 's/>[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}Z</>IGNORE</' | \
- sed 's/>urn:uuid:[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}</>urn:uuid:IGNORE</' \
+ sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}Z/IGNORE/g' | \
+ sed 's/urn:uuid:[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}/urn:uuid:IGNORE/g' \
> "$generated_file"
diff_test "$expected_file" "$generated_file"
rm "$generated_file"
+++ /dev/null
-<!DOCTYPE html>
-<html>
-<head>
-<title>Yet another blog – foo</title>
-</head>
-<body>
-<a href="index.html">Yet another blog</a>
-<article>
-<h1>foo</h1>
-<h2 id="bar">bar</h2>
-<p>bar</p>
-<h3 id="bar-1">bar</h3>
-<p>bar</p>
-</article>
-</body>
-</html>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+<title>Yet another blog – foo</title>
+</head>
+<body>
+<a href="index.html">Yet another blog</a>
+<article>
+<header>
+<h1>foo</h1>
+<p><time datetime="IGNORE">IGNORE</time></p>
+</header>
+<h2 id="bar">bar</h2>
+<p>bar</p>
+<h3 id="bar-1">bar</h3>
+<p>bar</p>
+</article>
+</body>
+</html>
\ No newline at end of file
+++ /dev/null
-<!DOCTYPE html>
-<html>
-<head>
-<title>Yet another blog – a title with some nasty characters: &<>"' %BODY%</title>
-</head>
-<body>
-<a href="index.html">Yet another blog</a>
-<article>
-<h1>a title with some nasty characters: &<>"' %BODY%</h1>
-<p>this text contains some special characters: /;%'"><&äöüß</p>
-<h2 id="some-sub-heading">some sub-heading</h2>
-<p>and more than one paragraph</p>
-<h2 id="another-sub-heading">another sub-heading</h2>
-<p>note that should be ignored but \ should give a backlash</p>
-</article>
-</body>
-</html>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+<title>Yet another blog – a title with some nasty characters: &<>"' %BODY%</title>
+</head>
+<body>
+<a href="index.html">Yet another blog</a>
+<article>
+<header>
+<h1>a title with some nasty characters: &<>"' %BODY%</h1>
+<p><time datetime="IGNORE">IGNORE</time></p>
+</header>
+<p>this text contains some special characters: /;%'"><&äöüß</p>
+<h2 id="some-sub-heading">some sub-heading</h2>
+<p>and more than one paragraph</p>
+<h2 id="another-sub-heading">another sub-heading</h2>
+<p>note that should be ignored but \ should give a backlash</p>
+</article>
+</body>
+</html>
\ No newline at end of file
+++ /dev/null
-<!DOCTYPE html>
-<html>
-<head>
-<link rel="alternate" type="application/rss+xml" title="atom feed" href="feed.xml" />
-<title>Yet another blog</title>
-</head>
-<body>
-<h1>Yet another blog</h1>
-<ul>
-<li><a href="foo.html">a title with some nasty characters: &<>"' %BODY%</a></li>
-<li><a href="bar%20baz.html">foo</a></li>
-<li><a href="test.html">foo <em>bar</em> <strong>baz</strong></a></li>
-</ul>
-</body>
-</html>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="alternate" type="application/rss+xml" title="atom feed" href="feed.xml" />
+<title>Yet another blog</title>
+</head>
+<body>
+<h1>Yet another blog</h1>
+<ul>
+<li><a href="foo.html">a title with some nasty characters: &<>"' %BODY%</a> (<time>IGNORE</time>)</li>
+<li><a href="bar%20baz.html">foo</a> (<time>IGNORE</time>)</li>
+<li><a href="test.html">foo <em>bar</em> <strong>baz</strong></a> (<time>IGNORE</time>)</li>
+</ul>
+</body>
+</html>
\ No newline at end of file
+++ /dev/null
-<!DOCTYPE html>
-<html>
-<head>
-<title>Yet another blog – foo bar baz</title>
-</head>
-<body>
-<a href="index.html">Yet another blog</a>
-<article>
-<h1>foo <em>bar</em> <strong>baz</strong></h1>
-<p>foo</p>
-<h2 id="bar">bar</h2>
-<p>baz</p>
-</article>
-</body>
-</html>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+<title>Yet another blog – foo bar baz</title>
+</head>
+<body>
+<a href="index.html">Yet another blog</a>
+<article>
+<header>
+<h1>foo <em>bar</em> <strong>baz</strong></h1>
+<p><time datetime="IGNORE">IGNORE</time></p>
+</header>
+<p>foo</p>
+<h2 id="bar">bar</h2>
+<p>baz</p>
+</article>
+</body>
+</html>
\ No newline at end of file