Browse Source

Started HTML writing stuff

spesk1 4 years ago
parent
commit
1241591cbf
2 changed files with 41 additions and 1 deletions
  1. 3 0
      gsg
  2. 38 1
      lib/Gsg/Html.pm

+ 3 - 0
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);
 

+ 38 - 1
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;