#!/bin/bash

indexFile="./index.html"

cat > $indexFile << EOF
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="alternate" type="application/rss+xml" title="RSS" href="http://cakelab.org/lamamarkwebber/feed.xml" />
<title>Lama Mark Webber Audio Archive</title>
</head>
<body>
EOF

for folder in `find . -type d -maxdepth 1`; do
	cat > $folder/index.html << EOF
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="alternate" type="application/rss+xml" title="RSS" href="http://cakelab.org/lamamarkwebber/feed.xml" />
<title>Lama Mark Webber Audio Archive</title>
</head>
<body>
<p>
EOF
	cat $folder/description.txt >> $folder/index.html
	echo "</p>" >> $folder/index.html
	echo "<p>" >> $folder/index.html
	for mp3 in `find $folder -name "*.mp3" | sort`; do
		mp3name=`basename $mp3`
		echo "<a href=\"https://cakelab.org/lamamarkwebber/$mp3\">$mp3name</a><br>" >> $folder/index.html
	done
	echo "</p>" >> $folder/index.html
	cat >> $folder/index.html << EOF
</body>
</html>
EOF
	
done

cat >> $indexFile << EOF
</body>
</html>
EOF
