summaryrefslogtreecommitdiff
path: root/gen.sh
diff options
context:
space:
mode:
authorknolax <1339802534.kk@gmail.com>2017-11-14 08:53:43 -0500
committerknolax <1339802534.kk@gmail.com>2017-11-14 08:53:43 -0500
commite6116f2dde5c3b38b4cab55899e3e23c55d8ede7 (patch)
treee59718d5e10136a5535bc2d65b28fb9597abe0f1 /gen.sh
initial commit
Diffstat (limited to 'gen.sh')
-rwxr-xr-xgen.sh43
1 files changed, 43 insertions, 0 deletions
diff --git a/gen.sh b/gen.sh
new file mode 100755
index 0000000..a870ab3
--- /dev/null
+++ b/gen.sh
@@ -0,0 +1,43 @@
+pages=$(ls -S -t cont/| grep html | grep -v home.html) #lists the actual content
+#-S -t so that the files are roughly in time order
+#home is excluded and appended at the end to make sure it gets processed last
+pages="$pages home.html"
+#clears the index
+rm index
+for page in $pages; do
+ #clears page and page.tmp
+ rm $page $page.tmp
+ #adds the header
+ cat src/header.html >> $page.tmp
+
+ #finds the [SETTITLE], but ignores \[SETTITLE], then filters out the [SETTITLE] part
+ #the head is to make it use the last one
+ title=$(cat cont/$page | grep '\[SETTITLE\]'| sed '/\\\[SETTITLE\]/d; s/\[SETTITLE\]//' | tail -n 1)
+ #does the same for the date
+ date=$(cat cont/$page | grep '\[SETDATE\]'| sed '/\\\[SETDATE\]/d; s/\[SETDATE\]//' | tail -n 1)
+
+
+ #replaces \[SETTITLE] with [SETTITLE], and removes lines with legitimate [SETTITLE]s in a temporary file
+ cat cont/$page | sed '/\\\[SETTITLE\]/bx; /\[SETTITLE\].*/d;:x s/\\\[SETTITLE\]/\[SETTITLE\]/' >> $page.tmp
+ #same for the date
+ cat $page.tmp | sed '/\\\[SETDATE\]/bx; /\[SETDATE\].*/d;:x s/\\\[SETDATE\]/\[SETDATE\]/' >> $page
+
+ #adds the index if its the homepage
+ if [ "$page" == "home.html" ]; then
+ cat index >> $page
+ rm index
+ fi
+ #adds the footer
+ cat src/footer.html >> $page
+
+ #replaces \[TITLE] with [TITLE] and [TITLE] with $title, "" is used so the $ still applies
+
+ #however that means "\\\\" becomes "\\" when passed to sed from bash, and finally interpreted as a literal \ by sed
+ cat $page | sed "/\\\\\[TITLE\]/bx; s/\[TITLE\]/$title/; :x s/\\\\\[TITLE\]/\[TITLE\]/" > $page.tmp
+ #same with date
+ cat $page.tmp | sed "/\\\\\[DATE\]/bx; s/\[DATE\]/$date/; :x s/\\\\\[DATE\]/\[DATE\]/" > $page
+
+ rm $page.tmp
+ #adds to the index
+ echo "<a href=\"$page\">[$title] $date</a>" >> index
+done