#!/usr/bin/env bash

toc=$(./toc.sh)

echo -e "START_TOC\n$toc\n\nEND_TOC" > temp.md

if [ -f index.md ]; then
    perl -i -p0e 's/START_TOC.*END_TOC/`cat temp.md`/se' index.md
    # sed -i "s/START_TOC.*END_TOC/\${toc}/g" index.md
else
    echo -e "# Index \n\n START_TOC \n $toc \n END_TOC" > index.md
fi

rm temp.md
