#!/bin/sh

# soc - Stream Of Consciousness mini-logger
# Copyright 2014 David Meyer <papa@sdf.org> +JMJ
# grabbed from : https://tilde.center/~papa/soc.html

# Modified by pgadey to include:
#	-- total entry count
#	-- anchors to all dates

# to do:
# 	-- split in to static blog generator and post creator




socdir=/home/pgadey/public_html/soc
socext=soc
outfile=/home/pgadey/public_html/soc/index.html

BASENAME=/usr/bin/basename
CAT=/bin/cat
DATE=/bin/date
ECHO=echo
FORTUNE=/usr/games/fortune
LS=ls
SORT=/usr/bin/sort

date=$($DATE +%F)
time=$($DATE +%R)

$ECHO "<li>[$time<a id=\"#$date-$time\"></a>] $* </li>" >>$socdir/$date.$socext

$CAT >$outfile <<EOF
<!DOCTYPE html>

<html>
  <head>
    <title>~pgadey</title>
    <meta charset="UTF-8" />
    <link rel="stylesheet" type="text/css" href="./screen.css">
  </head>
  <body>
    <h1>~pgadey's &micro;-blog</h1>
    <p>
      <a href="http://ctrl-c.club/~pgadey/">home</a>
      <a href="#stats">stats</a>
    </p>
    <hr>
EOF

for f in $($LS -r $socdir/*.$socext); do
    bn=${f##*/}
    fd=${bn%.*}
    $ECHO "<h2><a id=\"#$fd\">$fd</a></h2>" >>$outfile	# add headers with anchors for each date
    $ECHO "<ul>" >>$outfile
    $SORT -r $f >>$outfile
    $ECHO "</ul>" >>$outfile
done

$CAT >>$outfile <<EOF
    <hr>
    <pre id="stats">
EOF

#$FORTUNE >>$outfile

echo $(ls -1 $socdir/ | wc -l) "days with records" >> $outfile

$CAT >>$outfile <<EOF
    </pre>
    <div id="sitelink" style="width=100%;text-align:center;">
      <a href="/"><em>ctrl-c.club</em></a><br>
      <p><small>This page was generated by a modified version of <a href="https://tilde.center/~papa/soc.html">soc</a> written by <a href="https://tilde.center/~papa/">~papa</a>@<a href="http://tilde.center">tilde.center</a>.</small></p>



    </div>

  </body>
</html>
EOF
