From ff1677ec2b6a5ff077a5f619a7403f66e013701a Mon Sep 17 00:00:00 2001
From: Toke Eskildsen <te@ekot.dk>
Date: Wed, 4 Dec 2013 21:56:12 +0100
Subject: [PATCH] Fixed #23 (HTML-snippets in folders)

---
 folder_template.html |  2 +-
 image_template.html  |  2 +-
 quack.sh             | 24 ++++++++++++++++++++++++
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/folder_template.html b/folder_template.html
index 7fddc41..566bfc6 100644
--- a/folder_template.html
+++ b/folder_template.html
@@ -10,7 +10,7 @@
 
 <body class="folder">
 <h1>Quack <span style="color: #999">${SRC_FOLDER}</span></h1>
-<div class="foldersnippet">${SNIPPET_FOLDER}</div>
+<div class="foldersnippet">${SNIPPET}</div>
 
 <!-- TODO: Create decent bread crumbs -->
 <p>Parent folder: <a href="../index.html">${PARENT}</a></p>
diff --git a/image_template.html b/image_template.html
index 469f396..eb3f5aa 100644
--- a/image_template.html
+++ b/image_template.html
@@ -19,7 +19,7 @@ ${IDPREVS}
 <body class="previewpage">
 <h1>Quack <span style="color: #999">${SOURCE_SHORT}</span></h1>
 
-<div class="imagesnippet">${SNIPPET_IMAGE}</div>
+<div class="imagesnippet">${SNIPPET}</div>
 
 <div id="controlpanel" class="control">
 <p class="navigation">${NAVIGATION}</p>
diff --git a/quack.sh b/quack.sh
index b5603bf..8f97172 100755
--- a/quack.sh
+++ b/quack.sh
@@ -133,12 +133,23 @@ export OVERLAY_WHITE=FFFF00
 
 # Snippets are inserted verbatim at the top of the folder and the image pages.
 # Use them for specifying things like delivery date or provider notes.
+# Note that these snippet can be overridden on a per-folder and per-image basis
+# by creating special files in the source tree (see SPECIFIC_FOLDER_SNIPPET and
+# SPECIFIC_IMAGE_SNIPPET_EXTENSION below).
 export SNIPPET_FOLDER=""
 export SNIPPET_IMAGE=""
 
 
 # End default settings. User-supplied overrides will be loaded from quack.settings
 
+# If present in a source-folder, the content of the folder will be inserted into
+# the generated folder HTML file.
+SPECIFIC_FOLDER_SNIPPET="folder.snippet"
+
+# If a file with image basename + this extension is encountered, the content will
+# be inserted into the generated image HTML file.
+SPECIFIC_IMAGE_SNIPPET_EXTENSION=".snippet"
+
 
 pushd `dirname $0` > /dev/null
 ROOT=`pwd`
@@ -590,6 +601,14 @@ function makePreviewPage() {
     BASE=${SANS_PATH%.*}
     P="${DEST_FOLDER}/${BASE}.html"
 
+    local SSNIP="${BASE}${SPECIFIC_IMAGE_SNIPPET_EXTENSION}"
+
+    if [ -f $SSNIP ]; then
+        SNIPPET=`cat $SSNIP`
+    else
+        SNIPPET="$SNIPPET_FOLDER"
+    fi
+
     # Used by function caller
     PAGE_LINK="${BASE}.html"
 
@@ -742,6 +761,11 @@ function makeIndex() {
         exit
     fi
     pushd $SRC_FOLDER > /dev/null
+    if [ -f $SPECIFIC_FOLDER_SNIPPET ]; then
+        SNIPPET=`cat $SPECIFIC_FOLDER_SNIPPET`
+    else
+        SNIPPET="$SNIPPET_FOLDER"
+    fi
     local SRC_FOLDER=`pwd`
     popd > /dev/null
     echo "Processing $SRC_FOLDER"
-- 
GitLab