commit 38c16846eebe407d97ae54f499a8f700ef2d713e
Author: David Voznyarskiy <davidv@no-reply@disroot.org>
Date: Fri Apr 3 21:48:06 2026 -0700
test
Signed-off-by: David Voznyarskiy <davidv@no-reply@disroot.org>
diff --git a/README b/README
new file mode 100644
index 0000000..c49e398
--- /dev/null
+++ b/README
@@ -0,0 +1,50 @@
+Shroomgit: shindex shgit
+========================
+Quickly generate a static html page of your git repos
+
+
+Requirements
+------------
+git
+go
+
+
+Installation
+------------
+
+ git clone https://git.disroot.org/davidv/shroomgit.git
+ cd shroomgit
+ make
+
+The shindex and shgit binaries will be within the bin/ directory
+
+
+Documentation
+-------------
+1) shindex: generate an index page of various repositories
+
+ shindex repo1 repo2 ... > site.html
+
+Shindex directory outputs HTML code, use that to direct it to where you
+want. Shindex works with an unlimited amount of repositories as input.
+
+Within shared/shared.go, the logo, the page title, and description can
+be configured and edited.
+
+2) shgit: generate pages for a repository
+
+ shgit repo output_dir
+ shgit repo
+
+Still very much a work in progress. Shgit takes a repository as an
+argument and outputs multiple HTML files and directories into either a
+specified directory or, if no output directory is given, into the
+working directory.
+
+Within shared/shared.go, configuration of the logo and favicon can be
+set.
+
+
+License
+-------
+unlicense license <https://unlicense.org/>
diff --git a/README.md b/README.md
deleted file mode 100644
index ecf4474..0000000
--- a/README.md
+++ /dev/null
@@ -1,19 +0,0 @@
-## Shroomgit
-A program to quickly generate a static page of your git repos.
-Inspired by [stagit](https://codemadness.org/stagit.html)
-
-## Build
-```sh
-git clone https://git.disroot.org/davidv/shroomgit.git
-cd shroomgit
-make
-```
-The binaries will be within the `bin/` directory
-
-## Usage
-### shindex
-```
-shindex repo1 repo2 > index.html
-```
-### shgit
-not yet created
diff --git a/shgit/shared.go b/shgit/shared.go
index 43afb4b..a199fdd 100644
--- a/shgit/shared.go
+++ b/shgit/shared.go
@@ -20,7 +20,7 @@ func writePerFile(file *os.File, path string) {
numLine := 1
var strNumLine string
- file.WriteString("<table>")
+ file.WriteString("<table style=\"white-space:pre\">")
for scanner.Scan() {
line := scanner.Text()
escaped := html.EscapeString(line)
@@ -109,7 +109,7 @@ var genTopPart = func(repo string) string {
b.WriteString("</div>\n")
b.WriteString("\n<div style=\"display:flex;\">\n")
- b.WriteString("<a>")
+ b.WriteString("<a href=\"log.html\">")
b.WriteString("logs\n")
b.WriteString("</a>")
b.WriteString("</div>\n")
diff --git a/shgit/shgit.go b/shgit/shgit.go
index 21ae823..121b7c2 100644
--- a/shgit/shgit.go
+++ b/shgit/shgit.go
@@ -29,6 +29,7 @@ func main() {
indexPage(topPart, repo, output)
licensePage(topPart, repo, output)
+ logPage(topPart, repo, output)
}
func indexPage(topPart string, repo string, output string) {
@@ -37,7 +38,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>")
+ file.WriteString("<h3 style=\"margin-bottom:0px\">Recent Commits</h3>\n")
cmd, _ := exec.Command(
"git",
@@ -53,6 +54,31 @@ func indexPage(topPart string, repo string, output string) {
indexPageCommitTable(numofCommits, file, repo, output)
+ file.WriteString("<h3 style=\"margin-bottom:0px\">Head Branch</h3>\n")
+
+ cmd, _ = exec.Command(
+ "git",
+ "-C",
+ repo,
+ "rev-parse",
+ "--abbrev-ref",
+ "HEAD",
+ ).Output()
+ headBranchName := strings.TrimSpace(string(cmd))
+
+ file.WriteString("<table>")
+ file.WriteString("<tr>")
+
+ file.WriteString("<td style=\"padding-right:9px\">")
+ file.WriteString(headBranchName)
+ file.WriteString("</td>")
+
+ // TODO add first commit
+ // TODO add first author
+
+ file.WriteString("</tr>")
+ file.WriteString("</table>")
+
file.WriteString("<h3 style=\"margin-bottom:0px\">Read Me</h3>")
possibleFilePaths := []string{"README", "README.md", "readme.md"}
for _, f := range possibleFilePaths {
@@ -69,11 +95,10 @@ func indexPage(topPart string, repo string, output string) {
func indexPageCommitTable(numofCommits int, file *os.File, repo string, path string) {
notFile, _ := os.Open(path)
defer notFile.Close()
- file.WriteString("<table>")
+ file.WriteString("<table>\n")
for i := range numofCommits {
file.WriteString("<tr>")
- file.WriteString("<td>")
cmd, _ := exec.Command(
"git",
"-C", repo,
@@ -83,10 +108,10 @@ func indexPageCommitTable(numofCommits int, file *os.File, repo string, path str
"--date=format:%Y-%m-%d",
).Output()
commit := strings.TrimSpace(string(cmd))
+ file.WriteString("<td valign=\"top\">")
file.WriteString(commit)
- file.WriteString("</td>")
+ file.WriteString("</td>\n")
- file.WriteString("<td>")
cmd, _ = exec.Command(
"git",
"-C", repo,
@@ -100,10 +125,10 @@ func indexPageCommitTable(numofCommits int, file *os.File, repo string, path str
commit = commit[:maxLen] + "..."
}
// TODO add the paths to their commit pages
+ file.WriteString("<td valign=\"top\">")
file.WriteString("<a>" + commit + "</a>")
- file.WriteString("</td>")
+ file.WriteString("</td>\n")
- file.WriteString("<td>")
cmd, _ = exec.Command(
"git",
"-C", repo,
@@ -112,11 +137,13 @@ func indexPageCommitTable(numofCommits int, file *os.File, repo string, path str
"--pretty=format:%an",
).Output()
commit = strings.TrimSpace(string(cmd))
+ file.WriteString("<td valign=\"top\">")
file.WriteString(commit)
- file.WriteString("</td>")
+ file.WriteString("</td>\n")
file.WriteString("</tr>")
+ // index.html will only be showing the 5 latest or less commits
if i == 4 {
break
}
@@ -144,3 +171,115 @@ func licensePage(topPart string, repo string, output string) {
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>")
+ 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>")
+
+ 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 valign=\"top\" style=\"word-break:break-word\">")
+ 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 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>")
+}