#!/usr/local/bin/perl

#
# index.html generator
# nostromo, Mon Mar  7 19:57:11 2005
#
# index.html mobile generator
# nostromo, Fri 24 Apr 22:09:29 2015
#
# $Id: gen_index 18 2025-04-07 11:39:46Z root $
#

use constant PI => 4 * atan2(1, 1);
use POSIX qw(ceil floor);
use Getopt::Std;
use LWP::Simple;
use Digest::MD5 qw(md5_hex);

my $length;
my $tot_length;
my $back    = "/";
my $back_r  = "../../";
my $header  = "  |                      ";
my $scheme  = "https";
my $cgi_url = "$scheme://nostromo.joeh.org/cgi-bin";
my $c55_url = "$scheme://nostromo.joeh.org/cgi-c55";
my $file_p  = "/var/www/nostromo.joeh.org/htdocs";
my $index_h = "index.html";
my $index_s = "index.shtml";
my $index_m = "index_m.shtml";
my @empty_d = ( "content",
#               "content/holidays",
                "content/images",
                "content/making_of",
                "content/parties" );
my %offsets = ( category      => '9',    # 22 / 3
                alphabetical  => '23',   # 23 / 1
                chronological => '15',   # 21 / 4
                line_06       => "=*",   # ...
                signature     => '21',); # 23 / 1
my @new_gen;

open(IN_FH,  "< $file_p/../index.in") or die "$!";

