home · contact · privacy
Move snippet generation for index/feed into separate .do files.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 11 Dec 2016 23:06:49 +0000 (00:06 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 11 Dec 2016 23:06:49 +0000 (00:06 +0100)
processor/default.feed_snippet.do [new file with mode: 0644]
processor/default.index_snippet.do [new file with mode: 0644]
processor/feed.xml.do
processor/helpers.sh
processor/index.html.do

diff --git a/processor/default.feed_snippet.do b/processor/default.feed_snippet.do
new file mode 100644 (file)
index 0000000..9d33ad9
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# Pull in dependencies. 
+. ./helpers.sh
+src_file=$(get_source_file "$1")
+uuid_file="${1%.feed_snippet}.uuid"
+redo-ifchange "$uuid_file"
+intermediate_file="${src_file%.*}.intermediate"
+redo-ifchange "$intermediate_file"
+
+# Get variables, write entry.
+html_file=`escape_url "${src_file%.*}.html"`
+lastmod=`stat -c%y "$src_file"`
+lastmod_rfc3339=`date -u "+%Y-%m-%dT%TZ" -d "$lastmod"`
+published=`stat -c%y "$uuid_file"`
+published_rfc3339=`date -u "+%Y-%m-%dT%TZ" -d "${published}"`
+title=`read_and_escape_file "$intermediate_file" | head -1`
+uuid=`read_and_escape_file "$uuid_file" | head -1`
+body=`read_and_escape_file "$intermediate_file" | sed 1d`
+printf "<entry>\n"
+printf "<title type=\"html\">%s</title>\n" "$title"
+printf "<id>urn:uuid:%s</id>\n" "$uuid"
+printf "<updated>%s</updated>\n" "$lastmod_rfc3339"
+printf "<published>%s</published>\n" "$published_rfc3339"
+printf "<link href=\"%s%s\" />\n" "$(get_basepath)" "${html_file#\./}"
+printf "<content type=\"html\">\n%s\n</content>\n" "$body"
+printf "</entry>\n"
diff --git a/processor/default.index_snippet.do b/processor/default.index_snippet.do
new file mode 100644 (file)
index 0000000..759a510
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+# Pull in dependencies.
+. ./helpers.sh
+src_file=$(get_source_file "$1")
+intermediate_file="${src_file%.*}.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#\./}"`
+printf "<li><a href=\"%s\" />%s</a></li>\n" "$html_file_escaped" "$title_html"
index a0349110ec24297e362ac23cc43b8b7961708a37..16011f3d744331f3142030554660e6a5b02a7178 100644 (file)
@@ -1,32 +1,7 @@
 #!/bin/sh
 
-build_entry () {
-  file="${1}"
-  uuidfile="${2}"
-  published="${3}"
-  intermediate_file="${file%.*}.intermediate"
-  htmlfile=`escape_url "${file%.*}.html"`
-  redo-ifchange "$uuid_file"
-  redo-ifchange "$intermediate_file"
-  lastmod=`stat -c%y "$file"`
-  lastmod_rfc3339=`date -u "+%Y-%m-%dT%TZ" -d "$lastmod"`
-  title=`read_and_escape_file "$intermediate_file" | head -1`
-  uuid=`read_and_escape_file "$uuid_file" | head -1`
-  body=`read_and_escape_file "$intermediate_file" | sed 1d`
-  published_rfc3339=`date -u "+%Y-%m-%dT%TZ" -d "${published}"`
-  printf "<entry>\n"
-  printf "<title type=\"html\">%s</title>\n" "$title"
-  printf "<id>urn:uuid:%s</id>\n" "$uuid"
-  printf "<updated>%s</updated>\n" "$lastmod_rfc3339"
-  printf "<published>%s</published>\n" "$published_rfc3339"
-  printf "<link href=\"%s%s\" />\n" "$basepath" "${htmlfile#\./}"
-  printf "<content type=\"html\">\n%s\n</content>\n" "$body"
-  printf "</entry>"
-}
-
 # Pull in global dependencies.
 . ./helpers.sh
-url_file=url.meta
 author_file=author.meta
 uuid_file=uuid.meta
 title_file=title.meta
@@ -37,11 +12,8 @@ redo-ifchange "$title_file"
 
 # Build some variables. XML-escape even file contents that should not contain
 # dangerous characters, just to avoid any XML trouble.
-base_url=`cat "$url_file" | head -1`
-url_protocol=`echo $base_url | cut -d ':' -f 1`
-url_basepath=`echo $base_url | cut -d '/' -f 3-`
-url_basepath_escaped=`escape_url "$url_basepath"`
-basepath="$url_protocol""://""$url_basepath_escaped"
+srcdir=`pwd`
+basepath=$(get_basepath)
 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`
@@ -65,8 +37,9 @@ for file in ./*.rst ./*.md; do
     redo-ifchange "$uuid_file"
     published=`stat -c%y "${uuid_file}"`
     published_unix=$(date -u "+%s%N" -d "${published}")
-    entry=$(build_entry "${file}" "${uuid_file}" "${published}")
-    echo "${entry}" > ./feed_snippets/${published_unix}
+    snippet_file="${file%.*}.feed_snippet"
+    redo-ifchange "$snippet_file"
+    ln -s "$srcdir/$snippet_file" "./feed_snippets/${published_unix}"
   fi
 done
 
index c90e077dc9a37dc444c9a2d778d045fcc1c11e20..cc12358cdd1618c3b6c27f0fdbe2a1b26091af72 100644 (file)
@@ -1,19 +1,41 @@
 #!/bin/sh
 
-escape_html()
-{
-out=`python3 -c 'import sys, html; print(html.escape(sys.argv[1]))' "$1"`
-printf "%s" "$out"
+escape_html() {
+  out=`python3 -c 'import sys, html; print(html.escape(sys.argv[1]))' "$1"`
+  printf "%s" "$out"
 }
 
-read_and_escape_file()
-{
-in=`cat "$1"`
-escape_html "$in"
+read_and_escape_file() {
+  in=`cat "$1"`
+  escape_html "$in"
 }
 
-escape_url()
-{
-out=`python3 -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1]))' "$1"`
-printf "%s" "$out"
+escape_url() {
+  out=`python3 -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1]))' "$1"`
+  printf "%s" "$out"
+}
+
+get_basepath() {
+  url_file=url.meta
+  redo-ifchange "$url_file"
+  base_url=`cat "$url_file" | head -1`
+  url_protocol=`echo $base_url | cut -d ':' -f 1`
+  url_basepath=`echo $base_url | cut -d '/' -f 3-`
+  url_basepath_escaped=`escape_url "$url_basepath"`
+  basepath="$url_protocol""://""$url_basepath_escaped"
+  echo "$basepath"
+}
+
+get_source_file() {
+  md_file="${1%.*}.md"
+  rst_file="${1%.*}.rst"
+  if [ -f "$rst_file" ]; then
+    src_file="$rst_file"
+  elif [ -f "$md_file" ]; then
+    src_file="$md_file"
+  else
+    exit 1
+  fi
+  redo-ifchange "$src_file"
+  printf "$src_file"
 }
index dca7c33bacc4795c5e727f2bdd2dd6e3f2e062c1..af8ba85e225e05599ba7cca418f68ad453b9376f 100644 (file)
@@ -2,6 +2,7 @@
 
 # Pull in global dependencies.
 . ./helpers.sh
+srcdir=`pwd`
 title_file=title.meta
 redo-ifchange "$title_file"
 
@@ -23,13 +24,9 @@ for file in ./*.rst ./*.md; do
     redo-ifchange "$uuid_file"
     published=`stat -c%y "${uuid_file}"`
     published_unix=$(date -u "+%s%N" -d "${published}")
-    intermediate_file="${file%.*}.intermediate"
-    html_file="${file%.*}.html"
-    redo-ifchange "$intermediate_file"
-    redo-ifchange "$html_file"
-    title_html=`cat "$intermediate_file" | head -1`
-    html_file_escaped=`escape_url "${html_file#\./}"`
-    printf "<li><a href=\"%s\" />%s</a></li>\n" "$html_file_escaped" "$title_html" > ./index_snippets/${published_unix}
+    snippet_file="${file%.*}.index_snippet"
+    redo-ifchange "$snippet_file"
+    ln -s "$srcdir/$snippet_file" "./index_snippets/${published_unix}"
   fi
 done