shroomgit

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

commit 196f45b52be7ce3bb87268148805506ebcb91912
Author: David Voznyarskiy <davidv@no-reply@disroot.org>
Date:   Sun Apr 12 13:54:02 2026 -0700

    made the config to be default and empty for everyone, minor optimization with the use of the number of commits in a repo
    
    Signed-off-by: David Voznyarskiy <davidv@no-reply@disroot.org>

diff --git a/shgit/config.go b/shgit/config.go
index 15d10f5..c0f6036 100644
--- a/shgit/config.go
+++ b/shgit/config.go
@@ -13,9 +13,9 @@ var shgit = config{ favicon: "logo.png", logo: "logo.png", logoHref: "..",
- logoWidth: 40,
- logoHeight: 40,
- url: "https://git.davidvoz.net/",
+ logoWidth: 0,
+ logoHeight: 0,
+ url: "https://",
} var styles = map[string]string{ diff --git a/shgit/logs.go b/shgit/logs.go index 53607d0..839d9c9 100644
--- a/shgit/logs.go
+++ b/shgit/logs.go
@@ -6,7 +6,6 @@ import ( "os" "os/exec" "path/filepath"
- "strconv"
"strings" ) @@ -20,7 +19,14 @@ func logTest(repo string, path string) { panic(err) }
- cmd, err := exec.Command("git", "-C", repo, "rev-list", "--reverse", "--date-order", "HEAD").Output()
+ cmd, err := exec.Command(
+ "git",
+ "-C", repo,
+ "rev-list",
+ "--reverse",
+ "--date-order",
+ "HEAD",
+ ).Output()
if err != nil { panic(err) } @@ -76,7 +82,6 @@ func commitPageWriter(file *os.File, lines []string) { file.WriteString("<div style=\"color:#e54e50\">") file.WriteString(escaped) file.WriteString("</div>")
-
} else { file.WriteString(escaped) file.WriteString("\n") @@ -86,7 +91,7 @@ func commitPageWriter(file *os.File, lines []string) { file.WriteString("</pre>\n") }
-func logPage(topPart string, repo string, path string) {
+func logPage(topPart string, repo string, path string, numofCommits int) {
outputFile := filepath.Join(path, "log.html") file, err := os.Create(outputFile) if err != nil { @@ -94,21 +99,6 @@ func logPage(topPart string, repo string, path string) { } defer file.Close()
- cmd, err := exec.Command(
- "git",
- "-C",
- repo,
- "rev-list",
- "--count",
- "HEAD",
- ).Output()
- if err != nil {
- return
- }
-
- numofCommitsStr := strings.TrimSpace(string(cmd))
- numofCommits, _ := strconv.Atoi(numofCommitsStr)
-
file.WriteString(topPart) file.WriteString("<table>") diff --git a/shgit/shared.go b/shgit/shared.go index 00f78fd..0297e90 100644
--- a/shgit/shared.go
+++ b/shgit/shared.go
@@ -115,14 +115,16 @@ var genTopPart = func(repo string, depth int) string { b.WriteString(desc) b.WriteString("<hr>")
- b.WriteString("<table>\n")
- b.WriteString("<tr>\n<td>\n<code style=\"background-color: #222; color: white; padding: 4px; user-select: all; border: none;\">")
- b.WriteString("git clone " + config.url + repoName + ".git")
- b.WriteString("\n</code></td>")
+ if config.url != "" {
+ b.WriteString("<table>\n")
+ b.WriteString("<tr>\n<td>\n<code style=\"background-color: #222; padding: 4px; user-select: all; border: none;\">")
+ b.WriteString("git clone " + config.url + repoName + ".git")
+ b.WriteString("\n</code></td>")
- b.WriteString("</tr>\n")
- b.WriteString("</table>")
+ b.WriteString("</tr>\n")
+ b.WriteString("</table>")
+ }
b.WriteString("\n<div style=\"display:flex; flex-wrap:wrap; gap:30px;margin-top:3px;\">\n") @@ -156,7 +158,7 @@ var genTopPart = func(repo string, depth int) string { b.WriteString("</a>") b.WriteString("</div>\n")
- files := []string{"LICENSE", "LICENSE.txt", "LICENSE.md", "license", "COPYING"}
+ files := []string{"LICENSE", "LICENSE.txt", "LICENSE.md", "license", "license.txt", "COPYING", "copying"}
for _, f := range files { possibleL := filepath.Join(repo, f) @@ -214,4 +216,3 @@ func getRepoNameAndDesc(repo string) (string, string) { return filepath.Base(repo), desc }
-
diff --git a/shgit/shgit.go b/shgit/shgit.go index e2bd1aa..2a99f6b 100644
--- a/shgit/shgit.go
+++ b/shgit/shgit.go
@@ -25,21 +25,35 @@ func main() { os.Exit(1) }
+ cmd, err := exec.Command(
+ "git",
+ "-C",
+ repo,
+ "rev-list",
+ "--count",
+ "HEAD",
+ ).Output()
+ if err != nil {
+ panic(err)
+ }
+ numofCommitsStr := strings.TrimSpace(string(cmd))
+ numofCommits, _ := strconv.Atoi(numofCommitsStr)
+
// shared.go topPart := genTopPart(repo, 0) // this file
- indexPage(topPart, repo, output)
+ indexPage(topPart, repo, output, numofCommits, numofCommitsStr)
// logs.go
- logPage(topPart, repo, output)
+ logPage(topPart, repo, output, numofCommits)
logTest(repo, output) // tree.go treeRepo(topPart, repo, output) }
-func indexPage(topPart string, repo string, output string) {
+func indexPage(topPart string, repo string, output string, numofCommits int, numofCommitsStr string) {
outputFile := filepath.Join(output, "index.html") file, _ := os.Create(outputFile) defer file.Close() @@ -47,23 +61,11 @@ func indexPage(topPart string, repo string, output string) { file.WriteString("<b>Recent Commits</b>\n")
- cmd, _ := exec.Command(
- "git",
- "-C",
- repo,
- "rev-list",
- "--count",
- "HEAD",
- ).Output()
-
- numofCommitsStr := strings.TrimSpace(string(cmd))
- numofCommits, _ := strconv.Atoi(numofCommitsStr)
-
indexPageCommitTable(numofCommits, file, repo, output) file.WriteString("<br><b>Head Branch</b>\n")
- cmd, _ = exec.Command(
+ cmd, _ := exec.Command(
"git", "-C", repo, @@ -88,8 +90,7 @@ func indexPage(topPart string, repo string, output string) { // TODO add first commit // TODO add first author
- file.WriteString("</tr>")
- file.WriteString("</table>")
+ file.WriteString("</tr></table>")
file.WriteString("<br>") possibleFilePaths := []string{"README", "README.md", "readme.md"} @@ -108,6 +109,7 @@ 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>") @@ -163,7 +165,7 @@ func indexPageCommitTable(numofCommits int, file *os.File, repo string, path str if len(commit) > maxLen { commit = commit[:maxLen] + "..." }
- // TODO add the paths to their commit pages
+
file.WriteString("<td valign=\"top\">") file.WriteString("<a href=\"logs/") file.WriteString(hash) @@ -193,4 +195,3 @@ func indexPageCommitTable(numofCommits int, file *os.File, repo string, path str file.WriteString("</table>") file.WriteString("</body>") }
-
diff --git a/shgit/tree.go b/shgit/tree.go index 8eace16..1df2610 100644
--- a/shgit/tree.go
+++ b/shgit/tree.go
@@ -85,6 +85,14 @@ func treeFiles(path string, output string, relPath string, repo string) { depth := strings.Count(relPath, "/") topPart := genTopPart(repo, depth+1)
+ // TODO handle images better
+ // maybe try making a photos/ folder to hold it
+ ex := filepath.Ext(path)
+ if ex == ".png" || ex == ".jpg" || ex == ".webp" || ex == ".jpeg" {
+ file.WriteString("\n<img src=\"" + path + "\">")
+ return
+ }
+
file.WriteString(topPart) writePerFile(file, path) } diff --git a/shindex/config.go b/shindex/config.go index 676cf3a..b4dd461 100644
--- a/shindex/config.go
+++ b/shindex/config.go
@@ -13,8 +13,8 @@ type config struct { var shindex = config{ title: "Repositories", logo: "logo.png",
- logoHref: "https://davidvoz.net",
- logoWidth: 88,
- logoHeight: 36,
- desc: "this is a static index of my repos, for more visit <a href='https://git.disroot.org/davidv'>here</a>",
+ logoHref: "https://",
+ logoWidth: 0,
+ logoHeight: 0,
+ desc: "",
}