bashtube/templates/header.shs

80 lines
4.1 KiB
Bash

#!/bin/bash
##inherited from HTTP.sh's /templates/head.sh so that BashTube won't light on fire when I merge it LMAO ~luna
echo '<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">'
if [[ "${meta[title]}" != "" ]]; then echo "<title>$(html_encode "${meta[title]}") - ${cfg[title]}</title>"; else echo "<title>${cfg[title]}</title>"; fi
if [[ "${meta[author]}" != "" ]]; then echo "<meta name='author' content='$(html_encode "${meta[author]}")'>"; fi
if [[ "${meta[description]}" != "" ]]; then echo "<meta name='description' content='$(html_encode "${meta[description]}")'>"; fi
if [[ "${meta[keywords]}" != "" ]]; then echo "<meta name='keywords' content='$(html_encode "${meta[keywords]}")'>"; fi
if [[ "${meta[refresh]}" != "" ]]; then echo "<meta http-equiv='refresh' content='$(html_encode "${meta[refresh]}")'>"; fi
if [[ "${meta[redirect]}" != "" ]]; then echo "<meta http-equiv='refresh' content='0; URL=$(html_encode "${meta[redirect]}")'>"; fi
if [[ "${meta[css]}" != "" ]]; then echo "<link rel='stylesheet' type='text/css' href='$(html_encode "${meta[css]}")'/>"; fi
if [[ "${meta[title]}" != "" ]]; then echo "<meta property='og:title' content='$(html_encode "${meta[title]}")'>"; fi
#if [[ "${meta[og:type]}" != "" ]]; then echo "<meta property='og:type' content='${meta[og:type]}'>"; fi
if [[ "${cfg[url]}" != "" ]]; then echo "<meta property='og:url' content='$(html_encode "${cfg[url]}")'>"; fi
#if [[ "${meta[og:image}" != "" ]]; then echo "<meta property='og:image' content='${meta[og:image]}'>"; fi
if [[ "${meta[lang]}" != "" ]]; then echo "<meta property='og:locale' content='$(html_encode "${meta[lang]}")'>"; fi
if [[ "${meta[description]}" != "" ]]; then echo "<meta property='og:description' content='$(html_encode "${meta[description]}")'>"; fi
if [[ "${meta[unsafe]}" != "" ]]; then echo "${meta[unsafe]}"; fi
#the CSS part has been moved to /app/webroot/css/style.css :3
#echo "<style>
# body {
# background-color: #1a1a1a;
# color: #ccc;
# }
# a {
# color: #3d3;
# }
# a:visited {
# color: #3b3;
# }
# tr:nth-child(2n) {
# background-color: #333;
# }
# </style>
#</head>"
declare -A strings_
#echo "<!DOCTYPE html><meta content='width=device-width, initial-scale=1.0'><link rel='shortcut icon' href='/favicon.ico'>
#<link rel='stylesheet' href='/css/style.css'><a href='/'><img src='/img/bashtube.png'></a><br>"
if [[ ${cfg[template]} == 'default-v2' ]]; then
echo "<link rel='shortcut icon' href='/favicon.ico'>
<link rel='stylesheet' href='/css/style.css'><table style='border: 0px solid black; padding:0px;margin:0px;width:100%;'><tr><td><a href='/'><img src='/img/bashtube.png'></a></td><td style='text-align:right;'>"
if ! session_verify "${cookies[sh_session]}"; then
echo "<a href='/login.shs'>Log in</a><br><a href='/register.shs'>Register</a>"
else
echo "Logged in as ${cookies[username]}<br><a href='/logout.shs'>Log out</a><br><a href='/feed.shs'>Your feed</a><br><a href='/fav.shs'>Your favourites</a><br><a href='/subscribe.shs'>Your subscriptions</a>"
fi
echo "</td></tr></table>"
else
echo "<link rel='shortcut icon' href='/favicon.ico'><link rel='stylesheet' href='/css/style.css'><a href='/'><img src='/img/bashtube.png'></a><br>"
if ! session_verify "${cookies[sh_session]}"; then
echo "<a href='/login.shs'>Log in</a> | <a href='/register.shs'>Register</a>"
else
echo "Logged in as ${cookies[username]} | <a href='/logout.shs'>Log out</a> | <a href='/feed.shs'>Your feed</a> | <a href='/fav.shs'>Your favourites</a>"
fi
fi
# TODO: move this to a *real* template
# we'll need to figure out conditional templates first tho
if [[ "$query_nice" != '' ]]; then
strings_[query_nice]="$query_nice"
else
strings_[query_nice]=''
fi
render strings_ "${cfg[namespace]}/templates/themes/${cfg[template]}/elements/top.html"