afe1d2da3d2fb26b87ec0e9a29e7a4e7d067184a
commit afe1d2da3d2fb26b87ec0e9a29e7a4e7d067184a
Author: spesk1 <spesk@pm.me>
Date: Sat Apr 18 01:35:24 2020 +0000

Added link to view raw files

diff --git a/README.md b/README.md
index 28c6f3b..f0299f2 100644
--- a/README.md
+++ b/README.md
@@ -19,18 +19,18 @@ DONE:
* Show git:// address for cloning (configurable via config file)
* Support detection of misconfig of config file (pretty basic at this stage)
* Detects binary files
+* Show last time site was generated in top level index
+* Links to view raw files (cannot be used with cURL as pages are rendered as HTML)

TODO:
-* Show last commit time in top level index
-* Link to view raw file
-* Get diff stat for top of log index links
+* User-agent detection for `curl http://link | bash` use cases (stretch)
* Code needs to be more robust / handle failure cases
* Need to recurse git home, right now will only pull dirs in root of git home
-* README.md markdown renderer/parser / display in project index (Halfway / in progress)
-* (Stretch Goal) HTML based syntax highlighting for files
-* View history of files
-* Add support for displaying difference branches
-* Figure out more efficient/faster detection of binary files
+* README.md markdown renderer/parser / display in project index (Partially implemented)
+* HTML based syntax highlighting for files
+* File history
+* Display/browse branches
+* More efficient/faster detection of binary files

## Layout ##
* gsg -- Perl script to generate the site, uses modules below
diff --git a/lib/Gsg/Html.pm b/lib/Gsg/Html.pm
index 56bf724..12e62c3 100644
--- a/lib/Gsg/Html.pm
+++ b/lib/Gsg/Html.pm
@@ -116,6 +116,32 @@ sub gen_line_nums($$$) {

}

+sub gen_raw_html($$$) {
+
+ my $raw_file = shift;
+ my $filename = shift;
+ my $logger = shift;
+
+ my $html_file;
+ # Might be a better way to do this? TODO
+ open my $fh, '>>', \$html_file or die "Can't open variable: $!";
+
+ print $fh "<!DOCTYPE html><html><div id=\"content\"><pre id=\"blob\">";
+ foreach my $line ( split("\n", $raw_file) ) {
+ if ($line ne "") {
+ $line = check_for_html($line);
+ }
+ print $fh "$line<br>";
+ }
+
+ print $fh "</pre></div><html>";
+ close $fh;
+
+ $logger->info("Generated HTML file for $filename");
+ return $html_file;
+
+}
+
sub gen_diff_colors($$$) {

my $raw_diff = shift;
@@ -198,18 +224,22 @@ sub write_project_content($$$$$) {
append_file("<b>Files for $projects_map{$project_path}</b><br>",$project_index);
append_file("<hr/>",$project_index);
## Write files ##
- append_file("<table><div id=\"cotent\"><table id=\"index\"><thead><tr><td><b>File</b></td><td><b>Commit</b></td></tr></thead><tbody>",$project_index);
+ append_file("<table><div id=\"cotent\"><table id=\"index\"><thead><tr><td><b>File</b></td><td><b>Commit</b></td><td><b>Raw</b></td></tr></thead><tbody>",$project_index);
foreach my $filename ( sort keys %$file_content_ref ) {
my $browserCompat = $filename . ".html";
+ my $browserCompatRaw = $filename . "_raw" . ".html";
# Rewrite dir paths so we can save on disk without producing actual dir structure
if ( $filename =~ m/\// ) {
my $copy = $filename;
$copy =~ s/\//_/g;
$browserCompat = $copy . ".html";
+ $browserCompatRaw = $copy . "_raw" . ".html";
}
- append_file("<tr><td><a href=\"$browserCompat\">$filename</a></td><td>${$file_tree_ref}{$filename}</td>",$project_index);
+ append_file("<tr><td><a href=\"$browserCompat\">$filename</a></td><td>${$file_tree_ref}{$filename}</td><td><a href=\"$browserCompatRaw\">raw</a></td>",$project_index);
my $html_file = gen_line_nums(${$file_content_ref}{$filename},$filename,$logger);
write_file("$html_file",$spec_web_dir . $browserCompat);
+ my $raw_html_file = gen_raw_html(${$file_content_ref}{$filename},$filename,$logger);
+ write_file("$raw_html_file",$spec_web_dir . $browserCompatRaw);
}

append_file("</tr></tbody></table></div></body>",$project_index);