commit 189a6c4b21c9fafd4f3df3f9b21ab50ff957d3b4
Author: David Voznyarskiy <davidv@no-reply@disroot.org>
Date: Thu Apr 16 21:41:59 2026 -0700
added support for images and minor fixes
Signed-off-by: David Voznyarskiy <davidv@no-reply@disroot.org>
diff --git a/shgit/logs.go b/shgit/logs.go
index 2d0f06f..d549b12 100644
--- a/shgit/logs.go
+++ b/shgit/logs.go
@@ -19,8 +19,7 @@ func logTest(repo string, path string, numofCommits int) {
panic(err)
}
- // TODO fix formatting
- // TODO add coloring and links
+ // TODO add coloring maybe
for i := range numofCommits {
cmd, err := exec.Command(
"git",
diff --git a/shgit/shared.go b/shgit/shared.go
index 228d9d6..9159a66 100644
--- a/shgit/shared.go
+++ b/shgit/shared.go
@@ -120,7 +120,7 @@ var genTopPart = func(repo string, depth int) string {
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("</code></td>")
b.WriteString("</tr>\n")
b.WriteString("</table>")
diff --git a/shgit/shgit.go b/shgit/shgit.go
index 15ec1b9..e38e854 100644
--- a/shgit/shgit.go
+++ b/shgit/shgit.go
@@ -75,24 +75,18 @@ func indexPage(topPart string, repo string, output string, numofCommits int, num
).Output()
headBranchName := strings.TrimSpace(string(cmd))
- file.WriteString("<table>")
- file.WriteString("<tr>")
-
- file.WriteString("<td style=\"padding-right:9px\">")
- file.WriteString(headBranchName + ", ")
+ file.WriteString("<table><tr><td style=\"padding-right:9px\">")
+ file.WriteString(headBranchName + ", " + numofCommitsStr)
if numofCommits > 1 {
- file.WriteString(numofCommitsStr + " commits")
+ file.WriteString(" commits")
} else {
- file.WriteString(numofCommitsStr + " commit")
+ file.WriteString(" commit")
}
file.WriteString("</td>")
- // TODO add first commit
// TODO add first author
- file.WriteString("</tr></table>")
-
- file.WriteString("<br>")
+ file.WriteString("</tr></table><br>")
possibleFilePaths := []string{"README", "README.md", "readme.md"}
for _, f := range possibleFilePaths {
path := filepath.Join(repo, f)
diff --git a/shgit/tree.go b/shgit/tree.go
index 1df2610..0af71f4 100644
--- a/shgit/tree.go
+++ b/shgit/tree.go
@@ -2,6 +2,7 @@ package main
import (
"fmt"
+ "io"
"io/fs"
"log"
"os"
@@ -84,15 +85,55 @@ func treeFiles(path string, output string, relPath string, repo string) {
depth := strings.Count(relPath, "/")
topPart := genTopPart(repo, depth+1)
+ file.WriteString(topPart)
// 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 + "\">")
+ outputFile = filepath.Join(output, "media", relPath)
+ os.MkdirAll(filepath.Dir(outputFile), 0o755)
+
+ err := copyFile(path, outputFile)
+ if err != nil {
+ panic(err)
+ }
+
+ file.WriteString("\n<img src=\"")
+ depth += 1
+ for range depth {
+ file.WriteString("../")
+ }
+
+ file.WriteString("media/" + relPath + "\">")
return
}
- file.WriteString(topPart)
writePerFile(file, path)
}
+
+func copyFile(src, dst string) error {
+ // Ensure destination directory exists
+ if err := os.MkdirAll(filepath.Dir(dst), 0o755); err != nil {
+ return err
+ }
+
+ in, err := os.Open(src)
+ if err != nil {
+ return err
+ }
+ defer in.Close()
+
+ out, err := os.Create(dst)
+ if err != nil {
+ return err
+ }
+ defer out.Close()
+
+ _, err = io.Copy(out, in)
+ if err != nil {
+ return err
+ }
+
+ return out.Sync() // flush to disk
+}