commit 1241591cbf8a07c5b6edce380003941cc5341555
Author: spesk1 <spesk@pm.me>
Date: Sat Jun 22 01:15:33 2019 +0000
Started HTML writing stuff
diff --git a/gsg b/gsg
index 4e2128d..74e9824 100755
--- a/gsg
+++ b/gsg
@@ -9,6 +9,7 @@ use lib "/usr/local/lib";
use Shellex::Shellex qw(shellex findBin);
use Gsg::ConfigParse qw(parse_gsg_config);
use Gsg::Gather qw(get_file_tree get_projects);
+use Gsg::Html qw(write_file append_file write_root_index);
my $log_file = "gsg.log";
sub get_log_name { return $log_file; };
@@ -52,5 +53,7 @@ my $git_projects_ref = get_projects($config{'GitHome'},$config{'IgnoredProjects'
foreach my $p ( @$git_projects_ref ) {
print "$p\n";
}
+
+# write_root_index($root_index,$git_projects_ref);
# my ( $file_tree_ref, $file_content_ref, $commits_ref ) = get_file_tree($project_dir,$logger);
diff --git a/lib/Gsg/Html.pm b/lib/Gsg/Html.pm
index b92cf0c..caeb001 100644
--- a/lib/Gsg/Html.pm
+++ b/lib/Gsg/Html.pm
@@ -3,6 +3,43 @@ use strict;
use warnings;
use Log::Log4perl qw(:easy);
use Exporter qw(import);
-our @EXPORT_OK = qw();
+our @EXPORT_OK = qw(write_file append_file write_root_index);
+
+# These subs might belong in shellex
+sub write_file {
+
+ my $content = shift;
+ my $path = shift;
+ open(my $fh, ">", $path) or die "Couldnt open $path\n";
+ print $fh "$content";
+ close $fh;
+
+}
+
+sub append_file {
+ my $content = shift;
+ my $path = shift;
+ open(my $fh, ">>", $path) or die "Couldnt open $path\n";
+ print $fh "$content";
+ close $fh;
+}
+
+sub write_root_index {
+
+ my $index = shift;
+ my $project_dirs_ref = shift;
+ write_file("", $index);
+ append_file("<html><body><b>Git Projects</b><br><head><META NAME=\"ROBOTS\" CONTENT=\"NOINDEX, NOFOLLOW\"></head>\n",$index);
+ append_file("<small><i>Statically generated web root for browsing my git projects</i></small><br>",$index);
+ append_file("<small><i>This is a read-only site and does not provide a merge/clone interface</i></small><hr/>",$index);
+
+ foreach my $project ( @$project_dirs_ref ) {
+ append_file("<table><div id=\"cotent\"><table id=\"index\"><tbody>",$index);
+ append_file("<tr><td><a href=\"projects/$project/index.html\">$project</a></td>",$index);
+ system("mkdir -p $projects_dir$project") == 0 or die "Couldnt create $projects_dir/$project";
+ }
+ append_file("</tr></tbody></table></div></body></html>",$index);
+
+}
1;