From 6ee5e0e20b722b1d4e72dfa52a19ec684cb30410 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 21 Dec 2016 23:07:47 +0100 Subject: [PATCH] Move everything that does not need to be top level dir into sub dir. --- add_dir.sh | 25 +++++++++++++---- processor/{author.meta.do => .meta/author.do} | 0 processor/{ => .meta}/default.feed_snippet.do | 5 ++-- .../{ => .meta}/default.index_snippet.do | 4 +-- processor/{ => .meta}/default.intermediate.do | 4 +-- processor/{ => .meta}/default.uuid.do | 0 processor/{ => .meta}/helpers.sh | 6 ++-- processor/{ => .meta}/intermediate.tmpl | 0 processor/{title.meta.do => .meta/title.do} | 0 processor/{url.meta.do => .meta/url.do} | 0 processor/{uuid.meta.do => .meta/uuid.do} | 0 processor/all.do | 25 ++++++++++------- processor/default.html.do | 7 +++-- processor/feed.xml.do | 27 ++++++++++-------- processor/index.html.do | 28 ++++++++++--------- test.sh | 21 +++++++------- test/test_files/{author.meta => .meta/author} | 0 test/test_files/{title.meta => .meta/title} | 0 test/test_files/{url.meta => .meta/url} | 0 19 files changed, 90 insertions(+), 62 deletions(-) rename processor/{author.meta.do => .meta/author.do} (100%) rename processor/{ => .meta}/default.feed_snippet.do (92%) rename processor/{ => .meta}/default.index_snippet.do (76%) rename processor/{ => .meta}/default.intermediate.do (84%) rename processor/{ => .meta}/default.uuid.do (100%) rename processor/{ => .meta}/helpers.sh (91%) rename processor/{ => .meta}/intermediate.tmpl (100%) rename processor/{title.meta.do => .meta/title.do} (100%) rename processor/{url.meta.do => .meta/url.do} (100%) rename processor/{uuid.meta.do => .meta/uuid.do} (100%) rename test/test_files/{author.meta => .meta/author} (100%) rename test/test_files/{title.meta => .meta/title} (100%) rename test/test_files/{url.meta => .meta/url} (100%) diff --git a/add_dir.sh b/add_dir.sh index 33bc913..36bcf66 100755 --- a/add_dir.sh +++ b/add_dir.sh @@ -2,11 +2,26 @@ set -e +link_files_in_dir () { + srcdir="$1" + for file in "$srcdir"/* "$srcdir"/.*; do + if [ -f "$file" ]; then + set +e + ln -s "$file" + set -e + elif [ -d "$file" ] && \ + [ $(basename "$file") != "." ] && \ + [ $(basename "$file") != ".." ]; then + dir=$(basename "$file") + mkdir "$dir" + cd "$dir" + link_files_in_dir "$srcdir/$dir" + cd .. + fi + done +} + srcdir=`pwd`/processor mkdir -p "$1" cd "$1" -for file in "$srcdir"/*; do - set +e - ln -s "$file" - set -e -done +link_files_in_dir "$srcdir" diff --git a/processor/author.meta.do b/processor/.meta/author.do similarity index 100% rename from processor/author.meta.do rename to processor/.meta/author.do diff --git a/processor/default.feed_snippet.do b/processor/.meta/default.feed_snippet.do similarity index 92% rename from processor/default.feed_snippet.do rename to processor/.meta/default.feed_snippet.do index 9d33ad9..1949d0b 100644 --- a/processor/default.feed_snippet.do +++ b/processor/.meta/default.feed_snippet.do @@ -5,11 +5,12 @@ src_file=$(get_source_file "$1") uuid_file="${1%.feed_snippet}.uuid" redo-ifchange "$uuid_file" -intermediate_file="${src_file%.*}.intermediate" +intermediate_file="${1%.feed_snippet}.intermediate" redo-ifchange "$intermediate_file" # Get variables, write entry. html_file=`escape_url "${src_file%.*}.html"` +html_file=${html_file#*/} lastmod=`stat -c%y "$src_file"` lastmod_rfc3339=`date -u "+%Y-%m-%dT%TZ" -d "$lastmod"` published=`stat -c%y "$uuid_file"` @@ -22,6 +23,6 @@ printf "%s\n" "$title" printf "urn:uuid:%s\n" "$uuid" printf "%s\n" "$lastmod_rfc3339" printf "%s\n" "$published_rfc3339" -printf "\n" "$(get_basepath)" "${html_file#\./}" +printf "\n" "$(get_basepath)" "${html_file}" printf "\n%s\n\n" "$body" printf "\n" diff --git a/processor/default.index_snippet.do b/processor/.meta/default.index_snippet.do similarity index 76% rename from processor/default.index_snippet.do rename to processor/.meta/default.index_snippet.do index 759a510..33499ed 100644 --- a/processor/default.index_snippet.do +++ b/processor/.meta/default.index_snippet.do @@ -3,12 +3,12 @@ # Pull in dependencies. . ./helpers.sh src_file=$(get_source_file "$1") -intermediate_file="${src_file%.*}.intermediate" +intermediate_file="${1%.index_snippet}.intermediate" redo-ifchange "$intermediate_file" html_file="${src_file%.*}.html" redo-ifchange "$html_file" # Get variables, write entry. title_html=`cat "$intermediate_file" | head -1` -html_file_escaped=`escape_url "${html_file#\./}"` +html_file_escaped=`escape_url "${html_file#*/}"` printf "
  • %s
  • \n" "$html_file_escaped" "$title_html" diff --git a/processor/default.intermediate.do b/processor/.meta/default.intermediate.do similarity index 84% rename from processor/default.intermediate.do rename to processor/.meta/default.intermediate.do index 7470c3c..e6addea 100644 --- a/processor/default.intermediate.do +++ b/processor/.meta/default.intermediate.do @@ -4,8 +4,8 @@ template=intermediate.tmpl uuidfile="${1%.intermediate}.uuid" redo-ifchange "$uuidfile" redo-ifchange "$template" -mdfile="${1%.intermediate}.md" -rstfile="${1%.intermediate}.rst" +mdfile="../${1%.intermediate}.md" +rstfile="../${1%.intermediate}.rst" if [ -f "$rstfile" ]; then redo-ifchange "$rstfile" pandoc -f rst --template="$template" --mathml -t html5 "$rstfile" > "$3" diff --git a/processor/default.uuid.do b/processor/.meta/default.uuid.do similarity index 100% rename from processor/default.uuid.do rename to processor/.meta/default.uuid.do diff --git a/processor/helpers.sh b/processor/.meta/helpers.sh similarity index 91% rename from processor/helpers.sh rename to processor/.meta/helpers.sh index cc12358..20905ab 100644 --- a/processor/helpers.sh +++ b/processor/.meta/helpers.sh @@ -16,7 +16,7 @@ escape_url() { } get_basepath() { - url_file=url.meta + url_file="$1"url redo-ifchange "$url_file" base_url=`cat "$url_file" | head -1` url_protocol=`echo $base_url | cut -d ':' -f 1` @@ -27,8 +27,8 @@ get_basepath() { } get_source_file() { - md_file="${1%.*}.md" - rst_file="${1%.*}.rst" + md_file="../${1%.*}.md" + rst_file="../${1%.*}.rst" if [ -f "$rst_file" ]; then src_file="$rst_file" elif [ -f "$md_file" ]; then diff --git a/processor/intermediate.tmpl b/processor/.meta/intermediate.tmpl similarity index 100% rename from processor/intermediate.tmpl rename to processor/.meta/intermediate.tmpl diff --git a/processor/title.meta.do b/processor/.meta/title.do similarity index 100% rename from processor/title.meta.do rename to processor/.meta/title.do diff --git a/processor/url.meta.do b/processor/.meta/url.do similarity index 100% rename from processor/url.meta.do rename to processor/.meta/url.do diff --git a/processor/uuid.meta.do b/processor/.meta/uuid.do similarity index 100% rename from processor/uuid.meta.do rename to processor/.meta/uuid.do diff --git a/processor/all.do b/processor/all.do index edd2b47..73d0124 100644 --- a/processor/all.do +++ b/processor/all.do @@ -1,24 +1,28 @@ #!/bin/sh +metadata_dir=.meta + # Remove target files for which no sources files can be found. -for file in *.intermediate; do +for file in "$metadata_dir"/*.intermediate; do + basename=$(basename "$file") if test -f "$file" && - ! test -f "${file%.intermediate}.md" && - ! test -f "${file%.intermediate}.rst"; then + ! test -f "${basename%.intermediate}.md" && + ! test -f "${basename%.intermediate}.rst"; then rm "$file" fi done -for file in *.uuid; do +for file in "$metadata_dir"/*.uuid; do + basename=$(basename "$file") if test -f "$file" && - ! test -f "${file%.uuid}.md" && - ! test -f "${file%.uuid}.rst"; then + ! test -f "${basename%.uuid}.md" && + ! test -f "${basename%.uuid}.rst"; then rm "$file" fi done for file in *.html; do if test -f "$file" && ! test "$file" = "index.html" && - ! test -f "${file%.html}.intermediate"; then + ! test -f "${metadata_dir}/${file%.html}.intermediate"; then rm "$file" fi done @@ -27,12 +31,13 @@ done # of the all.do script on them / build them if necessary. for file in *.rst *.md; do if test -f "$file"; then - redo-ifchange "${file%.*}.intermediate" + redo-ifchange "${metadata_dir}/${file%.*}.intermediate" fi done -for file in *.intermediate; do +for file in "$metadata_dir"/*.intermediate; do if test -f "$file"; then - redo-ifchange "${file%.*}.html" + basename=$(basename "$file") + redo-ifchange "${basename%.intermediate}.html" fi done diff --git a/processor/default.html.do b/processor/default.html.do index 2a457a5..4371a3a 100644 --- a/processor/default.html.do +++ b/processor/default.html.do @@ -1,9 +1,10 @@ #!/bin/sh # Pull in global dependencies. -. ./helpers.sh -intermediate_file="${1%.html}.intermediate" -title_file=title.meta +metadata_dir=.meta +. "$metadata_dir"/helpers.sh +intermediate_file="${metadata_dir}/${1%.html}.intermediate" +title_file="${metadata_dir}"/title redo-ifchange "$title_file" redo-ifchange "$intermediate_file" diff --git a/processor/feed.xml.do b/processor/feed.xml.do index 16011f3..2b43969 100644 --- a/processor/feed.xml.do +++ b/processor/feed.xml.do @@ -1,10 +1,12 @@ #!/bin/sh # Pull in global dependencies. -. ./helpers.sh -author_file=author.meta -uuid_file=uuid.meta -title_file=title.meta +metadata_dir=.meta +. "$metadata_dir"/helpers.sh +author_file="$metadata_dir"/author +uuid_file="$metadata_dir"/uuid +title_file="$metadata_dir"/title +url_file="$metadata_dir"/url redo-ifchange "$url_file" redo-ifchange "$author_file" redo-ifchange "$uuid_file" @@ -13,10 +15,11 @@ redo-ifchange "$title_file" # Build some variables. XML-escape even file contents that should not contain # dangerous characters, just to avoid any XML trouble. srcdir=`pwd` -basepath=$(get_basepath) +basepath=$(get_basepath "${metadata_dir}/") 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` +tmp_snippets_dir=.tmp_feed_snippets # Write majority of feed head. cat << EOF @@ -30,21 +33,21 @@ printf "%s\n" "$author" printf "urn:uuid:%s\n" "$uuid" # Generate feed entry snippets. -mkdir -p feed_snippets +mkdir -p "$tmp_snippets_dir" for file in ./*.rst ./*.md; do if [ -e "$file" ]; then - uuid_file="${file%.*}.uuid" + uuid_file="${metadata_dir}/${file%.*}.uuid" redo-ifchange "$uuid_file" published=`stat -c%y "${uuid_file}"` published_unix=$(date -u "+%s%N" -d "${published}") - snippet_file="${file%.*}.feed_snippet" + snippet_file=./${metadata_dir}/"${file%.*}.feed_snippet" redo-ifchange "$snippet_file" - ln -s "$srcdir/$snippet_file" "./feed_snippets/${published_unix}" + ln -s "$srcdir/$snippet_file" "./${tmp_snippets_dir}/${published_unix}" fi done # Derive feed modification date from snippets. -mod_dates=$(grep -hE "^" ./feed_snippets/* | sed -E 's/<.?updated>//g') +mod_dates=$(grep -hE "^" ./${metadata_dir}/*.feed_snippet | sed -E 's/<.?updated>//g') last_mod_unix=0 for date in $mod_dates; do date_unix=$(date -u "+%s" -d "${date}") @@ -56,11 +59,11 @@ lastmod_rfc3339=`date -u "+%Y-%m-%dT%TZ" -d "@${last_mod_unix}"` printf "%s\n\n" "$lastmod_rfc3339" # Write feed entries. -for file in ./feed_snippets/*; do +for file in ./${tmp_snippets_dir}/*; do cat "${file}" printf "\n" done -rm -rf feed_snippets +rm -rf "$tmp_snippets_dir" # Write feed foot. printf "" diff --git a/processor/index.html.do b/processor/index.html.do index af8ba85..64fe355 100644 --- a/processor/index.html.do +++ b/processor/index.html.do @@ -1,9 +1,10 @@ #!/bin/sh # Pull in global dependencies. -. ./helpers.sh +metadata_dir=.meta +. "$metadata_dir"/helpers.sh srcdir=`pwd` -title_file=title.meta +title_file="$metadata_dir"/title redo-ifchange "$title_file" # Write index head. @@ -17,29 +18,30 @@ printf "%s\n\n\n" "$blog_title" printf "

    %s

    \n
      \n" "$blog_title" # Generate link list entries. -mkdir -p index_snippets +tmp_snippets_dir=.tmp_index_snippets +mkdir -p "$tmp_snippets_dir" for file in ./*.rst ./*.md; do if [ -e "$file" ]; then - uuid_file="${file%.*}.uuid" + uuid_file="${metadata_dir}/${file%.*}.uuid" redo-ifchange "$uuid_file" published=`stat -c%y "${uuid_file}"` published_unix=$(date -u "+%s%N" -d "${published}") - snippet_file="${file%.*}.index_snippet" + snippet_file="${metadata_dir}/${file%.*}.index_snippet" redo-ifchange "$snippet_file" - ln -s "$srcdir/$snippet_file" "./index_snippets/${published_unix}" + ln -s "$srcdir/$snippet_file" "./${tmp_snippets_dir}/${published_unix}" fi done # Write link list. -for file in ./index_snippets/*; do - touch ./index_snippets/list - cat "$file" ./index_snippets/list > ./index_snippets/tmp - mv ./index_snippets/tmp ./index_snippets/list +for file in ./${tmp_snippets_dir}/*; do + touch ./${tmp_snippets_dir}/list + cat "$file" ./${tmp_snippets_dir}/list > ./${tmp_snippets_dir}/tmp + mv ./${tmp_snippets_dir}/tmp ./${tmp_snippets_dir}/list done -if [ -e "./index_snippets/list" ]; then - cat ./index_snippets/list +if [ -e "./${tmp_snippets_dir}/list" ]; then + cat ./${tmp_snippets_dir}/list fi -rm -rf index_snippets +rm -rf "${tmp_snippets_dir}" # Write index footer. printf "
    \n\n" diff --git a/test.sh b/test.sh index d930e66..c54e48a 100755 --- a/test.sh +++ b/test.sh @@ -2,13 +2,13 @@ uuid_test() { -uuid_file="$1" -printf "== %s UUID pattern match test ==\n" "$uuid_file" -if cat "$uuid_file" | grep -Eq "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"; then - echo "== test SUCCESS ==" -else - echo "== test FAILURE ==" -fi + uuid_file="$1" + printf "== %s UUID pattern match test ==\n" "$uuid_file" + if cat "$uuid_file" | grep -Eq "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"; then + echo "== test SUCCESS ==" + else + echo "== test FAILURE ==" + fi } diff_test() @@ -42,13 +42,14 @@ redo cd "$working_dir" # Simple file comparison tests and UUID tests. -uuid_test "$generated_files_dir""/uuid.meta" -for file in "$expected_files_dir"/*.html "$expected_files_dir"/*.meta; do +uuid_test "$generated_files_dir""/.meta/uuid" +for file in "$expected_files_dir"/*.html "$expected_files_dir"/.meta/*; 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 - uuid_test "${cmp_file%.html}.uuid" + basename=$(basename "$cmp_file") + uuid_test "${generated_files_dir}/.meta/${basename%.html}.uuid" fi diff_test "$file" "$cmp_file" done diff --git a/test/test_files/author.meta b/test/test_files/.meta/author similarity index 100% rename from test/test_files/author.meta rename to test/test_files/.meta/author diff --git a/test/test_files/title.meta b/test/test_files/.meta/title similarity index 100% rename from test/test_files/title.meta rename to test/test_files/.meta/title diff --git a/test/test_files/url.meta b/test/test_files/.meta/url similarity index 100% rename from test/test_files/url.meta rename to test/test_files/.meta/url -- 2.30.2