home · contact · privacy
Display creation dates in index.html and article html files.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 2 Jan 2017 17:58:03 +0000 (18:58 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 2 Jan 2017 17:58:03 +0000 (18:58 +0100)
14 files changed:
README.md
processor/default.html.do
processor/metadata/article.tmpl.do
processor/metadata/default.index_snippet.do
processor/metadata/index_snippet.tmpl.do
test.sh
test/test_files/bar baz.html [deleted file]
test/test_files/bar baz.html.ignoring [new file with mode: 0644]
test/test_files/foo.html [deleted file]
test/test_files/foo.html.ignoring [new file with mode: 0644]
test/test_files/index.html [deleted file]
test/test_files/index.html.ignoring [new file with mode: 0644]
test/test_files/test.html [deleted file]
test/test_files/test.html.ignoring [new file with mode: 0644]

index c247230c0293a192c7ea57d0ef3c0fd259a4bd29..bfb117436f74a0a07058aa7befdf519119ca115a 100644 (file)
--- a/README.md
+++ b/README.md
@@ -84,7 +84,7 @@ bugs and peculiarities
 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
index 99d784df28884f9816f08305099b04cc3338211e..c9bfbdb9eb160e59d383127c87f5a941b4afe14d 100644 (file)
@@ -3,6 +3,8 @@
 # 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
@@ -17,6 +19,9 @@ title_plaintext=`echo "$title_html" | html2text`
 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")
@@ -24,5 +29,7 @@ printf "%s" "$template" | \
 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' '%'
index 7a560ecea535dad4b8f0cb6a15db09f94af8c5e2..9f08b033b2a5c0832e3e6fdceb79fd9dfe29c058 100644 (file)
@@ -10,7 +10,10 @@ cat << EOF
 <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>
index c65f1a66cdf54a045d8d34ead2c56d4b1075b48f..a1ff6f966cb6bc6c155be184058e140909439ab1 100644 (file)
@@ -3,6 +3,8 @@
 # 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"
@@ -13,10 +15,13 @@ redo-ifchange "$template_file"
 # 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' '%'
index 8846342048de7f01dcba2dd84fc6c6b30d75f424..fbe3a45f34a7b50ac8eb4cbc080f63cc27e431b0 100644 (file)
@@ -2,6 +2,6 @@
 
 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
diff --git a/test.sh b/test.sh
index 89a817fd7c6838fabb412defd6b544ac6c77082d..025ebc4d5a7a0d7f8922ea7c234181eaaae30f53 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -26,9 +26,7 @@ diff_test()
 
 # 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)
@@ -42,26 +40,37 @@ cp "$working_dir/$expected_files_dir"/foo.rst .
 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"
diff --git a/test/test_files/bar baz.html b/test/test_files/bar baz.html
deleted file mode 100644 (file)
index 418a91b..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<!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
diff --git a/test/test_files/bar baz.html.ignoring b/test/test_files/bar baz.html.ignoring
new file mode 100644 (file)
index 0000000..410dadf
--- /dev/null
@@ -0,0 +1,19 @@
+<!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
diff --git a/test/test_files/foo.html b/test/test_files/foo.html
deleted file mode 100644 (file)
index 9eb95f5..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<title>Yet another blog – a title with some nasty characters: &amp;&lt;&gt;&quot;&#x27; %BODY%</title>
-</head>
-<body>
-<a href="index.html">Yet another blog</a>
-<article>
-<h1>a title with some nasty characters: &amp;&lt;&gt;&quot;' %BODY%</h1>
-<p>this text contains some special characters: /;%'&quot;&gt;&lt;&amp;äöüß</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
diff --git a/test/test_files/foo.html.ignoring b/test/test_files/foo.html.ignoring
new file mode 100644 (file)
index 0000000..72d1388
--- /dev/null
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Yet another blog – a title with some nasty characters: &amp;&lt;&gt;&quot;&#x27; %BODY%</title>
+</head>
+<body>
+<a href="index.html">Yet another blog</a>
+<article>
+<header>
+<h1>a title with some nasty characters: &amp;&lt;&gt;&quot;' %BODY%</h1>
+<p><time datetime="IGNORE">IGNORE</time></p>
+</header>
+<p>this text contains some special characters: /;%'&quot;&gt;&lt;&amp;äöüß</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
diff --git a/test/test_files/index.html b/test/test_files/index.html
deleted file mode 100644 (file)
index a2660a1..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<!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: &amp;&lt;&gt;&quot;' %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
diff --git a/test/test_files/index.html.ignoring b/test/test_files/index.html.ignoring
new file mode 100644 (file)
index 0000000..3f80781
--- /dev/null
@@ -0,0 +1,15 @@
+<!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: &amp;&lt;&gt;&quot;' %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
diff --git a/test/test_files/test.html b/test/test_files/test.html
deleted file mode 100644 (file)
index bd4b81f..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<!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
diff --git a/test/test_files/test.html.ignoring b/test/test_files/test.html.ignoring
new file mode 100644 (file)
index 0000000..31fa715
--- /dev/null
@@ -0,0 +1,18 @@
+<!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