# Image stream.
# Inspired by https://img.texto-plano.xyz.
MKSHELL=rc
IMGTYPES=png jpg jpeg gif
TARG=`{ls -t | grep -i '\.(png|jpe?g|gif)$' >[2] /dev/null | sed 20q}
ALTS=`{ls $TARG^.alt >[2] /dev/null}
CAPTIONS=`{ls $TARG^.caption >[2] /dev/null}
BASEURL='http://a.9srv.net/img'
update:VQ: index index.atom feed.json mkfile # _timestamps
# echo $IMGTYPES – $TARG $ALTS $CAPTIONS
clean:VQ:
rm -f index index.html >[2] /dev/null
{cat _header
echo '
There are no entries in the current blog.
'
cat _footer} > index.html
#%: _header _footer
# If an entry doesn't have a timestamp, make one from mod time or now.
_timestamps:Q: $TARG
for (i in $TARG) {
if (! grep -s ' '$i'$' $target >[2] /dev/null) {
echo 'adding timestamp for' $i
t=`{stat $i || date -n}
echo $t' '$i >> $target
}
}
touch $target
index:Q: _header _footer _timestamps $TARG $ALTS $CAPTIONS mkfile
{cat _header
#for (entry in `{ls -t *.^(png jpg jpeg gif) >[2]/dev/null | sed 20q}) {
for (entry in $TARG) {
alt=''
if (test -r $entry^.alt) {alt=`{cat $entry^.alt}}
pubts=`{grep ' '$entry'$' _timestamps | awk '{print $1}'}
modts=`{stat $entry}
listing=`{ls -l $entry}
echo -n ''
echo -n '
'
echo ''
echo '
'
echo -n ''
if (test -r $entry^.caption) {cat $entry^.caption; echo '
'}
echo -n ''
echo -n $listing(4)
echo -n ' — '
datefmt -t $modts '%F %T'
if (! ~ $modts $pubts) {
echo -n ' (orig: '
datefmt -t $pubts '%F %T'
echo -n ')'
}
echo ''
echo ''
echo '
'
}
cat _footer} > $target
cp $target $target.html
# Atom feed.
index.atom:Q: _atomhead _timestamps $TARG $ALTS $CAPTIONS mkfile
now=`{datefmt %FT%T%:}
{cat _atomhead | sed 's/UPDATED/'^$now^'/'
echo ' '
for (entry in $TARG) {
alt=''
caption=''
if (test -r $entry^.alt) {alt=`{cat $entry.alt | htmlfmt -c utf-8 | sed 10q}}
if (test -r $entry^.caption) {caption=`{cat $entry.caption | htmlfmt -c utf-8 | sed 10q}}
pubts=`{grep ' '$entry'$' _timestamps | awk '{print $1}'}
modts=`{stat $entry}
mtype=`{file -m $entry}
echo ' '
echo ' '$entry'' | sed 's/␣/ /g'
echo ' '
echo ' '$BASEURL'/#'$entry''
echo -n ' '
datefmt -t $pubts %FT%T%:
echo ''
echo -n ' '
datefmt -t $modts %FT%T%:
echo ''
echo ' '
# echo ' '
# echo ' '
# echo -n '
'
# echo ' '
echo -n ' '
{
if (! ~ $caption '')
echo $caption
if not if (! ~ $alt '')
echo $alt
}
echo ''
echo ' '
}
echo ''} > $target
# JSON Feed.
feed.json:Q: _jsonhead _timestamps $TARG $ALTS $CAPTIONS mkfile
#entries=`{sort -rn _timestamps | awk '{print $2}'}
#nentries=$#entries
nentries=$#TARG
{cat _jsonhead
echo ' "items": ['
#for (entry in $entries) {
for (entry in $TARG) {
alt=''
caption=''
# XXX These need better escaping for json.
if (test -r $entry^.alt) {alt=`{cat $entry.alt | htmlfmt -c utf-8 | sed 10q}}
if (test -r $entry^.caption) {caption=`{cat $entry.caption | htmlfmt -c utf-8 | sed 10q}}
pubts=`{grep ' '$entry'$' _timestamps | awk '{print $1}'}
modts=`{stat $entry}
echo ' {'
echo ' "id": "'$BASEURL'/index.html#'$entry'",'
echo ' "url": "'$BASEURL'/index.html#'$entry'"',
echo ' "image": "'$BASEURL'/'$entry'"',
# Need to get escaping right before including $entry.caption or $entry.alt here.
echo -n ' "content_text": "'
{
if (! ~ $caption '')
echo -n $caption
if not if (! ~ $alt '')
echo -n $alt
}
echo '",'
echo -n ' "date_published": '
datefmt -t $pubts '"%FT%T%:",%n'
echo -n ' "date_modified": '
datefmt -t $modts '"%FT%T%:"%n'
echo -n ' }'
if (! ~ $entry $TARG($nentries))
echo ','
if not
echo ''
}
echo ' ]'
echo '}' } > $target
# Some defaults for the first run.
_header:Q:
echo -n 'Making a default header... '
{echo ''
echo ''
echo ''
echo ' mkImg — image stream'
echo ' '
echo ' '
echo ' '
echo ''
echo ''
echo ''
echo ''} > $target
echo 'done. Edit _header to customize it.'
_footer:Q:
echo -n 'Making a default footer... '
{echo ''
echo '
'
echo '
'
echo ''
echo ''
echo ''} >_footer
echo 'done. Edit _footer to customize it.'
_jsonhead:Q:
echo -n 'Making a default header for the JSON feed... '
{echo '{'
echo ' "version": "https://jsonfeed.org/version/1.1",'
echo ' "title": "mkImg — Image stream",'
echo ' "home_page_url": "'$BASEURL'",'
echo ' "feed_url": "'$BASEURL'/feed.json",'
echo ' "authors": ['
echo ' {'
echo ' "name": "PUT_YOUR_NAME_HERE",'
echo ' "url": "PUT_YOUR_HOME_PAGE_URL_HERE"'
echo ' }'
echo ' ],'} >_jsonhead
echo 'done. Edit _jsonhead to customize it.'
_atomhead:Q:
echo -n 'Making a default header for the Atom feed... '
{echo ''
echo ''
echo ' mkImg — Image stream'
echo ' '
echo ' UPDATED'
echo ' '
echo ' PUT_YOUR_NAME_HERE'
echo ' '
echo ' PUT_YOUR_URL_HERE'} >_atomhead
echo 'done. Edit _atomhead to customize it.'