commit 06eadf0bd5b44ca2114ee2d16f3c82dab1b0f26a
Author: David Voznyarskiy <davidv@no-reply@disroot.org>
Date: Wed Mar 25 16:21:13 2026 -0700
WIP save point for index page generator
Signed-off-by: David Voznyarskiy <davidv@no-reply@disroot.org>
diff --git a/shgit/shared.go b/shgit/shared.go
index cb53571..43afb4b 100644
--- a/shgit/shared.go
+++ b/shgit/shared.go
@@ -11,23 +11,36 @@ import (
)
// prints an html section for each file inputted
+// TODO class option for lines instead of the clunky style elements
func writePerFile(file *os.File, path string) {
notFile, _ := os.Open(path)
defer notFile.Close()
scanner := bufio.NewScanner(notFile)
numLine := 1
+ var strNumLine string
+
+ file.WriteString("<table>")
for scanner.Scan() {
line := scanner.Text()
escaped := html.EscapeString(line)
-
- file.WriteString("<p>")
- file.WriteString(strconv.Itoa(numLine))
+ strNumLine = strconv.Itoa(numLine)
+
+ file.WriteString("<tr>")
+ file.WriteString("<td style=\"text-align:right;vertical-align:top;user-select:none\">")
+ file.WriteString("<a href=\"#" + strNumLine + "\" id=\"" + strNumLine + "\">")
+ file.WriteString(strNumLine)
+ file.WriteString("</a>")
+ file.WriteString("</td>")
+ file.WriteString("<td>")
file.WriteString(escaped + "\n")
- file.WriteString("</p>")
+ file.WriteString("</td>")
+
+ file.WriteString("</tr>")
numLine++
}
+ file.WriteString("</table>")
}
// the common HTML lines that all files will share
diff --git a/shgit/shgit.go b/shgit/shgit.go
index f008a3a..33e022e 100644
--- a/shgit/shgit.go
+++ b/shgit/shgit.go
@@ -3,7 +3,10 @@ package main
import (
"fmt"
"os"
+ "os/exec"
"path/filepath"
+ "strconv"
+ "strings"
)
func main() {
@@ -24,21 +27,53 @@ func main() {
topPart := genTopPart(repo)
- indexPage(topPart, output)
+ indexPage(topPart, repo, output)
licensePage(topPart, repo, output)
}
-func indexPage(topPart string, output string) {
+func indexPage(topPart string, repo string, output string) {
outputFile := filepath.Join(output, "index.html")
file, _ := os.Create(outputFile)
defer file.Close()
-
file.WriteString(topPart)
- file.WriteString("<h4>Commits</h4>")
- file.WriteString("<h4>Read Me</h4>")
+
+ file.WriteString("<h3 style=\"margin-bottom:0px\">Commits</h3>")
+
+ cmd, _ := exec.Command(
+ "git",
+ "-C",
+ repo,
+ "rev-list",
+ "--count",
+ "HEAD",
+ ).Output()
+
+ numofCommitsStr := strings.TrimSpace(string(cmd))
+ numofCommits, _ := strconv.Atoi(numofCommitsStr)
+
+ indexPageCommitTable(numofCommits, file, output)
+
+ file.WriteString("<h3 style=\"margin-bottom:0px\">Read Me</h3>")
+ possibleFilePaths := []string{"README", "README.md", "readme.md"}
+ for _, f := range possibleFilePaths {
+ path := filepath.Join(repo, f)
+ if _, err := os.Stat(path); err == nil {
+ writePerFile(file, path)
+ break
+ }
+ }
+
file.WriteString("\n</body>")
}
+func indexPageCommitTable(numofCommits int, file *os.File, path string) {
+ notFile, _ := os.Open(path)
+ defer notFile.Close()
+ file.WriteString("<table>")
+ file.WriteString(strconv.Itoa(numofCommits))
+ file.WriteString("</table>")
+}
+
func licensePage(topPart string, repo string, output string) {
outputFile := filepath.Join(output, "license.html")
file, _ := os.Create(outputFile)