shroomgit

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

commit 2dcc0d833da485dda1bf6ff6b1ac283196ba70d1
Author: David Voznyarskiy <davidv@no-reply@disroot.org>
Date:   Sat Mar 28 17:52:43 2026 -0700

    i honestly forgot what changed but i went back and forth so many times but im sure its further along
    
    Signed-off-by: David Voznyarskiy <davidv@no-reply@disroot.org>

diff --git a/config/config.go b/config/config.go
new file mode 100644
index 0000000..e054c37
--- /dev/null
+++ b/config/config.go
@@ -0,0 +1,41 @@
+// Package config
+package config
+
+type Config struct {
+ Title string
+ Favicon string
+ Logo string
+ LogoHref string
+ LogoWidth int
+ LogoHeight int
+ Desc string
+ URL string
+}
+
+// Shindex config
+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>",
+}
+
+// Shgit config
+var Shgit = Config{
+ Favicon: "logo.png",
+ Logo: "logo.png",
+ LogoHref: "..",
+ LogoWidth: 40,
+ LogoHeight: 40,
+ URL: "https://git.davidvoz.net/",
+}
+
+var Style string = `
+ .codeline {
+ text-align: right;
+ vertical-align: top;
+ user-select: none;
+ }
+`
diff --git a/shared/shared.go b/shared/shared.go deleted file mode 100644 index 5391124..0000000
--- a/shared/shared.go
+++ /dev/null
@@ -1,66 +0,0 @@
-// Package shared
-package shared
-
-import (
- "os"
- "path/filepath"
- "strings"
-)
-
-type Config struct {
- Title string
- Favicon string
- Logo string
- LogoHref string
- LogoWidth int
- LogoHeight int
- Desc string
-}
-
-// Shindex config
-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>",
-}
-
-// Shgit config
-var Shgit = Config{
- Favicon: "logo.png",
- Logo: "logo.png",
- LogoHref: "..",
- LogoWidth: 40,
- LogoHeight: 40,
-}
-
-func GetRepoNameAndDesc(repo string) (string, string) {
- descFile := filepath.Join(repo, ".git", "description")
- desc := ""
- if data, err := os.ReadFile(descFile); err == nil {
- desc = string(data)
- }
-
- gitConfig := filepath.Join(repo, ".git", "config")
- data, err := os.ReadFile(gitConfig)
- if err != nil {
- return filepath.Base(repo), desc
- }
-
- content := string(data)
-
- for line := range strings.SplitSeq(content, "\n") {
- line = strings.TrimSpace(line)
- if strings.HasPrefix(line, "url =") {
- parts := strings.Fields(line)
- url := parts[2]
- url = strings.TrimSuffix(url, ".git")
- segments := strings.Split(url, "/")
- return segments[len(segments)-1], desc
- }
- }
-
- return filepath.Base(repo), desc
-}
diff --git a/shgit/shared.go b/shgit/shared.go index a199fdd..0f112c6 100644
--- a/shgit/shared.go
+++ b/shgit/shared.go
@@ -4,10 +4,11 @@ import ( "bufio" "html" "os"
+ "path/filepath"
"strconv" "strings"
- "shroomgit/shared"
+ "shroomgit/config"
) // prints an html section for each file inputted @@ -20,14 +21,14 @@ func writePerFile(file *os.File, path string) { numLine := 1 var strNumLine string
- file.WriteString("<table style=\"white-space:pre\">")
+ file.WriteString("\n<table style=\"white-space:pre\">")
for scanner.Scan() { line := scanner.Text() escaped := html.EscapeString(line) strNumLine = strconv.Itoa(numLine) file.WriteString("<tr>")
- file.WriteString("<td style=\"text-align:right;vertical-align:top;user-select:none\">")
+ file.WriteString("<td class=\"codeline\">")
file.WriteString("<a href=\"#" + strNumLine + "\" id=\"" + strNumLine + "\">") file.WriteString(strNumLine) file.WriteString("</a>") @@ -41,13 +42,15 @@ func writePerFile(file *os.File, path string) { numLine++ } file.WriteString("</table>")
+ file.WriteString("<br>")
} // the common HTML lines that all files will share var genTopPart = func(repo string) string { var b strings.Builder
- config := shared.Shgit
- repoName, desc := shared.GetRepoNameAndDesc(repo)
+ shgitStyle := config.Style
+ config := config.Shgit
+ repoName, desc := getRepoNameAndDesc(repo)
b.WriteString("<!DOCTYPE html>\n") b.WriteString("<html>\n") @@ -57,28 +60,36 @@ var genTopPart = func(repo string) string { b.WriteString(config.Favicon) b.WriteString("\" \\>\n")
+ b.WriteString("<style>")
+ b.WriteString(shgitStyle)
+ b.WriteString("</style>\n")
+
b.WriteString("</head>\n") b.WriteString("<body>\n") b.WriteString("<table>")
- b.WriteString("<tr>")
-
- b.WriteString("<td>")
- b.WriteString("<a href=\"")
- b.WriteString(config.LogoHref)
- b.WriteString("\">")
- b.WriteString("<img src=\"")
- b.WriteString(config.Logo)
- b.WriteString("\" width=")
- b.WriteString(strconv.Itoa(config.LogoWidth))
- b.WriteString(" height=")
- b.WriteString(strconv.Itoa(config.LogoHeight))
- b.WriteString("/>")
- b.WriteString("</a>")
- b.WriteString("</td>")
+ b.WriteString("<tr>\n")
+
+ if config.Logo != "" {
+ b.WriteString("<td>")
+ b.WriteString("<a href=\"")
+ b.WriteString(config.LogoHref)
+
+ b.WriteString("\">")
+
+ b.WriteString("<img src=\"")
+ b.WriteString(config.Logo)
+ b.WriteString("\" width=")
+ b.WriteString(strconv.Itoa(config.LogoWidth))
+ b.WriteString(" height=")
+ b.WriteString(strconv.Itoa(config.LogoHeight))
+ b.WriteString("/>")
+ b.WriteString("</a>")
+ b.WriteString("</td>")
+ }
- b.WriteString("<td><h2 style=\"margin-left:10px\">")
+ b.WriteString("\n<td><h2 style=\"margin-left:10px\">")
b.WriteString(repoName) b.WriteString("</h2>") @@ -86,18 +97,16 @@ var genTopPart = func(repo string) string { b.WriteString("</tr>") b.WriteString("</table>")
- b.WriteString("<table>")
- b.WriteString("<tr>")
b.WriteString(desc)
- // TODO why this is creating a highlighting error on browser
b.WriteString("<hr>")
+ b.WriteString("<table>\n")
- b.WriteString("<td><code style=\"background-color: #222; color: white; padding: 4px; user-select: all; border: none;\">")
- b.WriteString("git clone https://git.davidvoz.net/ffr.git")
- b.WriteString("</code></td>")
+ 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>")
- b.WriteString("</tr>")
+ b.WriteString("</tr>\n")
b.WriteString("</table>") b.WriteString("\n<div style=\"display:flex; flex-wrap:wrap; gap:30px;margin-top:3px;\">\n") @@ -136,3 +145,32 @@ var genTopPart = func(repo string) string { return b.String() }
+
+func getRepoNameAndDesc(repo string) (string, string) {
+ descFile := filepath.Join(repo, ".git", "description")
+ desc := ""
+ if data, err := os.ReadFile(descFile); err == nil {
+ desc = string(data)
+ }
+
+ gitConfig := filepath.Join(repo, ".git", "config")
+ data, err := os.ReadFile(gitConfig)
+ if err != nil {
+ return filepath.Base(repo), desc
+ }
+
+ content := string(data)
+
+ for line := range strings.SplitSeq(content, "\n") {
+ line = strings.TrimSpace(line)
+ if strings.HasPrefix(line, "url =") {
+ parts := strings.Fields(line)
+ url := parts[2]
+ url = strings.TrimSuffix(url, ".git")
+ segments := strings.Split(url, "/")
+ return segments[len(segments)-1], desc
+ }
+ }
+
+ return filepath.Base(repo), desc
+}
diff --git a/shgit/shgit.go b/shgit/shgit.go index 121b7c2..1706d8c 100644
--- a/shgit/shgit.go
+++ b/shgit/shgit.go
@@ -70,7 +70,12 @@ func indexPage(topPart string, repo string, output string) { file.WriteString("<tr>") file.WriteString("<td style=\"padding-right:9px\">")
- file.WriteString(headBranchName)
+ file.WriteString(headBranchName + ", ")
+ if numofCommits > 1 {
+ file.WriteString(numofCommitsStr + " commits")
+ } else {
+ file.WriteString(numofCommitsStr + " commit")
+ }
file.WriteString("</td>") // TODO add first commit @@ -191,25 +196,6 @@ func logPage(topPart string, repo string, path string) { file.WriteString(topPart) file.WriteString("<table>")
- file.WriteString("<tr>")
- file.WriteString("<td>")
- file.WriteString("Date")
- file.WriteString("<hr>")
- file.WriteString("</td>")
- file.WriteString("<td>")
- file.WriteString("Commit")
- file.WriteString("<hr>")
- file.WriteString("</td>")
- file.WriteString("<td>")
- file.WriteString("Name")
- file.WriteString("<hr>")
- file.WriteString("</td>")
- file.WriteString("<td>")
- file.WriteString("F")
- file.WriteString("<hr>")
- file.WriteString("</td>")
-
- file.WriteString("</tr>\n")
for i := range numofCommits { file.WriteString("<tr>") @@ -236,7 +222,7 @@ func logPage(topPart string, repo string, path string) { "--pretty=format:%s", ).Output() commit := strings.TrimSpace(string(cmd))
- file.WriteString("<td valign=\"top\" style=\"word-break:break-word\">")
+ file.WriteString("<td>")
file.WriteString("\n<a>" + commit + "</a>\n") file.WriteString("</td>\n") @@ -265,10 +251,10 @@ func logPage(topPart string, repo string, path string) { if len(arr) == 0 { continue }
- file.WriteString("<td valign=\"top\" align=\"right\">")
+ 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("<td style=\"color:ForestGreen\" valign=\"top\" align=\"right\">+")
file.WriteString(arr[3]) file.WriteString("</td>\n") if len(arr) > 5 { diff --git a/shindex/shindex.go b/shindex/shindex.go index 02b704f..9640a8d 100644
--- a/shindex/shindex.go
+++ b/shindex/shindex.go
@@ -7,7 +7,7 @@ import ( "path/filepath" "strings"
- "shroomgit/shared"
+ "shroomgit/config"
) func main() { @@ -26,7 +26,7 @@ func gitTable(args []string) { fmt.Println("<div style=\"display:flex; flex-wrap:wrap; gap;9px;\">") for _, repo := range args {
- repoName, desc := shared.GetRepoNameAndDesc(repo)
+ repoName, desc := getRepoNameAndDesc(repo)
cmd := exec.Command( "git", "-C", repo, @@ -69,7 +69,7 @@ func gitTable(args []string) { } func basicPart() {
- config := shared.Shindex
+ config := config.Shindex
fmt.Println("<!DOCTYPE html>") fmt.Println("<html>") fmt.Println("<head>") @@ -124,6 +124,35 @@ func detectLicense(repo string) string { return "0" }
+func getRepoNameAndDesc(repo string) (string, string) {
+ descFile := filepath.Join(repo, ".git", "description")
+ desc := ""
+ if data, err := os.ReadFile(descFile); err == nil {
+ desc = string(data)
+ }
+
+ gitConfig := filepath.Join(repo, ".git", "config")
+ data, err := os.ReadFile(gitConfig)
+ if err != nil {
+ return filepath.Base(repo), desc
+ }
+
+ content := string(data)
+
+ for line := range strings.SplitSeq(content, "\n") {
+ line = strings.TrimSpace(line)
+ if strings.HasPrefix(line, "url =") {
+ parts := strings.Fields(line)
+ url := parts[2]
+ url = strings.TrimSuffix(url, ".git")
+ segments := strings.Split(url, "/")
+ return segments[len(segments)-1], desc
+ }
+ }
+
+ return filepath.Base(repo), desc
+}
+
func printHelp(errorNum int) { switch errorNum { case 1: