Browse Source

Added line counters

spesk1 4 years ago
parent
commit
9695844961
2 changed files with 29 additions and 4 deletions
  1. 2 1
      README.md
  2. 27 3
      lib/Gsg/Html.pm

+ 2 - 1
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

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