96958449619af8d5f6e8d7f2426dfbf18823e857
commit 96958449619af8d5f6e8d7f2426dfbf18823e857
Author: spesk1 <spesk@pm.me>
Date: Sat Jun 22 18:58:46 2019 +0000

Added line counters

diff --git a/README.md b/README.md
index 14ad80f..f29117d 100644
--- a/README.md
+++ b/README.md
@@ -13,12 +13,13 @@ DONE:
* Generate top level index with links to all projects
* Generate project specific index with links to git log/diffs and file content of repo
* Extremely basic markdown parser (only supports headings and non nested bullets
+* Line numbers for file browsing

TODO:
+* Show git:// address for cloning (configurable via config file)
* 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
* Diff highlighting for log
-* Line numbers for file browsing
* README.md markdown renderer/parser / display in project index
* (Stretch Goal) HTML based syntax highlighting for files
* Support detection of misconfig of config file
diff --git a/lib/Gsg/Html.pm b/lib/Gsg/Html.pm
index d83c579..8e64209 100644
--- a/lib/Gsg/Html.pm
+++ b/lib/Gsg/Html.pm
@@ -54,6 +54,29 @@ sub write_root_index($$$$) {

}

+sub gen_line_nums($$) {
+
+ my $raw_file = 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\">";
+ my $line_counter = 1;
+ foreach my $line ( split("\n", $raw_file) ) {
+ print $fh "<a href=\"\#l$line_counter\" class=\"line\" id=\"l$line_counter\">$line_counter</a>\t$line</br>";
+ $line_counter++;
+ }
+
+ print $fh "</pre></div><html>";
+ close $fh;
+
+ return $html_file;
+
+}
+
# Main sub for generating project page
# Might make more sense to split into more subs?
sub write_project_content($$$$) {
@@ -91,15 +114,16 @@ sub write_project_content($$$$) {
## 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);
foreach my $filename ( sort keys %$file_content_ref ) {
- my $browserCompat = $filename . ".txt";
+ my $browserCompat = $filename . ".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 . ".txt";
+ $browserCompat = $copy . ".html";
}
append_file("<tr><td><a href=\"$browserCompat\">$filename</a></td><td>${$file_tree_ref}{$filename}</td>",$project_index);
- write_file("${$file_content_ref}{$filename}",$spec_web_dir . $browserCompat);
+ my $html_file = gen_line_nums(${$file_content_ref}{$filename},$logger);
+ write_file("$html_file",$spec_web_dir . $browserCompat);
}

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