# Image stream.
# Inspired by https://img.texto-plano.xyz.
MKSHELL=rc
IMGTYPES=png jpg jpeg gif
TARG=`{ls -t *.^($IMGTYPES) >[2] /dev/null}
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 $TARG $ALTS $CAPTIONS mkfile #_timestamps
{cat _header
for (entry in `{ls -t *.^(png jpg jpeg gif) >[2]/dev/null | sed 20q}) {
alt=''
if (test -r $entry^.alt) {alt=`{cat $entry^.alt}}
listing=`{ls -l $entry}
echo -n ''
echo -n '
'
echo ''
echo '
'
echo -n ''
if (test -r $entry^.caption) {cat $entry^.caption; echo '
'}
echo -n $listing(4)
echo -n ' — '
datefmt -t `{stat $entry} '%F %T'
echo ''
echo '
'
}
cat _footer} > $target
cp $target $target.html
# Atom feed.
index.atom:Q: _atomhead _timestamps $TARG $ALTS $CAPTIONS mkfile
now=`{datefmt %FT%T%z}
{cat _atomhead | sed 's/UPDATED/'^$now^'/'
echo ' '
for (entry in `{sort -rn _timestamps | awk '{print $2}'}) {
pubts=`{grep ' '$entry'$' _timestamps | awk '{print $1}'}
modts=`{stat $entry}
echo ' '
echo ' '$entry'' | sed 's/␣/ /g'
echo ' '
echo ' '$BASEURL'/'$entry''
echo -n ' '
datefmt -t $pubts %FT%T%z
echo ''
echo -n ' '
datefmt -t $modts %FT%T%z
echo ''
echo -n ' '
{
if (test -r $entry.alt) {
cat $entry.alt | htmlfmt -c utf-8 | sed 10q
}
}
echo ''
echo ' '
}
echo ''} > $target
# JSON Feed.
feed.json:Q: _jsonhead _timestamps $TARG $ALTS $CAPTIONS mkfile
entries=`{sort -rn _timestamps | awk '{print $2}'}
nentries=$#entries
{cat _jsonhead
echo ' "items": ['
for (entry in $entries) {
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": '
echo -n '"'
# {
# htmlfmt -c utf-8 $entry | ssam '0,/[^\n]+\n/+1d
# $-2,d
# ,s/\\/\\\\/g
# ,s/"/\\"/g
# ,s/(\[|\])/\\\1/g
# ,s/\n/\\n/g'
# }
echo '",'
echo -n ' "date_published": '
datefmt -t $pubts '"%FT%T%z",%n'
echo -n ' "date_modified": '
datefmt -t $modts '"%FT%T%z"%n'
echo -n ' }'
if (! ~ $entry $entries($nentries))
echo ','
if not
echo ''
}
echo ' ]'
echo '}' } > $target
# Some defaults for the first run.
_header:Q:
echo -n 'Making a default header... '
echo '' >_header
echo '' >>_header
echo '' >>_header
echo ' mkImg — image stream' >>_header
echo ' ' >>_header
echo '' >>_header
echo '' >>_header
echo '' >>_header
echo '' >>_header
echo 'done. Edit _header to customize it.
_footer:Q:
echo -n 'Making a default footer... '
echo '' >_footer
echo '
' >>_footer
echo '
' >>_footer
echo '' >>_footer
echo '' >>_footer
echo '' >>_footer
echo 'done. Edit _footer to customize it.
_jsonhead:Q:
echo -n 'Making a default header for the JSON feed... '
echo '{' >_jsonhead
echo ' "version": "https://jsonfeed.org/version/1.1",' >>_jsonhead
echo ' "title": "mkImg — Image stream",' >>_jsonhead
echo ' "home_page_url": "PUT_YOUR_URL_HERE",' >>_jsonhead
echo ' "feed_url": "PUT_YOUR_URL_HERE/feed.json",' >>_jsonhead
echo ' "authors": [' >>_jsonhead
echo ' {' >>_jsonhead
echo ' "name": "PUT_YOUR_NAME_HERE",' >>_jsonhead
echo ' "url": "PUT_YOUR_HOME_PAGE_URL_HERE"' >>_jsonhead
echo ' }' >>_jsonhead
echo ' ],' >>_jsonhead
echo 'done. Edit _jsonhead to customize it (the feed won''t work otherwise).'
_atomhead:Q:
echo -n 'Making a default header for the Atom feed... '
echo '' >_atomhead
echo '' >>_atomhead
echo ' mkImg — Image stream' >>_atomhead
echo ' ' >>_atomhead
echo ' UPDATED' >>_atomhead
echo ' ' >>_atomhead
echo ' PUT_YOUR_NAME_HERE' >>_atomhead
echo ' ' >>_atomhead
echo ' PUT_YOUR_URL_HERE' >>_atomhead
echo 'done. Edit _atomhead to customize it (the feed won''t work otherwise).'