#!/usr/bin/bash

### 1. Get input files:

echo $1

cat $1 footer |


### 2. Normal text:

# Headers
sed 's/\(^\* \)\(.*$\)/<h1>\2<\/h1>/' |

sed 's/\(^\~ \)\(.*$\)/<h3>✳ \2<\/h3>/' |

# Paragraphs
sed 's/^[A-Z].*$/<p>&<\/p>/' |

# Quotes
sed 's/\(^\| \)\("\)/\1<span style="color:#626e74">/g' |
sed 's/\("\)\( \|,\|\.\|:\|)\)/<\/span>\2/g' |


### 3. Separators:

# Blank lines
sed 's/^$/<br>/' |

# Separators
sed 's/^\.$/<hr>/' |


### 4. Links:

# Images
sed 's/^.*\.\(jpg\|png\|gif\)$/<img src="&">/' |

# Internal links
sed 's/\(-\)\(https.*\)\( desc: \)\(.*\)\(-\)/<a href="\2">\4<\/a>/' |

# External links
sed 's/\(_\)\(https.*\)\( desc: \)\(.*$\)/<a href="\2" target="_blank">\4<\/a>/' > tmpfile


### 5. Initial boilerplate:

echo '<!DOCTYPE html>
<html lang=en>
<head>
	<meta charset=utf-8>
	<title>oviel-azur</title>
	<link rel="icon" type="image/x-icon" href="https://ctrl-c.club/~oviel/img/favicon.png">
	<link rel="stylesheet" href="../css/general.css">
</head>
<body>
<img id="label" src="https://ctrl-c.club/~oviel/img/ruppert.png">
' > ../html/$1.html


### 6. Add the content:

cat tmpfile >> ../html/$1.html
rm tmpfile


### 7. Final boilerplate:

echo '
</body>
</html>' >> ../html/$1.html

