Html.pm 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package Gsg::Html;
  2. use strict;
  3. use warnings;
  4. use Log::Log4perl qw(:easy);
  5. use Exporter qw(import);
  6. our @EXPORT_OK = qw(write_file append_file write_root_index);
  7. # These subs might belong in shellex
  8. sub write_file {
  9. my $content = shift;
  10. my $path = shift;
  11. open(my $fh, ">", $path) or die "Couldnt open $path\n";
  12. print $fh "$content";
  13. close $fh;
  14. }
  15. sub append_file {
  16. my $content = shift;
  17. my $path = shift;
  18. open(my $fh, ">>", $path) or die "Couldnt open $path\n";
  19. print $fh "$content";
  20. close $fh;
  21. }
  22. sub write_root_index {
  23. my $index = shift;
  24. my $project_dirs_ref = shift;
  25. write_file("", $index);
  26. append_file("<html><body><b>Git Projects</b><br><head><META NAME=\"ROBOTS\" CONTENT=\"NOINDEX, NOFOLLOW\"></head>\n",$index);
  27. append_file("<small><i>Statically generated web root for browsing my git projects</i></small><br>",$index);
  28. append_file("<small><i>This is a read-only site and does not provide a merge/clone interface</i></small><hr/>",$index);
  29. foreach my $project ( @$project_dirs_ref ) {
  30. append_file("<table><div id=\"cotent\"><table id=\"index\"><tbody>",$index);
  31. append_file("<tr><td><a href=\"projects/$project/index.html\">$project</a></td>",$index);
  32. system("mkdir -p $projects_dir$project") == 0 or die "Couldnt create $projects_dir/$project";
  33. }
  34. append_file("</tr></tbody></table></div></body></html>",$index);
  35. }
  36. 1;