shroomgit

generate static pages of git repos
git clone https://git.davidvoz.net/shroomgit.git
index
logs
tree

commit cd086f2c2c5fb516cf52182987d9ad685db19226
Author: David Voznyarskiy <davidv@no-reply@disroot.org>
Date:   Thu Mar 26 22:46:28 2026 -0700

    better formatting and README description trying to resolve stuff
    
    Signed-off-by: David Voznyarskiy <davidv@no-reply@disroot.org>

diff --git a/shgit/shgit.go b/shgit/shgit.go
index 1706d8c..881c0b3 100644
--- a/shgit/shgit.go
+++ b/shgit/shgit.go
@@ -25,11 +25,18 @@ func main() { os.Exit(1) }
- topPart := genTopPart(repo)
+ // shared.go
+ topPart := genTopPart(repo, 0)
+ // this file
indexPage(topPart, repo, output)
- licensePage(topPart, repo, output)
+
+ // logs.go
logPage(topPart, repo, output)
+ logTest(repo, output)
+
+ // tree.go
+ treeRepo(topPart, repo, output)
} func indexPage(topPart string, repo string, output string) { @@ -38,7 +45,7 @@ func indexPage(topPart string, repo string, output string) { defer file.Close() file.WriteString(topPart)
- file.WriteString("<h3 style=\"margin-bottom:0px\">Recent Commits</h3>\n")
+ file.WriteString("<b>Recent Commits</b>\n")
cmd, _ := exec.Command( "git", @@ -54,7 +61,7 @@ func indexPage(topPart string, repo string, output string) { indexPageCommitTable(numofCommits, file, repo, output)
- file.WriteString("<h3 style=\"margin-bottom:0px\">Head Branch</h3>\n")
+ file.WriteString("<br><b>Head Branch</b>\n")
cmd, _ = exec.Command( "git", @@ -84,7 +91,7 @@ func indexPage(topPart string, repo string, output string) { file.WriteString("</tr>") file.WriteString("</table>")
- file.WriteString("<h3 style=\"margin-bottom:0px\">Read Me</h3>")
+ file.WriteString("<br>")
possibleFilePaths := []string{"README", "README.md", "readme.md"} for _, f := range possibleFilePaths { path := filepath.Join(repo, f) @@ -101,10 +108,11 @@ func indexPageCommitTable(numofCommits int, file *os.File, repo string, path str notFile, _ := os.Open(path) defer notFile.Close() file.WriteString("<table>\n")
+ // TODO find out how to have a range (0 -> 4 or numofCommits)
for i := range numofCommits { file.WriteString("<tr>")
- cmd, _ := exec.Command(
+ cmd, err := exec.Command(
"git", "-C", repo, "log", "-1", @@ -112,11 +120,37 @@ func indexPageCommitTable(numofCommits int, file *os.File, repo string, path str "--pretty=format:%cd", "--date=format:%Y-%m-%d", ).Output()
+ if err != nil {
+ panic(err)
+ }
+
commit := strings.TrimSpace(string(cmd)) file.WriteString("<td valign=\"top\">") file.WriteString(commit) file.WriteString("</td>\n")
+ cmd, _ = exec.Command(
+ "git",
+ "-C",
+ repo,
+ "show",
+ fmt.Sprintf("HEAD~%d", i),
+ ).Output()
+
+ // commit := strings.TrimSpace(string(cmd))
+
+ lines := strings.Split(string(cmd), "\n")
+ var firstLine string
+ var hash string
+ if lines[0] != "" {
+ firstLine = lines[0]
+ } else {
+ return
+ }
+
+ fields := strings.Fields(firstLine)
+ hash = fields[1]
+
cmd, _ = exec.Command( "git", "-C", repo, @@ -131,7 +165,9 @@ func indexPageCommitTable(numofCommits int, file *os.File, repo string, path str } // TODO add the paths to their commit pages file.WriteString("<td valign=\"top\">")
- file.WriteString("<a>" + commit + "</a>")
+ file.WriteString("<a href=\"logs/")
+ file.WriteString(hash)
+ file.WriteString(".html\">" + commit + "</a>")
file.WriteString("</td>\n") cmd, _ = exec.Command( @@ -155,117 +191,5 @@ func indexPageCommitTable(numofCommits int, file *os.File, repo string, path str } file.WriteString("</table>")
-}
-
-func licensePage(topPart string, repo string, output string) {
- outputFile := filepath.Join(output, "license.html")
- file, _ := os.Create(outputFile)
- defer file.Close()
-
- file.WriteString(topPart)
-
- possibleFilePaths := []string{"LICENSE", "LICENSE.txt", "LICENSE.md", "license", "COPYING"}
-
- 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 logPage(topPart string, repo string, path string) {
- outputFile := filepath.Join(path, "log.html")
- file, _ := os.Create(outputFile)
- defer file.Close()
-
- cmd, _ := exec.Command(
- "git",
- "-C",
- repo,
- "rev-list",
- "--count",
- "HEAD",
- ).Output()
-
- numofCommitsStr := strings.TrimSpace(string(cmd))
- numofCommits, _ := strconv.Atoi(numofCommitsStr)
-
- file.WriteString(topPart)
- file.WriteString("<table>")
-
- for i := range numofCommits {
- file.WriteString("<tr>")
-
- cmd, _ := exec.Command(
- "git",
- "-C", repo,
- "log", "-1",
- fmt.Sprintf("--skip=%d", i),
- "--pretty=format:%cd",
- "--date=format:%Y-%m-%d",
- ).Output()
- date := strings.TrimSpace(string(cmd))
- file.WriteString("<td valign=\"top\">")
- file.WriteString(date)
-
- file.WriteString("</td>\n")
-
- cmd, _ = exec.Command(
- "git",
- "-C", repo,
- "log", "-1",
- fmt.Sprintf("--skip=%d", i),
- "--pretty=format:%s",
- ).Output()
- commit := strings.TrimSpace(string(cmd))
- file.WriteString("<td>")
- file.WriteString("\n<a>" + commit + "</a>\n")
- file.WriteString("</td>\n")
-
- cmd, _ = exec.Command(
- "git",
- "-C", repo,
- "log", "-1",
- fmt.Sprintf("--skip=%d", i),
- "--pretty=format:%an",
- ).Output()
- author := strings.TrimSpace(string(cmd))
- file.WriteString("<td style=\"white-space:nowrap\" valign=\"top\">")
- file.WriteString(author)
- file.WriteString("</td>\n")
-
- cmd, _ = exec.Command(
- "git",
- "-C", repo,
- "log", "-1",
- fmt.Sprintf("--skip=%d", i),
- "--shortstat",
- "--pretty=format:",
- ).Output()
- cmdOutput := strings.TrimSpace(string(cmd))
- arr := strings.Fields(cmdOutput)
- if len(arr) == 0 {
- continue
- }
- file.WriteString("<td style=\"padding-left: 1em\" valign=\"top\" align=\"right\">")
- file.WriteString(arr[0])
- file.WriteString("</td>\n")
- file.WriteString("<td style=\"color:ForestGreen\" valign=\"top\" align=\"right\">+")
- file.WriteString(arr[3])
- file.WriteString("</td>\n")
- if len(arr) > 5 {
- file.WriteString("<td style=\"color:Crimson\" valign=\"top\" align=\"right\">-")
- file.WriteString(arr[5])
- file.WriteString("</td>\n")
- }
-
- file.WriteString("\n</tr>")
- }
-
- file.WriteString("\n</table>")
- file.WriteString("\n</body>")
+ file.WriteString("</body>")
}