while (<IN_FH>)
{
    s/\$cgi_url/$cgi_url/g;
    s/\$c55_url/$c55_url/g;
    next if (/^#/);
    my ($ti_temp, $file_temp, $cat_temp, $y_temp, $des_temp, $url_temp) = split(/;/, $_);
    if ($cat_temp =~ /,/) {
        foreach my $i (split(/,/, $cat_temp))
        {
            push(@in_all, "$ti_temp; $file_temp; $i; $y_temp; $des_temp; $url_temp");
            if ($cat_temp =~ /,holidays$/) {
                my $filepath_temp = $file_temp . "/";
                $filepath_temp =~ s/^\s+|\s+$//g;
                push(@holidays_all, "/usr/local/www/nostromo.joeh.org/htdocs/content/$filepath_temp");
            }
 
        }
    } else {
        push(@in_all, $_);
        my $filepath_temp = $file_temp . "/";
        my $url = $url_temp;
           $url =~ s/^\s+|\s+$//g;
           $filepath_temp =~ s/^\s+|\s+$//g;
        if ($url =~ /http:\/\//i) {
            next;
        }
        if ($url =~ /,/) {
            ($url, undef) = split(/,/, $url);
            
        } 
        if ($url =~ /::/) {
            ($url, undef) = split(/::/, $url);
        }
        push(@files_all, "/usr/local/www/nostromo.joeh.org/htdocs/content/$filepath_temp") if ($filepath_temp && $url ne /\.\.html/);
    }
}
close IN_FH;

my $latest_site;
my @sorted_files = sort { -M $a <=> -M $b } @files_all;
($latest_site = $sorted_files[0]) =~ s/^(.*\/htdocs\/)(.*)$/$2/;
chomp($latest_site);

my $latest_holidays;
my @sorted_holidays = sort { -M $a <=> -M $b } @holidays_all;
($latest_holidays = $sorted_holidays[0]) =~ s/^(.*\/htdocs\/)(.*)$/$2/;
chomp($latest_holidays);

my $i        = 0;
my $counter  = 0;
@in_all      = map { $_ =~ s/;\ */; /g; $_ } @in_all;

my @out_all  = grep { ! $seen{$_} ++ }
    (sort { my ($aa, $bb);
        $a =~ /^(.*);\ *(.*);\ *(.*);\ *(\d{4});\ *(.*);\ *(.*)$/ and
        $aa = $4;
        $b =~ /^(.*);\ *(.*);\ *(.*);\ *(\d{4});\ *(.*);\ *(.*)$/ and
        $bb = $4; push (@in_year, $aa);
     return $aa <=> $bb } @in_all);

   @out_all  = grep { ! $seen{$_} ++ }
    (sort { my ($aa, $bb);
        $a =~ /^(.*);\ *(.*);\ *(.*);\ *(\d{4});\ *(.*);\ *(.*)$/ and
        $aa = $3;
        $b =~ /^(.*);\ *(.*);\ *(.*);\ *(\d{4});\ *(.*);\ *(.*)$/ and
        $bb = $3;
        push (@in_category, $bb);
     return $aa <=> $bb;
     } @in_all);

my %seen     = ();
@in_year     = grep { ! $seen{$_} ++ } sort (@in_year);
@in_category = grep { ! $seen{$_} ++ } sort (@in_category);
@in_all      = sort { $a cmp $b } @in_all;

$| = 1;
my @in_all_d;
$counter_d = 0;

while($counter_d < $#in_all)
{
    @in_all_d[$counter_d]     = (@in_all[$counter_d]);
    @in_all_d[$counter_d + 1] = (@in_all[$#in_all - $counter_d]);
    $counter_d += 2;
}

my %hash_y   = map { $_ => $i++ } @in_year;
$i           = 0;
my %hash_c   = map { $_ => $i++ } @in_category;
$i           = 0;

# -- main ----------------------------------------------------------------------
my %opts = ();
getopts('dmsh', \%opts);

if (keys %opts) {
    foreach my $option ( keys %opts ) {
        if ($option eq "h") {
            print_help();
        } elsif ($option eq "d") {
            create_desktop();
        } elsif ($option eq "m") {
            create_mobile();
        } elsif ($option eq "s") {
            create_sitemap();
        }
    }
} else {
    create_desktop();
    create_mobile();
    create_sitemap();

    if (@new_gen) {
        print STDOUT "new items generated:\n";
        foreach my $new_item (@new_gen) {
            print STDOUT "$new_item";
        }
    }
}

# -- subs ----------------------------------------------------------------------
sub create_desktop {
    print STDOUT "creating desktop: ";
    open(OUT_FH, "> $file_p/$index_h.gen_index.tmp") or die "$!";
    select OUT_FH;

    &summarize_misc(                                 );
    &summarize_alphabetical(  \@in_all               );
    &summarize_category(      \@in_category, \@in_all);
    &summarize_chronological( \@in_year,     \@in_all);
    &print_all;
 
    close OUT_FH;
    rename("$file_p/$index_h.gen_index.tmp", "$file_p/$index_s");
    chown 80, 80, "$file_p/$index_s";
 
    &gen_html(                \@in_all               );
    &gen_yindex(              \@in_all, \@in_year    );
    &gen_cindex(              \@in_all, \@in_category);
    &gen_ymain(               \@in_all, \@in_year    );
    &gen_cmain(               \@in_all, \@in_category);
    &gen_amain(               \@in_all               );

    &fill_emply_dirs();
    print STDOUT "done\n";
}

sub create_mobile {
    print STDOUT "creating mobile: ";

    open(OUT_FH, "> $file_p/$index_h.gen_index_m.tmp") or die "$!";
    select OUT_FH;

    &gen_mobile( \@in_all, \@in_year, \@in_category );

    close OUT_FH;
    rename("$file_p/$index_h.gen_index_m.tmp", "$file_p/$index_m"); 
    chown 80, 80, "$file_p/$index_m";
    print STDOUT "done\n";
} 

sub create_sitemap {
    # sitemap...
    print STDOUT "creating sitemap.xml";
    open(OUT_FH, "> $file_p/sitemap.xml") or die "$!";
    select OUT_FH;

    &gen_sitemap( \@in_all );

    close OUT_FH;

    # image sitemap...
    print STDOUT ", image_sitemap: ";
    open(OUT_FH, "> $file_p/sitemap_images.xml") or die "$!";
    select OUT_FH;

    &gen_imagesitemap();

    close OUT_FH;
    chown 80, 80, "$file_p/sitemap_images.xml";
    print STDOUT "done\n";
}

sub fill_emply_dirs {
    foreach my $i (@empty_d) {
        open(FILLER_OUT, "> /var/www/nostromo.joeh.org/htdocs/$i/index.html_xxx") or die "$!";
        select FILLER_OUT;

        print <<EO_FILLER;
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
    <title>
      please proceed into android hell...
    </title>
    <meta http-equiv="refresh" content="0; URL=/">
    <meta name="author"       content="nostromo eiljeen">
    <link rel="stylesheet"    type="text/css"     href="$back_r/.css">
    <link rel="icon"          type="image/x-icon" href="/favicon.ico">
    </head>
    <body bgcolor="#040404"   text="#208888"
      link="#20FFFF"      vlink="#20FFFF" alink="#20FFFF">
    </body>
    </html>
EO_FILLER

        close FILLER_OUT;

        compare_md5("/var/www/nostromo.joeh.org/htdocs/$i/index.html",
                    "/var/www/nostromo.joeh.org/htdocs/$i/index.html_xxx");

    }
}

sub summarize_misc {
    push(@misc_array, 
    "  |\n",
    "  +--=[ <a href=\"/\">miscellaneous</a> ]=--+\n",
    "  |                       |\n",
    "  |                       `-++++\n",
    "  |                         ||||\n",
    "  |                         |||`-----------=[<a href=\"/index_m.shtml\">vertical layout</a>]=--------------.\n",
    "  |                         |||                                             |\n",
    "  |                         ||`-----------=[<a href=\"/blog/index.latest\" >latest bLog entry</a>]=------------.|\n" ,
    "  |                         |`------------=[<a href=\"$latest_site\">latest site entry<\/a>]=-----------.||\n" ,
    "  |                         `-----------=[<a href=\"$latest_holidays\">latest holidays entry<\/a>]=--------.|||\n" ,
    "  |                                                                      ||||\n" ,
    "  |                         *=~------------------------------------------++++\n" ,
    "  |\n"      ,
    "  |\n"      ,);
}

sub summarize_alphabetical {
    my ($in_c_ref) = @_;
    my @in;
    # my @in       = @{$in_c_ref};

    foreach $i (@{$in_c_ref})
    {
        next if ($i =~ /olidays;\ /);
        push (@in, $i);
    }

    my $i = $j = 0;
    $spacer = "  |                       ";

    $line_01 = $line_02 = $line_03 = $line_04 = $line_05 = $spacer;
    $line_00 = "  |                      `--";
    $offset_length = length($line_00);

    while($i < @in)
    {
        my $item_01 = $in[$i+0];
        my $item_02 = $in[$i+1];
        my $item_03 = $in[$i+2];

        my ($index_01, $path_01, undef, undef, undef, undef) =
            split(/;\ */, $item_01);
        my ($index_02, $path_02, undef, undef, undef, undef) =
            split(/;\ */, $item_02);
        my ($index_03, $path_03, undef, undef, undef, undef) =
            split(/;\ */, $item_03);

#       if (($path_01 =~ /holiday/) ||
#          ($path_02 =~ /holiday/) ||
#          ($path_03 =~ /holiday/));

        $path_01 = "content/$path_01/";
        $path_02 = "content/$path_02/";
        $path_03 = "content/$path_03/";

        $sub_01 = (substr($index_01, 0, 1));
        $sub_03 = (substr($index_02, 0, 1)) if $index_02;
        $sub_03 = (substr($index_03, 0, 1)) if $index_03;

        $indicator = "-=[" . $sub_01;

        if(($sub_01 ne $sub_03) && ($index_02 || $index_03))
        {
            $indicator .= "-" . $sub_03;
        }
        $indicator .= "]=-";

        if($j % 2)
        {
            $line_00 .= "+"  if $index_02;
            $line_00 .= "+"  if $index_03;
            $line_00 .= "+"; $line_00 .= $indicator .
                        "-"x(25 - length($indicator))
                             if ($i+3 < @in);

            $line_01 .= "|"  if $index_02;
            $line_01 .= "|"  if $index_03;
            $line_01 .= "|" . " "x23;

            $line_02 .= "|"  if $index_02;
            $line_02 .= "|"  if $index_03;
            $line_02 .= "`- <a href=\"$path_01\">$index_01</a> " .
                        "-"x(15 - length($index_01)) . "---."
                             if $index_01;
            $line_02 .= " ";

            $line_03 .= " "x22 . "|" unless $index_02;
            $line_03 .= "|"  if $index_03;
            $line_03 .= "`-- <a href=\"$path_02\">$index_02</a> " .
                        "-"x(15 - length($index_02)) . "---."
                             if $index_02;
            $line_03 .= " ";

            $line_04 .= " "x22 . "|" unless ($index_02 && $index_03);
            $line_04 .= "|"  if ($index_01 && $index_02 && !$index_03);
            $line_04 .= "`--- <a href=\"$path_03\">$index_03</a> " .
                        "-"x(15 - length($index_03)) . "---."
                             if $index_03;
            $line_04 .= " ";

            $line_05 .= " "x22 . "|" unless ($index_02 && $index_03);
            $line_05 .= "|"  if ($index_01 && $index_02 && !$index_03);
            $line_05 .= "     " . " "x(length($index_03)) . " " .
                        " "x(15 - length($index_03)) . "   |"
                             if $index_03;
            $line_05 .= " ";

            $line_06 .= "~----" . "-"x(length($index_03)) . "-" .
                        "-"x(15 - length($index_03)) . "--~+"
                             if $index_03;
            $line_06 .= "=" if $index_03;
        }
        else
        {
            $line_00 .= "-"x(20 - length($indicator)) . $indicator . "+" 
                             if $index_01;
            $line_00 .= "+"  if $index_02;
            $line_00 .= "+"  if $index_03;
            $line_00 .= "--" if($i+3 < @in);

            $line_01 .= " "x22 . "|";
            $line_01 .= "|"  if $index_02; $line_01 .= "|"
                             if $index_03;
            $line_01 .= "  ";

            $line_02 .= ".---" . "-"x(17 - length($index_01) - 2) .
                        " <a href=\"$path_01\">$index_01</a> -'"
                             if $index_01;
            $line_02 .= "|"  if $index_02;
            $line_02 .= "|"  if $index_03;
            $line_02 .= "  ";

            $line_03 .= "|"  if($index_01 && ($i >= (@in-1)));
            $line_03 .= ".---" . "-"x(17 - length($index_02) - 2) .
                        " <a href=\"$path_02\">$index_02</a> --'"
                             if $index_02;
            $line_03 .= "|"  if $index_03;
            $line_03 .= "  ";

            $line_04 .= "|"  if($index_01 && ($i >= (@in-2)));
            $line_04 .= "|"  if($index_02 && ($i >= (@in-2)));
            $line_04 .= ".---" . "-"x(17 - length($index_03) - 2) .
                        " <a href=\"$path_03\">$index_03</a> ---'"
                             if $index_03;
            $line_04 .= "  ";

            $line_05 .= "|"  if($index_01 && ($i >= (@in-2)));
            $line_05 .= "|"  if($index_02 && ($i >= (@in-2)));
            $line_05 .= "|   " . " "x(17 - length($index_03) - 2) .
                        " " . " "x(length($index_03)) . "     "
                             if $index_03;
            $line_05 .= "  ";

            $line_06 .= "+~--" . "-"x(17 - length($index_03) - 2) .
                        "-" . "-"x(length($index_03)) . "----~"
                             if $index_03;
            $line_06 .= "==" if $index_03;
        }

        $index_01 = $index_02 = $index_03 = "";
        
        $i += 3;
        $j += 1;
    }

    ($length  = $line_04)  =~ s/(<[^>]+>)//g;
    $length   = (length($length) - $offset_length);

    $line_06  = (substr($line_06, 1, ($length - 1)));
    $line_06  = "  |                       `" . $line_06;
    $line_06 .= $offsets{line_06};

    push(@alpha_array, 
    "  |\n",
    "  +--=[ <a href=\"alphabetical/\">alphabetical</a> ]=--+\n",
    "  |                      |\n",
    "$line_00" . "-"x01 . "*\n",
    "$line_01\n" ,
    "$line_01\n" ,
    "$line_02\n" ,
    "$line_03\n" ,
    "$line_04\n" ,
    "$line_05\n" ,
    "$line_05\n" ,
    "$line_06\n" ,
    "  |\n"      ,
    "  |\n"      ,);
}

sub summarize_category {
    my ($cat_ref, $in_c_ref) = @_;
    my @in_c     = @{$in_c_ref};
    my @cat      = @{$cat_ref};
    my $i        = 0;
    my %seen     = ();
    my @u_cat    = grep { ! $seen{$_} ++ } @cat;
    my $spacer_c = "  |                    ";
    my @array_c;
    my $x_c;
    my $y_c;
    my $target_ic;
    my $target_xc;
    my $target_icc = 3;
    $line_00c    = $line_00;
    $line_01c    = $line_01;
    $line_00c    = $spacer_c;
    $line_cat_c  = "  |                      `" .  "-"x$offsets{category};

    push(@categ_array,
    "  |\n",
    "  +----=[ <a href=\"category/\">category</a> ]=----+\n",
    "  |                      |\n");

    ($ca_dummy   = $categ_array[1]) =~ s/(<[^>]+>)//g;

    $cl_length_c      = (((length(substr($line_01c, (length($line_cat_c)))))) -
                          (length($ca_dummy)));
    $length_c         = $cl_length_c + length($line_cat_c);


    while ($i < ($#cat + 1))
    {
        $i_cat        = $cat[$i];

        $c_length     = length("-=[" . $i_cat . "]=-");
        $line_cat_c  .= ("-"x(floor(($length / ($#cat + 1)) / 2) - 
                             (floor($c_length / 2))) .
                        "-=[<a href=\"category/$i_cat/\">$i_cat</a>]=-" .
                         "-"x(ceil(($length / ($#cat + 1)) / 2) -
                             ((ceil($c_length / 2)) - 0)));
        $i++;
    }

    push(@categ_array,  substr($line_cat_c, 0, (length($line_cat_c) - 4)) . "*\n", # - 0))
    "  |\n");

    $target_ic  = 0;
    $line_01c   = substr($line_01c, (length($spacer_c) + 2));

}

sub summarize_chronological {
    $target_i = 0;
    $line_05  = substr($line_05, (length($spacer)-1));

    my ($date_ref, $in_ref) = @_;
    my @in     = @{$in_ref};
    my @date   = @{$date_ref};
    my $i      = 0;
    my $sig    = "nostromo.joeh.org";
    $spacer    = "  |                      ";
    $line_date = "  |                      `-" . "-"x$offsets{chronological};

    while ($i < ($#date + 1))
    {
        $i_date     = $date[$#date - $i];      # ascending
        # $i_date   = $date[$i];               # descending

        $i_length   = length("-=[" . $i_date . "]=-");
        $indicator  = "-=[<a href=\"chronological/$i_date/\">$i_date</a>]=-";
        $line_date .= ("-"x((ceil($length/($#date + 1)) - ($i_length))/2) . $indicator .
                       "-"x((floor($length/($#date + 1)) - ($i_length))/2 - 1));
        $i++;
    }

    $tot_length = length (" "x111 . ("-"x(length($line_05) - 89 - (length($sig)))) .  "-"x$offsets{signature} .  "$sig-" . "*  ");

    push(@chrono_array,
    "  +-=[ <a href=\"chronological/\">chronological</a> ]=--+\n",
    "  |                      |\n",
    "$line_date" . "-"x(11) . "*\n",
    "  |\n",
    "  |\n",
    "  |\n",
    "  |\n",
    "  |\n",
    "  |\n",
    "  +-=[ (c) nostromo<a class=\"no_style\" href=\"https://gizmodo.com/the-humble-origins-of-the-html-blink-tag-5903827\" target=\"_blank\"><span id=\"sig\">_</span></a> ]=--+\n",
    "  |                      |\n",
    "  |                      `----------=[<a href=\"/?a=n\">normal</a>]=----------=[<a href=\"/?a=i\">inverted</a>]=----------=[<a href=\"/content/colour_picker/\">colouring</a>]=----------=[<a href=\"/?a=r\">rotated</a>]=----------=[<a href=\"/?a=f\">flipped</a>]=-" .
                               ("-"x(length($line_05) - 132 - (length($sig)))) .
                               "-"x$offsets{signature} .
                               "<a href=\"//$sig\">$sig</a>-" . "*  \n",
    "  |\n",
    "  |\n",
    "  |\n",
    "  |\n",
    "  |\n",
    "  `-=[ random images ]=--+<!-- $tot_length -->\n",
    "                         |\n",
    "                         `<!--#if expr=\"\$QUERY_STRING = /a=i/\" --><!--#include virtual=\"/cgi-bin/random_image.cgi?a=i\" -->" .
                              "<!--#else --><!--#include virtual=\"/cgi-bin/random_image.cgi\" --><!--#endif --> --*\n");
}

sub print_all {
    print <<EO_HEADER;
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
  <title>
      nostromo
  </title>
  <meta name="author"       content="nostromo eiljeen">
  <link rel="stylesheet"    type="text/css"     href="/.css">
  <link rel="icon"          type="image/x-icon" href="/favicon.ico">
  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
</head>
<body bgcolor="#040404"   text="#208888"
      link="#20FFFF"      vlink="#20FFFF" alink="#20FFFF">
<pre>

*=+-- choose:
  |
  |
EO_HEADER

    foreach $m_item (@misc_array)
    {
        print $m_item;
    }

    foreach $c_item (@categ_array)
    {
        print $c_item;
    }

    foreach $a_item (@alpha_array)
    {
        print $a_item;
    }

    foreach $d_item (@chrono_array)
    {
        print $d_item;
    }

    print <<EO_FOOTER;
</pre>
<!-- IPv6-counter :: begin -->
<!--
<img src="http://6bone.informatik.uni-leipzig.de/ipv6/stats/log.php3?URL=nostromo.joeh.org&amp;ImageId=6" 
     border="0" width="0" height="0" alt="IPv6 supported" />
  -->
<!-- IPv6-counter :: end   -->
</body>
</html>
EO_FOOTER
}

sub gen_html {
    my ($in_c_ref) = @_;
    my @in_c       = @{$in_c_ref};
    my $index_xxx;

    foreach $in (@in_all)
    {
        my($title, $path, $cat, $year, $info, $links) = split(/;\ */, $in);
        next if ($title eq "bLog");
        mkdir "content/$path" unless
            (-d "content/$path"); 

        # $index_xxx  = "content/$path/.__index.html_xxx";
        $index_xxx  = "../tmp/$title-$cat-index.html";
        open(OUT, "> $index_xxx") || die "oh nos - $path!\n$!\n";

        select OUT;

        print <<EO_HTML1;
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
  <title>
      $title
  </title>
  <meta name="author"       content="nostromo eiljeen">
  <link rel="stylesheet"    type="text/css"     href="/.css">
  <link rel="icon"          type="image/x-icon" href="/favicon.ico">
  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
</head>
<body bgcolor="#040404"   text="#208888"
      link="#20FFFF"      vlink="#20FFFF" alink="#20FFFF">
<pre>

*=+-- $title:
  |
  |
  |
  +----=[ summary ]=-----+ 
  |                      |
EO_HTML1

        my $line_01 = "$header+" . 
                      "-"x(20 - (floor((length($cat) + length($year) + 1)/2))) .
                      "=[<a href=\"/category/$cat/\">$cat</a>/"        .
                      "<a href=\"/chronological/$year/\">$year</a>]="  .
                      "-"x(20 - ( ceil((length($cat) + length($year) + 1)/2))) .
                      "*\n";

        my $line_02 = "$header|\n";
        my $line_03 = "$header`--+" . "-"x39 . "+-*\n";

           $line_05 = "$header   `" . "-"x39 . "'\n  |\n  |\n";
        my $line_06 = "  +-----=[ links ]=------+\n" .
                      " "x25 . "|\n";

        foreach $i (split(/, /, $links))
        {
            my ($url, $text) = split(/::/, $i);
            next unless($url);
            chomp($url);
            $text     = $title unless $text;
            chomp($text);
            $line_07 .= " "x25 . "+" . "-"x(20 - (floor((length($text)/2))))  .
                        "=[<a href=\"" .
                            (($url =~ s/^H/h/) ? "$url\" target=\"_new\">"    :
                                                 "$url\">")                   .
                        "$text</a>]=" . "-"x(20 - (ceil((length($text)/2)))) .
                        "*\n" . " "x25 . "|\n";
        }
        my $line_08 = " "x25 . "`------------------=[<a href=\"$back\">" .
                      "back</a>]=------------------*\n";

        print "$line_01";
        print "$line_02";
        print "$line_03";
        print "  |" . " "x25 . "|" . " "x39 . "|\n";

        if($info =~ /§/)
        {
            foreach $info_i (split(/§/, $info))
            {
                formline <<'END', $info_i;
~~|                         | ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
END
            }
        }
        else
        {
            formline <<'END', $info;
~~|                         | ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
END
        }
        print "$^A";
        print "  |" . " "x25 . "|" . " "x39 . "|\n";

        print "$line_05";
        print "$line_06";
        print "$line_07";
        undef  $line_07;
        print "$line_08";
        undef  $^A;
        print <<EO_FOOTER;
</pre>
</body>
</html>
EO_FOOTER

        close OUT;

        if ($cat !~ /olidays/) {
            if (compare_md5("content/$path/$index_h",
                            "$index_xxx") != 0) {
                push(@new_gen, "  * content/$path/$index_h - $cat\n");
            }
        }

        undef $title;
        undef $path;
        undef $cat;
        undef $year;
        undef $info;
        undef $links;
    }
}

sub gen_yindex {
    my ($in_ref, $year_ref) = @_;
    my @in     = @{$in_ref};
    my @date   = @{$year_ref};
    my $index_xxx  = "index.html_xxx";

    foreach $d (@date)
    {
        mkdir "$file_p/chronological/$d" unless
            ( -d "$file_p/chronological/$d" );

        open(OUT_Y, "> $file_p/chronological/$d/$index_xxx");
        select OUT_Y;

        print <<EO_HEADER;
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
  <title>
      $d
  </title>
  <meta name="author"       content="nostromo eiljeen">
  <link rel="stylesheet"    type="text/css"     href="$back_r/.css">
  <link rel="icon"          type="image/x-icon" href="/favicon.ico">
</head>
<body bgcolor="#040404"   text="#208888"
      link="#20FFFF"      vlink="#20FFFF" alink="#20FFFF">
<pre>

*=+-- $d:
  |
  |
  |
  +----=[ elements ]=----+
  |                      |
  |                      `--+---------------------------------------+-*
  |                         |                                       |
EO_HEADER

            @tmp = (grep(/$d/, @in));
            my $dbl_info, $dbl_path;

            @tmp = grep { ! $seen{$_} ++ } sort (@tmp);
            @tmp = sort { $a cmp $b } @tmp;

            foreach $t (@tmp)
            {
                next unless ($t =~ /$d/);
                my ($title, $path, $cat, $year, $info, $links) = split(/;\ */, $t);
                if(($dbl_info eq $info) && ($dbl_path eq $path)) {
                    $dbl_info = "";
                    $dbl_path = "";
                    next;
                }
                $dbl_info = $info;
                $dbl_path = $path;
                print "  |" . " "x25 . "| <a href=\"/content/$path/\">$title" .
                      "</a>" .
                      " "x(37 - (length($cat) + (length($title)))) . 
                      "<a href=\"/category/$cat/\">$cat</a> |\n" if ($year eq $d);
            }
        print <<EO_FOOTER;
  |                         |                                       |
  |                         `---------------------------------------'
  |
  +-----=[ links ]=------+
                         |
                         `------------------=[<a href="$back">back</a>]=------------------*
EO_FOOTER

        close OUT_Y;

        compare_md5("$file_p/chronological/$d/$index_h",
                    "$file_p/chronological/$d/$index_xxx");

    }
}

sub gen_cindex {
    my ($in_ref, $cat_ref) = @_;
    my @in     = @{$in_ref};
    my @cat    = @{$cat_ref};
    my $index_xxx  = "index.html_xxx";

    foreach $c (@cat)
    {
        mkdir "$file_p/category/$c" unless
            ( -d "$file_p/category/$c" );

        open(OUT_C, "> $file_p/category/$c/$index_xxx");
        select OUT_C;

        print <<EO_HEADER;
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
  <title>
      $c
  </title>
  <meta name="author"       content="nostromo eiljeen">
  <link rel="stylesheet"    type="text/css"     href="$back_r/.css">
  <link rel="icon"          type="image/x-icon" href="/favicon.ico">
</head>
<body bgcolor="#040404"   text="#208888"
      link="#20FFFF"      vlink="#20FFFF" alink="#20FFFF">
<pre>

*=+-- $c:
  |
  |
  |
  +----=[ elements ]=----+
  |                      |
  |                      `--+---------------------------------------+-*
  |                         |                                       |
EO_HEADER

            @tmp = (grep(/$c/, @in));

            my @new;

            if($c eq "holidays")
            {
                # @tmp = reverse sort { (split(/;\ /, $a))[3] cmp (split(/;\ /, $b))[3] } @tmp;
                @tmp = reverse sort { (split(/_/, $a))[1] cmp (split(/_/, $b))[1] } @tmp;
                # foreach $item (@new) { print STDOUT ">>> $item\n"; }
            }
    
            foreach $t (@tmp)
            {
                next unless ($t =~ /$c/);
                my ($title, $path, $cat, $year, $info, $links) = split(/;\ */, $t);
                print "  |" . " "x25 . "| <a href=\"/content/$path/\">$title" .
                      "</a>" .
                      " "x(37 - (length($year) + (length($title)))) . 
                      "<a href=\"/chronological/$year/\">$year</a> |\n" if ($cat eq $c);
            }
        print <<EO_FOOTER;
  |                         |                                       |
  |                         `---------------------------------------'
  |
  +-----=[ links ]=------+
                         |
                         `------------------=[<a href="$back">back</a>]=------------------*
EO_FOOTER

        close OUT_C;

        compare_md5("$file_p/category/$c/$index_h",
                    "$file_p/category/$c/$index_xxx");

    }
}

sub gen_cmain {
    my ($in_ref, $cat_ref) = @_;
    my @in     = @{$in_ref};
    my @cat    = @{$cat_ref};
    my $index_xxx  = "index.html_xxx";

    open(OUT_C, "> $file_p/category/$index_xxx");
    select OUT_C;

    print <<EO_HEADER;
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
  <title>
      category
  </title>
  <meta name="author"       content="nostromo eiljeen">
  <link rel="stylesheet"    type="text/css"     href="$back_r/.css">
  <link rel="icon"          type="image/x-icon" href="/favicon.ico">
</head>
<body bgcolor="#040404"   text="#208888"
      link="#20FFFF"      vlink="#20FFFF" alink="#20FFFF">
<pre>

*=+-- category:
  |
  |
  |
  +----=[ elements ]=----+
  |                      |
  |                      `--+---------------------------------------+-*
  |                         |                                       |
EO_HEADER

    foreach $c (@cat)
    {
        print "  |" . " "x25 . "| <a href=\"/category/$c/\">$c" .
              "</a>" .
              " "x(37 - (length($c))) . " |\n";

        @tmp = (grep(/$c/, @in));

        foreach $t (@tmp)
        {
            next unless ($t =~ /$c/);
            my ($title, $path, $cat, $year, $info, $links) = split(/;\ */, $t);
            print "  |" . " "x25 . "| - <a href=\"/content/$path/\">$title" .
                  "</a>" .
                  " "x(35 - (length($year) + (length($title)))) . 
                  "<a href=\"/chronological/$year/\">$year</a> |\n" if ($cat eq $c);
        }
        print "  |" . " "x25 . "|" . " "x38 . " |\n";
    }

    print <<EO_FOOTER;
  |                         |                                       |
  |                         `---------------------------------------'
  |
  +-----=[ links ]=------+
                         |
                         `------------------=[<a href="$back">back</a>]=------------------*
EO_FOOTER

    close OUT_C;

    compare_md5("$file_p/category/$index_h",
                "$file_p/category/$index_xxx");

}

sub gen_ymain {
    my ($in_ref, $year_ref) = @_;
    my @in     = @{$in_ref};
    my @date   = @{$year_ref};
    my $index_xxx  = "index.html_xxx";

    open(OUT_Y, "> $file_p/chronological/$index_xxx");
    select OUT_Y;

    print <<EO_HEADER;
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
  <title>
      chronological
  </title>
  <meta name="author"       content="nostromo eiljeen">
  <link rel="stylesheet"    type="text/css"     href="$back_r/.css">
  <link rel="icon"          type="image/x-icon" href="/favicon.ico">
</head>
<body bgcolor="#040404"   text="#208888"
      link="#20FFFF"      vlink="#20FFFF" alink="#20FFFF">
<pre>

*=+-- chronological:
  |
  |
  |
  +----=[ elements ]=----+
  |                      |
  |                      `--+---------------------------------------+-*
  |                         |                                       |
EO_HEADER

    # foreach $y (@date)        # ascending
    foreach $y (reverse @date)  # descending
    {
        print "  |" . " "x25 . "| <a href=\"/chronological/$y/\">$y" .
              "</a>" .
              " "x(37 - (length($y))) . " |\n";

        @tmp = (grep(/$y/, @in));
        my $dbl_info, $dbl_path;

        foreach $t (@tmp)
        {
            next unless ($t =~ /$y/);
            my ($title, $path, $cat, $year, $info, $links) = split(/;\ */, $t);
            if(($dbl_info eq $info) && ($dbl_path eq $path)) {
                $dbl_info = "";
                $dbl_path = "";
                next;
            }
            $dbl_info = $info;
            $dbl_path = $path;
            print "  |" . " "x25 . "| - <a href=\"/content/$path/\">$title" .
                  "</a>" .
                  " "x(35 - (length($cat) + (length($title)))) . 
                  "<a href=\"/category/$cat/\">$cat</a> |\n";
        }
        print "  |" . " "x25 . "|" . " "x38 . " |\n";
    }

    print <<EO_FOOTER;
  |                         |                                       |
  |                         `---------------------------------------'
  |
  +-----=[ links ]=------+
                         |
                         `------------------=[<a href="$back">back</a>]=------------------*
EO_FOOTER

    close OUT_Y;

    compare_md5("$file_p/chronological/$index_h",
                "$file_p/chronological/$index_xxx");

}

sub gen_amain {
    my ($in_ref) = @_;
    my @in       = @{$in_ref};
    my $index_xxx  = "index.html_xxx";

    open(OUT_A, "> $file_p/alphabetical/$index_xxx");
    select OUT_A;

    print <<EO_HEADER;
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
  <title>
      alphabetical
  </title>
  <meta name="author"       content="nostromo eiljeen">
  <link rel="stylesheet"    type="text/css"     href="$back_r/.css">
  <link rel="icon"          type="image/x-icon" href="/favicon.ico">
</head>
<body bgcolor="#040404"   text="#208888"
      link="#20FFFF"      vlink="#20FFFF" alink="#20FFFF">
<pre>

*=+-- alphabetical:
  |
  |
  |
  +----=[ elements ]=----+
  |                      |
  |                      `--+---------------------------------------+-*
  |                         |                                       |
EO_HEADER

    my $dbl_info, $dbl_path;

    @tmp = grep { ! $seen{$_} ++ } sort (@in);
    @tmp = sort { $a cmp $b } @in;

    foreach $a (@in)
    {
        my ($title, $path, $cat, $year, $info, $links) = split(/;\ */, $a);
        if(($dbl_info eq $info) && ($dbl_path eq $path)) {
            $dbl_info = "";
            $dbl_path = "";
            next;
        }
        $dbl_info = $info;
        $dbl_path = $path;
        print "  |" . " "x25 . "| - <a href=\"/content/$path/\">$title" .
              "</a>" .
              " "x(32 - (length($year) + length($cat) + length($title))) .
              "<a href=\"/category/$cat/\">$cat</a> / " . 
              "<a href=\"/chronological/$year/\">$year</a> |\n";
    }

    print <<EO_FOOTER;
  |                         |                                       |
  |                         `---------------------------------------'
  |
  +-----=[ links ]=------+
                         |
                         `------------------=[<a href="$back">back</a>]=------------------*
EO_FOOTER

    close OUT_A;

    compare_md5("$file_p/alphabetical/$index_h",
                "$file_p/alphabetical/$index_xxx");

}

sub gen_sitemap {
    my ($in_ref) = @_;

    my @in_all = @{$in_ref};

    open(IN, "< /var/www/nostromo.joeh.org/htdocs/robots.txt") || die "$!";
    while(<IN>) {
        next unless (/^Disallow:/);
        $_ =~ m/Disallow: (.*)$/;
        push(@disallow, $1);
    }
    close IN;
    chown 80, 80, "/var/www/nostromo.joeh.org/htdocs/robots.txt";

    foreach $in (@in_all)
    {
        my($title, $path, $cat, $year, $info, $links) = split(/;\ */, $in);
        if ($title eq "bLog") {
            chomp($links);
            push(@in_sitemap, "\l$links\E")
        }

        foreach $i (split(/, /, $links))
        {
            my ($url, undef) = split(/::/, $i);
            next if((!$url) || ($url =~ /^((h|H)ttp(s)?:\/\/|\/blog)/));
            chomp($url);
            $url =~ s/\.\.html$//;
            $url .= "/" if ($url && ($url !~ m{/$}));
            push(@in_sitemap, "$scheme://nostromo.joeh.org/content/$path/$url")
                unless ( grep /($path|$url)/, @disallow);
        }
    }
    print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    print "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
    print map "  <url>\n    <loc>$_</loc>\n  </url>\n", sort keys %{ {map {$_ => 1} @in_sitemap} };
    print "</urlset>\n";
}

sub gen_imagesitemap {
    open(IN, "< /var/www/nostromo.joeh.org/random_images.in") || die "$!";

    print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    print "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n"   .
          "  xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\">" .
          "\n  <url>\n    <loc>$scheme://nostromo.joeh.org/</loc>\n";

    while(<IN>) {
        next if (/^\d+/);
        $_ =~ m/^\/var\/www\/nostromo.joeh.org\/htdocs\/content\/(.*?)\/.llgal\/thumb_([^\/]*)$/;

        $image = "$scheme://nostromo.joeh.org/content/$1/$2"; chomp($image);
        print "    <image:image>\n      <image:loc>$image</image:loc>\n" .
              "    </image:image>\n";
    }

    close IN;
    print "  </url>\n</urlset>\n";
}

sub gen_mobile {
    my ($in_ref, $year_ref, $category_ref) = @_;

    my @in_all;      # = @{$in_ref};
    my @in_year      = reverse @{$year_ref};
    my @in_category  = @{$category_ref};

    foreach $i (@{$in_ref})
    {
        next if ($i =~ /olidays;\ /);
        push (@in_all, $i);
    }

    my $time       = ($#in_all);
    my $years      = ($#in_year + 1);
    my $cats       = ($#in_category + 1);

    my $two_pi     = (PI * 2);

    my $seg_length = 21;
    my $padding    = 15;
    my $amplitude  = 5;
    my $period     = 100;
    my $period_a   = 30;
    my $cur_line   = "";

    my @cur_lines_y;
    my @cur_lines_c;
    my @cur_lines_a;

    my $counter_a;
    my $counter_y;
    my $counter_c;

    my $counter_lines_a = 0;
    my $counter_lines_y = 0;
    my $counter_lines_c = 0;

    for $i ( 0 .. $time ) {
        $cur_line   = "";
        $cur_length = 0;

        $curr_a  = ( $amplitude * sin(2 * $two_pi *  $i     /
                    ($time * 2 / $period_a) ));
        $next_a = ( $amplitude * sin(2 * $two_pi * ($i + 1) /
                    ($time * 2 / $period_a) ));
        $prev_a = ( $amplitude * sin(2 * $two_pi * ($i - 1) /
                    ($time * 2 / $period_a) ));
        $curr_c = ( $amplitude * sin(2 * $two_pi *  $i      /
                    ($time * 2 / $cats) ));
        $next_c = ( $amplitude * sin(2 * $two_pi * ($i + 1) /
                    ($time * 2 / $cats) ));
        $prev_c = ( $amplitude * sin(2 * $two_pi * ($i - 1) /
                    ($time * 2 / $cats) ));
        $curr_y = ( $amplitude * sin(2 * $two_pi *  $i      /
                    ($time * 2 / $years) ));
        $next_y = ( $amplitude * sin(2 * $two_pi * ($i + 1) /
                    ($time * 2 / $years) ));
        $prev_y = ( $amplitude * sin(2 * $two_pi * ($i - 1) /
                    ($time * 2 / $years) ));

        $length_a = ($padding + ( $amplitude * sin(2 * $two_pi * $i /
                    ($time * 2 / $period_a) )));
        $length_y = ($padding + ( $amplitude * sin(2 * $two_pi * $i /
                    ($time * 2 / $years) )));
        $length_c = ($padding + ( $amplitude * sin(2 * $two_pi * $i /
                    ($time * 2 / $cats) )));

        my $fill_a = "X";
        my $fill_c = "=";
        my $fill_y = "^";
        my $fill_r = ".";

        #   zoo;       zoo;      cat;   year;  desc; zoo_linz_0310::zoo_linz_0310,
        my ($index_01, $path_01, undef, undef, undef, $path_02) =
            split(/;\ */, @in_all[$counter_a]);

        # alphabet...
        if (($path_02 =~ s/(,)/\1/g) > 1) {
            $link_a    = "<a href=\"/content/$path_01/\">";
        } elsif ($path_02 =~ /^Http/) {
            $link_a    = "<a href=\"\l$path_02\E\">";
        } else {
            ($path_02, undef) = split(/:/, $path_02);
            $link_a    = "<a href=\"/content/$path_01/$path_02\">";
        }

        my $length_balancer_a = 0;
        if ( length("$fill_a"x($padding + ($length_a - (length($index_01) + 4))) .
            "[$index_01]==" . "$fill_c"x($seg_length - $length_a) . " ")  > 36 ) {
            $length_balancer_a = 1;
        }
        $cur_line_a .= "$fill_a"x($padding + ($length_a - (length($index_01) + 4))) .
            "[$link_a$index_01</a>]==" . "$fill_c"x($seg_length - $length_a -
            $length_balancer_a) . " ";

        $cur_line_a .= $fill_c if ($counter_lines_a < 1);
        $counter_lines_a++;
        $counter_a++;

        # category...
        $cur_length = length($cur_line_a);
        my $length_balancer_c = 0;

        $length_balancer_string_c = " " if ($counter_lines_c < 1);
        $counter_lines_c++;

        if (( $prev_c < $curr_c ) && ( $curr_c > $next_c )) {
            if (length( "$fill_c"x($padding + ($length_c -
                (length(@in_category[$counter_c]) + 4))) . "[" .
                @in_category[$counter_c] . "]" . "$fill_y"x2 .
                "."x($seg_length - $length_c) . " ") > 36 ) {
                $length_balancer_c = 1;
            }
            $link_c    = "<a href=\"/category/" . @in_category[$counter_c] .
                         "\">";
            $cur_line_c .= "$fill_c"x($padding + ($length_c - 
                (length(@in_category[$counter_c]) + 4))) .
                "[$link_c" . @in_category[$counter_c] . "</a>]" . "$fill_c"x2 .
                "$fill_y"x($seg_length - $length_c - $length_balancer_c) . " ";
            $counter_c++;
        } else {
            if (length("$fill_c"x($padding + $length_c) .
                "$fill_y"x($seg_length - $length_c) . " ") > 36 ) {
                $length_balancer_c = 1;
            }
            $cur_line_c .= "$fill_c"x($padding + $length_c) .
                "$fill_y"x($seg_length - $length_c - $length_balancer_c) .
                $length_balancer_string_c . " ";
        }

        # year...
        $cur_length = length($cur_line_a);
        my $length_balancer_y = 0;

        $length_balancer_string_y = " " if ($counter_lines_y < 1);
        $counter_lines_y++;

        if (( $prev_y < $curr_y ) && ( $curr_y > $next_y )) {
            $link_y    = "<a href=\"/chronological/" . @in_year[$counter_y] .
                         "\">";
            $cur_line_y .= "$fill_y"x($padding + ($length_y - 
                (length(@in_year[$counter_y]) + 4))) . "[$link_y" .
                @in_year[$counter_y] . "</a>]" . "$fill_y"x2 . $fill_r;
            $counter_y++;
        }
        else {
            if (length("$fill_y"x($padding + $length_y) .
                "$fill_r"x($seg_length - $length_y) . " ") > 36 ) {
                $length_balancer_y = 1;
            }
            $cur_line_y .= "$fill_y"x($padding + $length_y) .
                "$fill_r"x($seg_length - $length_y - $length_balancer_y) .
                $length_balancer_string_y . " ";
        }
        
        if ($cur_line_a) {
            push (@cur_lines_a, $cur_line_a);
            $cur_line_a = "";
        }
        if ($cur_line_y) {
            push (@cur_lines_y, $cur_line_y);
            $cur_line_y = "";
        }
        if ($cur_line_c) {
            push (@cur_lines_c, $cur_line_c);
            $cur_line_c = "";
        }
    }
    print <<EO_HEADER;
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <title>
      nostromo&nbsp;
  </title>
  <meta name="author"       content="nostromo eiljeen">
  <link rel="stylesheet"    type="text/css"     href="/.m.css">
  <link rel="icon"          type="image/x-icon" href="/favicon.ico">
  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
</head>
<body bgcolor="#040404"   text="#208888"
      link="#20FFFF"      vlink="#20FFFF" alink="#20FFFF">
<div class="horizontalaccordion">
  <ul>
EO_HEADER

    # http://tympanus.net/codrops/2012/02/21/accordion-with-css3/
    # http://jsfiddle.net/m_raffaele/Fzuz7/
    # http://www.script-tutorials.com/css3-onclick-vertical-metal-menu/

    # http://www.w3avenue.com/2010/04/02/cross-browser-pure-css3-vertical-accordion/

    ## alphabet XX== category ==^^ chronology ^^.. misc ..

    my $header_line_a = "X"x4 . "aXXlXXpXXhXXaXXbXXeXXtXXiXXcXXaXXlX" .
                        "X"x($#cur_lines_a - 18);
    $header_line_a .= "X"x(($time * 3) - length($header_line_a));

    print "  <li>\n"                        .
          "    <h3>$header_line_a</h3>\n" .
          "      <div><pre>";

    $cur_lines_a[0] = substr($cur_lines_a[0], 0, -2) . " ";
    foreach my $line_a (@cur_lines_a) {
        print "$line_a\n";
    }

    my $header_line_c = "="x7 . "c==a==t==e==g==o==r==i==e==s=" .
                        "="x($#cur_lines_c - 18);
    $header_line_c .= "="x(($time * 3) - length($header_line_c));

    print "</pre></div>\n"                    .
          "  </li>\n"                         .
          "  <li>\n"                          .
          "    <h3>$header_line_c</h3>\n"     .
          "      <div><pre>";

    $cur_lines_c[0] = substr($cur_lines_c[0], 0, -2) . " ";
    foreach my $line_c (@cur_lines_c) {
        print "$line_c\n";
    }

    my $header_line_y = "^"x10 . "c^^h^^r^^o^^n^^o^^l^^o^^g^^i^^c^^a^^l^" .
                        "^"x($#cur_lines_y - 16);
    $header_line_y .= "^"x(($time * 3) - length($header_line_y));

    print "</pre></div>\n"                    .
          "  </li>\n"                         .
          "  <li>\n"                          .
          "    <h3>$header_line_y</h3>\n"     .
          "    <div><pre>\n";

    $cur_lines_y[0] = substr($cur_lines_y[0], 0, -2) . " ";
    foreach my $line_y (@cur_lines_y) {
        print "$line_y\n";
    }

    my $header_line_m = "."x13 . "m..i..s..c..e..l..l..a..n.." .
                        "e..o..u..s..." .  "."x($#cur_lines_a - 35);
    $header_line_m .= "."x(($time * 3) - length($header_line_m));

    my $latest_holidays_string = "latest holidays entry";
    my $latest_holidays_line   = "."x(floor($seg_length - (length($latest_holidays_string) / 2))) .
                                 "<a href=\"$latest_holidays\">$latest_holidays_string<\/a>"      .
                                 "."x(ceil($seg_length - (length($latest_holidays_string) / 2)))  ;

    my $latest_site_string      = "latest site entry";
    my $latest_site_line        = "."x(floor($seg_length - (length($latest_site_string) / 2))) .
                                 "<a href=\"$latest_site\">$latest_site_string</a>"            .
                                 "."x(ceil($seg_length - (length($latest_site_string) / 2)))  ;

    my $latest_blog            = "$scheme://nostromo.joeh.org/blog/index.latest";
    my $latest_blog_string     = "latest bLog entry";
    my $latest_blog_line       = "."x(floor($seg_length - (length($latest_blog_string) / 2))) .
                                 "<a href=\"$latest_blog\">$latest_blog_string</a>"           .
                                 "."x(ceil($seg_length - (length($latest_blog_string) / 2)))  ;

    print "</pre></div>\n"                                                .
          "  </li>\n"                                                     .
          "  <li>\n"                                                      .
          "    <h3>$header_line_m</h3>\n"                                 .
          "      <div><pre>\n"                                            .
          "."x11 . "<a href=\"/\">horizontal layout</a>" . "."x11 . "\n"  .
          "."x($seg_length * 2) . "\n"                                    .
          "$latest_blog_line\n"                                           .
          "$latest_site_line\n"                                            .
          "$latest_holidays_line\n"                                       .
          "."x($seg_length * 2) . "\n"                                    .
          "<!--# if expr=\"\$QUERY_STRING = /a=i/\" -->"                  .
          "<!--# include virtual=\"/cgi-bin/random_image_m.cgi?a=i\" -->" .
          "<!--# else -->"                                                .
          "<!--# include virtual=\"/cgi-bin/random_image_m.cgi?a=n\" -->" .
          "<!--# endif -->\n" ;

    print "</pre></div>\n"                    .
          "    </li>\n"                       .
          "  </ul>\n"                         .
          "</div>\n"                          ;

    print <<EO_FOOTER;
<!-- IPv6-counter :: begin -->
<!--
<img src="http://6bone.informatik.uni-leipzig.de/ipv6/stats/log.php3?URL=nostromo.joeh.org&amp;ImageId=6" 
     border="0" width="0" height="0" alt="IPv6 supported" />
  -->
<!-- IPv6-counter :: end   -->
</body>
</html>
EO_FOOTER
}

sub print_help {
  print <<EO_HELP;
NAME
    gen_index - an index generator

SYNOPSIS
    gen_index [OPTION] ...

DESCRIPTION
    gen_index creates all the files to create the beautiful homepage
    with all the subfolders and their index files, it also creates
    the index file for the mobile version, and sitemaps.
    If no option is specified, all files are generated (same as "-dms").
    
OPTIONS
    -h        prints out this help.
    -d        create desktop-version, and index-files.
    -m        create mobile-version of main index.
    -s        create sitemaps.
    
EO_HELP
exit;
}

sub compare_md5 {
    my ($file_orig, $file_new) = @_;
    my $return_val;
    my $file_orig_hash;
    my $file_new_hash;
            
    if (!-f "$file_orig") {
        open (NEW, '>>', "$file_orig") or die "warning: can not touch $file_orig: $!";
        close NEW;
    }

    open (my $md5_orig, '<', "$file_orig") or die "warning: can not hash $file_orig: $!" if
        (-f "$file_orig");
    binmode ($md5_orig);
    $file_orig_hash = Digest::MD5->new->addfile($md5_orig)->hexdigest;
    close $md5_orig;

    open (my $md5_new, '<', "$file_new") or die "warning: can not hash $file_new: $!" if
        (-f "$file_new");
    binmode ($md5_new);
    $file_new_hash = Digest::MD5->new->addfile($md5_new)->hexdigest;
    close $md5_new;

    if ($file_orig_hash eq $file_new_hash) {
        unlink "$file_new" or warn "could not unlink $file_new : $!";
        $return_val = 0;
    } else {
        # print STDOUT "  O> $file_orig: $file_orig_hash\n";
        # print STDOUT "  N> $file_new: $file_new_hash\n";
        rename("$file_new", "$file_orig") or warn "could not rename $file_new: $!";
        chown 80, 80, "$file_orig";
        $return_val = 1;
    }

    return $return_val;
}