From: Christian Heller Date: Mon, 2 Jan 2017 17:58:03 +0000 (+0100) Subject: Display creation dates in index.html and article html files. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bprefix%7D%7D/foo.html?a=commitdiff_plain;h=f58e6d66bc1228640227e9a95a305f8213a7103a;p=redo-blog Display creation dates in index.html and article html files. --- diff --git a/README.md b/README.md index c247230..bfb1174 100644 --- 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 diff --git a/processor/default.html.do b/processor/default.html.do index 99d784d..c9bfbdb 100644 --- a/processor/default.html.do +++ b/processor/default.html.do @@ -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' '%' diff --git a/processor/metadata/article.tmpl.do b/processor/metadata/article.tmpl.do index 7a560ec..9f08b03 100644 --- a/processor/metadata/article.tmpl.do +++ b/processor/metadata/article.tmpl.do @@ -10,7 +10,10 @@ cat << EOF %BLOG_TITLE%
+

%ARTICLE_TITLE_HTML%

+

+
%BODY%
diff --git a/processor/metadata/default.index_snippet.do b/processor/metadata/default.index_snippet.do index c65f1a6..a1ff6f9 100644 --- a/processor/metadata/default.index_snippet.do +++ b/processor/metadata/default.index_snippet.do @@ -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' '%' diff --git a/processor/metadata/index_snippet.tmpl.do b/processor/metadata/index_snippet.tmpl.do index 8846342..fbe3a45 100644 --- a/processor/metadata/index_snippet.tmpl.do +++ b/processor/metadata/index_snippet.tmpl.do @@ -2,6 +2,6 @@ if [ ! -f "$1" ]; then cat << EOF -
  • %TITLE%
  • +
  • %TITLE% ()
  • EOF fi diff --git a/test.sh b/test.sh index 89a817f..025ebc4 100755 --- 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\}ZIGNOREurn:uuid:[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}urn:uuid:IGNORE "$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 index 418a91b..0000000 --- a/test/test_files/bar baz.html +++ /dev/null @@ -1,16 +0,0 @@ - - - -Yet another blog – foo - - -Yet another blog -
    -

    foo

    -

    bar

    -

    bar

    -

    bar

    -

    bar

    -
    - - \ 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 index 0000000..410dadf --- /dev/null +++ b/test/test_files/bar baz.html.ignoring @@ -0,0 +1,19 @@ + + + +Yet another blog – foo + + +Yet another blog +
    +
    +

    foo

    +

    +
    +

    bar

    +

    bar

    +

    bar

    +

    bar

    +
    + + \ No newline at end of file diff --git a/test/test_files/foo.html b/test/test_files/foo.html deleted file mode 100644 index 9eb95f5..0000000 --- a/test/test_files/foo.html +++ /dev/null @@ -1,17 +0,0 @@ - - - -Yet another blog – a title with some nasty characters: &<>"' %BODY% - - -Yet another blog -
    -

    a title with some nasty characters: &<>"' %BODY%

    -

    this text contains some special characters: /;%'"><&äöüß

    -

    some sub-heading

    -

    and more than one paragraph

    -

    another sub-heading

    -

    note that should be ignored but \ should give a backlash

    -
    - - \ 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 index 0000000..72d1388 --- /dev/null +++ b/test/test_files/foo.html.ignoring @@ -0,0 +1,20 @@ + + + +Yet another blog – a title with some nasty characters: &<>"' %BODY% + + +Yet another blog +
    +
    +

    a title with some nasty characters: &<>"' %BODY%

    +

    +
    +

    this text contains some special characters: /;%'"><&äöüß

    +

    some sub-heading

    +

    and more than one paragraph

    +

    another sub-heading

    +

    note that should be ignored but \ should give a backlash

    +
    + + \ No newline at end of file diff --git a/test/test_files/index.html b/test/test_files/index.html deleted file mode 100644 index a2660a1..0000000 --- a/test/test_files/index.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - -Yet another blog - - -

    Yet another blog

    - - - \ 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 index 0000000..3f80781 --- /dev/null +++ b/test/test_files/index.html.ignoring @@ -0,0 +1,15 @@ + + + + +Yet another blog + + +

    Yet another blog

    + + + \ No newline at end of file diff --git a/test/test_files/test.html b/test/test_files/test.html deleted file mode 100644 index bd4b81f..0000000 --- a/test/test_files/test.html +++ /dev/null @@ -1,15 +0,0 @@ - - - -Yet another blog – foo bar baz - - -Yet another blog -
    -

    foo bar baz

    -

    foo

    -

    bar

    -

    baz

    -
    - - \ 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 index 0000000..31fa715 --- /dev/null +++ b/test/test_files/test.html.ignoring @@ -0,0 +1,18 @@ + + + +Yet another blog – foo bar baz + + +Yet another blog +
    +
    +

    foo bar baz

    +

    +
    +

    foo

    +

    bar

    +

    baz

    +
    + + \ No newline at end of file