#!/bin/bash

rm -r output/*.html

genHTML(){
	content=$1

	cat <<< '<!DOCTYPE html>
	<html lang="de">'
	
	cat <<< '
	<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
   	<meta charset="utf-8">
    	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    	<meta name="description" content="">
    	<meta name="author" content="">
    	<link rel="icon" href="https://getbootstrap.com/favicon.ico">
	<!-- please dont judge me, im not getting paid for this. -->'
	
    	cat <<< "<title>$(basename $content .html)</title>"

	cat <<< '
	<!-- Bootstrap core CSS -->
    	<link href="ressources/bootstrap.css" rel="stylesheet">
    	<!-- Custom styles for this template -->
    	<link href="ressources/sticky-footer-navbar.css" rel="stylesheet">
	</head>'

	# begin navbar content

	cat <<< '<header><nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">'
	cat <<< '<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>'

	cat <<< '<div class="collapse navbar-collapse" id="navbarCollapse">'
	cat <<< '<ul class="navbar-nav mr-auto">'

	cat <<< '<a class="navbar-brand" href="#">Navigation</a>'

	for navitem in content/*.html
	do
		pagename=$(basename $navitem .html)
		if [[ "$navitem" == "$content" ]]
		then
		        cat <<< '<li class="nav-item active">'
			cat <<< "<a class=\"nav-link\" href=\"#\">$pagename</a>"
		else
			cat <<< '<li class="nav-item">'
			cat <<< "<a class=\"nav-link\" href=\"$(basename $navitem)\">$pagename</a>"
		fi
		cat <<< '</li>'
	done
	cat <<< '</ul>'
	cat <<< '</div>'
	cat <<< '</nav></header>'
	# end navbar content
	
	cat <<< '<body>'
	# begin main content
	cat $content 
	# end main conteint
	cat footer.html
	cat scripts.html
	cat <<< '</body></html>'
}


for content in content/*.html
do
	genHTML $content > output/$(basename $content)
done
