optimized header creation, now has configuration

This commit is contained in:
bluesaxman 2019-05-01 11:53:58 -06:00
parent 0e71232a62
commit fd198d82a9

View File

@ -12,12 +12,22 @@ my $js_dir = "/js/"; #must be in docroot
my $data_dir = "./dynamic/";
# What are my configurations?
my $system_base = `pwd`;
chomp($system_base);
my $site_base = "/";
my $site_name = "Murkfall Mountain";
my $site_symbol = "&#9968";
my $site500 = "There was an oopsy";
my $site404 = "There is nothing here...";
# What files should we include in our header
my @header_includes = (
{"file" => $img_dir."favicon.gif", "type" => "image/gif", "rel" => "icon", "tag" => "link"},
{"file" => $css_dir."css.css", "type" => "text/css", "rel" => "stylesheet", "tag" => "link"},
{"file" => $js_dir."bluecore.js", "type" => "text/javascript", "rel" => "", "tag" => "script"},
{"file" => $js_dir."base.js", "type" => "text/javascript", "rel" => "", "tag" => "script"}
);
# Make some tools
sub clean_input {
my $input = shift;
@ -59,6 +69,7 @@ sub html_tag {
my $end = " />";
if (@attrib_array) {
foreach(@attrib_array) {
unless (defined($_)) { next; }
$string .= ' '.$_->{attribute}.'="'.$_->{value}.'"';
}
}
@ -104,35 +115,16 @@ sub header {
{attribute=>'content', value=>'text/html; charset=utf-8'});
# Make title dynamic
$header .= html_tag('title',$site_name);
if (-e $img_dir.'favicon.gif') {
$header .= html_tag(
'link',
undef,
{attribute=>'rel', value=>'icon'},
{attribute=>'type', value=>'image/gif'},
{attribute=>'href', value=>$img_dir.'favicon.gif'});
}
if (-e $css_dir.'css.css') {
$header .= html_tag(
'link',
undef,
{attribute=>'rel', value=>"stylesheet"},
{attribute=>'type',value=>"text/css"},
{attribute=>'href',value=>$css_dir.'css.css'});
}
if (-e $js_dir.'bluecore.js') {
$header .= html_tag(
'script',
" ",
{attribute=>'type', value=>"text/javascript"},
{attribute=>'src',value=>$js_dir.'bluecore.js'});
}
if (-e $js_dir.'base.js') {
$header .= html_tag(
'script',
" ",
{attribute=>'type', value=>"text/javascript"},
{attribute=>'src', value=>$js_dir.'base.js'});
for (@header_includes) {
if (-e $system_base.$_->{"file"}) {
my $rel = $_->{"rel"} ne "" ? 1 : 0;
$header .= html_tag(
$_->{"tag"},
$_->{"tag"} eq "script" ? " " : undef,
$rel ? {attribute=>'rel', value=>$_{"rel"}} : undef,
{attribute=>'type', value=>$_->{"type"}},
{attribute=>$rel?'href':'src', value=>$_->{"file"}});
}
}
$header .= html_tag(
'meta',