Add $FILE feature and remove test files
authorMira Ayre <mi@boxin.space>
Fri, 15 Jan 2021 23:41:56 +0000 (23:41 +0000)
committerMira Ayre <mi@boxin.space>
Fri, 9 Jul 2021 19:41:28 +0000 (20:41 +0100)
PREFIX [deleted file]
README
SUFFIX [deleted file]
a.cf [deleted file]
lib/core.sh
ssg
test with spaces [deleted file]
test.cf [deleted file]
test.html [deleted file]

diff --git a/PREFIX b/PREFIX
deleted file mode 100644 (file)
index c914b70..0000000
--- a/PREFIX
+++ /dev/null
@@ -1 +0,0 @@
-<pre>This goes at the start
diff --git a/README b/README
index c6e0e4c492eb7ef2a6ccbe772d5f9834b644e33c..9942067f648e0b8e3c6db6d22cf92cc2d745d9c2 100644 (file)
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-                                                ### Static Site Generator ###
+                         ### Static Site Generator ###
 
 SSG is a collection of scripts for simplified generation of basic static
 websites.
@@ -44,6 +44,9 @@ By default, these scripts are expected to be in `$XDG_DATA_HOME/ssg` falling
 back to `~/.local/share/ssg`. All files in this directory are sourced when
 invoking ssg.
 
+Functions called from within content and affix files have access to the `$FILE`
+variable that contains the path to the initial file passed to SSG.
+
 # USAGE
 
 ssg FILE
diff --git a/SUFFIX b/SUFFIX
deleted file mode 100644 (file)
index e0edc4c..0000000
--- a/SUFFIX
+++ /dev/null
@@ -1 +0,0 @@
-This goes at the end</pre>
diff --git a/a.cf b/a.cf
deleted file mode 100644 (file)
index d48f45a..0000000
--- a/a.cf
+++ /dev/null
@@ -1 +0,0 @@
-This was included from another file
index 155f48ae2724f1a9a04184c4470b6230e8c2c021..5beacf85d155cf51210c0eee6f659a8c93ec4771 100644 (file)
@@ -21,5 +21,7 @@ function indexh() { # index with header
 }
 
 function git-history() {
-       git log --follow --format='%h %ad: %s<br/>' --date='format:%d-%m-%Y' "$0"
+       git log --follow --format='%h %ad: %s<br/>' \
+               --date='format:%d-%m-%Y' "$FILE" \
+               | tr -d "\n"
 }
diff --git a/ssg b/ssg
index 705cf0fc442b5976af96e3dfb87d36e560172f04..5abdd63a9b60d4ac9cd9fbfcf2894c48f86eb3ab 100755 (executable)
--- a/ssg
+++ b/ssg
@@ -37,7 +37,7 @@ done
 cat PREFIX "$file" SUFFIX 2>/dev/null | while IFS= read l ; do
        if [[ "$l" == ';;'* ]] ; then
                echo "running command '${l:2}'" > /dev/stderr
-               eval "${l:2}"
+               eval "FILE='$file' ${l:2}"
        else
                echo "$l"
        fi
diff --git a/test with spaces b/test with spaces
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/test.cf b/test.cf
deleted file mode 100644 (file)
index dd40297..0000000
--- a/test.cf
+++ /dev/null
@@ -1,18 +0,0 @@
-<h1>This is the header</h1>
-
-Here's the contents of my `~/`:
-;;ls ~
-
-       and here's some fancy text
-
-           with indents                  and large spaces
-
-;;include a.cf
-
-<b>Index of current directory</b>
-
-;;index
-
-<b>File history</b>
-
-;;git-history
diff --git a/test.html b/test.html
deleted file mode 100644 (file)
index 7b20358..0000000
--- a/test.html
+++ /dev/null
@@ -1,21 +0,0 @@
-<pre>This goes at the start
-<h1>This is the header</h1>
-
-Here's the contents of my `~/`:
-daysoftheweek.csv
-daysoftheweek.wav
-dnl
-doc
-prj
-vid
-
-       and here's some fancy text
-
-           with indents                  and large spaces
-
-This was included from another file
-
-Index of current directory
-
-<b>---------- name                               date                          size</b><br/>
-drwxr-xr-x <a href="../">../</a>                                15-01-2021 20:07              4096<br/>-rw-r--r-- <a href="a.cf">a.cf</a>                               15-01-2021 22:07                36<br/>drwxr-xr-x <a href="lib/">lib/</a>                               15-01-2021 23:12              4096<br/>-rw-r--r-- <a href="LICENCE">LICENCE</a>                            15-01-2021 20:53             13005<br/>-rw-r--r-- <a href="PREFIX">PREFIX</a>                             15-01-2021 21:37                28<br/>-rw-r--r-- <a href="README">README</a>                             15-01-2021 20:53              2366<br/>-rwxr-xr-x <a href="ssg">ssg</a>                                15-01-2021 22:16               877<br/>-rw-r--r-- <a href="SUFFIX">SUFFIX</a>                             15-01-2021 21:37                27<br/>-rw-r--r-- <a href="test.cf">test.cf</a>                            15-01-2021 22:39               209<br/>-rw-r--r-- <a href="test.html">test.html</a>                          15-01-2021 23:13              1334<br/>-rw-r--r-- <a href="test with spaces">test with spaces</a>                   15-01-2021 22:27                 0<br/>This goes at the end</pre>