#!/bin/sh
# This script compiles the "works.html" page

make_item()
{
  sed "s/$/<\/div>/g" | \
  sed "s/^..\([^;]*\);\([^;]*\);\([^;]*\);/<div>\n  <img \2src=\"\3\"><\/img>\n  \1\n;/g" | \
  sed "s/;\([^;<]*\)/  <a href=\"\1\">*<\/a>\n/g" | \
  sed "s/|ALI|/https:\/\/archive.li\//g" | \
  sed "s/|BS|/https:\/\/blendswap.com\/blend\//g" | \
  sed "s/|CB|/https:\/\/codeberg.org\/drummyfish\//g" | \
  sed "s/|DA|/https:\/\/www.deviantart.com\/drummyfish\/art\//g" | \
  sed "s/|FLI|/https:\/\/www.flickr.com\/\/photos\//g" | \
  sed "s/|GL|/https:\/\/gitlab.com\//g" | \
  sed "s/|IA|/https:\/\/archive.org\/details\//g" | \
  sed "s/|IAW|/https:\/\/web.archive.org\/web\//g" | \
  sed "s/|IBB|/https:\/\/ibb.co\//g" | \
  sed "s/|IMW|/https:\/\/www.imagevenue.com\//g" | \
  sed "s/|LGW|/https:\/\/libregamewiki.org\/File:/g" | \
  sed "s/|MHC|/https:\/\/commons.miraheze.org\/wiki\/File:/g" | \
  sed "s/|NCH|/https:\/\/nch.pl\/s\//g" | \
  sed "s/|OGA|/https:\/\/opengameart.org\/content\//g" | \
  sed "s/|OGF|/https:\/\/opengameart.org\/sites\/default\/files\//g" | \
  sed "s/|PRT|/https:\/\/preservetube.com\/watch?v=/g" | \
  sed "s/|TF|/http:\/\/self.tastyfish.cz\/files\//g" | \
  sed "s/|W10|/http:\/\/tastyfish.w10.site\/images\//g" | \
  sed "s/|WID|/https:\/\/www.vidlii.com\/watch?v=/g" | \
  sed "s/|WMC|/https:\/\/commons.wikimedia.org\/wiki\/File:/g" | \
  sed "s/|WMT|/https:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\//g" | \
  sed "s/|YT|/https:\/\/inv.nadeko.net\/watch?v=/g"
}

sed -n -e '/DOCTYPE html/,/SECTION 0 START/ p' works.html > __tmp.html
cat works.html | grep "^#0" | make_item >> __tmp.html
sed -n -e '/SECTION 0 END/,/SECTION 1 START/ p' works.html >> __tmp.html
cat works.html | grep "^#1" | make_item >> __tmp.html
sed -n -e '/SECTION 1 END/,/\/html/ p' works.html >> __tmp.html

mv __tmp.html works.html
