commit 086d8207ee3faadb1672e349ef8871d40ee89796
Author: David Voznyarskiy <davidv@no-reply@disroot.org>
Date: Wed Mar 25 14:21:43 2026 -0700
added a license page in shgit
diff --git a/Makefile b/Makefile
index f81cb3c..89f2573 100644
--- a/Makefile
+++ b/Makefile
@@ -12,3 +12,7 @@ shgit:
clean:
rm -rf bin
+
+test:
+ @go build -o bin/shgit ./shgit
+ @./bin/shgit bin/ffr bin/shgit_ffr
diff --git a/config/config.go b/config/config.go
deleted file mode 100644
index 7c67984..0000000
--- a/config/config.go
+++ /dev/null
@@ -1,26 +0,0 @@
-package config
-
-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: "",
- LogoWidth: 0,
- LogoHeight: 0,
- Desc: "",
-}
-
-// shgit config
-var Shgit = Config{
- Favicon: "favicon.png",
-}
diff --git a/shared/shared.go b/shared/shared.go
new file mode 100644
index 0000000..5391124
--- /dev/null
+++ b/shared/shared.go
@@ -0,0 +1,66 @@
+// 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/top_part.go b/shgit/shared.go
similarity index 73%
rename from shgit/top_part.go
rename to shgit/shared.go
index 20d90f2..cb53571 100644
--- a/shgit/top_part.go
+++ b/shgit/shared.go
@@ -1,16 +1,40 @@
package main
import (
+ "bufio"
+ "html"
+ "os"
"strconv"
"strings"
- "shroomgit/config"
+ "shroomgit/shared"
)
+// prints an html section for each file inputted
+func writePerFile(file *os.File, path string) {
+ notFile, _ := os.Open(path)
+ defer notFile.Close()
+
+ scanner := bufio.NewScanner(notFile)
+ numLine := 1
+ for scanner.Scan() {
+ line := scanner.Text()
+ escaped := html.EscapeString(line)
+
+ file.WriteString("<p>")
+ file.WriteString(strconv.Itoa(numLine))
+ file.WriteString(escaped + "\n")
+ file.WriteString("</p>")
+
+ numLine++
+ }
+}
+
// the common HTML lines that all files will share
-var topPart = func() string {
+var genTopPart = func(repo string) string {
var b strings.Builder
- config := config.Shgit
+ config := shared.Shgit
+ repoName, desc := shared.GetRepoNameAndDesc(repo)
b.WriteString("<!DOCTYPE html>\n")
b.WriteString("<html>\n")
@@ -42,7 +66,7 @@ var topPart = func() string {
b.WriteString("</td>")
b.WriteString("<td><h2 style=\"margin-left:10px\">")
- b.WriteString("ffr")
+ b.WriteString(repoName)
b.WriteString("</h2>")
b.WriteString("</td>")
@@ -51,7 +75,9 @@ var topPart = func() string {
b.WriteString("</table>")
b.WriteString("<table>")
b.WriteString("<tr>")
- b.WriteString("for future reference")
+ b.WriteString(desc)
+
+ // TODO why this is creating a highlighting error on browser
b.WriteString("<hr>")
b.WriteString("<td><code style=\"background-color: #222; color: white; padding: 4px; user-select: all; border: none;\">")
@@ -64,7 +90,7 @@ var topPart = func() string {
b.WriteString("\n<div style=\"display:flex; flex-wrap:wrap; gap:30px;margin-top:3px;\">\n")
b.WriteString("\n<div style=\"display:flex;padding-left:20px;\">\n")
- b.WriteString("<a>")
+ b.WriteString("<a href=\"index.html\">")
b.WriteString("index\n")
b.WriteString("</a>")
b.WriteString("</div>\n")
@@ -84,7 +110,7 @@ var topPart = func() string {
// TODO if license exists {
if 1+1 == 2 {
b.WriteString("\n<div style=\"display:flex;\">\n")
- b.WriteString("<a>")
+ b.WriteString("<a href=\"license.html\">")
b.WriteString("license\n")
b.WriteString("</a>")
b.WriteString("</div>\n")
@@ -94,7 +120,6 @@ var topPart = func() string {
b.WriteString("\n</div>\n")
b.WriteString("<hr>")
- b.WriteString("</body>")
return b.String()
-}()
+}
diff --git a/shgit/shgit.go b/shgit/shgit.go
index 1c7be04..f008a3a 100644
--- a/shgit/shgit.go
+++ b/shgit/shgit.go
@@ -15,10 +15,6 @@ func main() {
output = os.Args[2]
}
- fmt.Println(repo)
- fmt.Println(output)
- fmt.Println(len(os.Args))
-
gitPath := filepath.Join(repo, ".git")
_, err := os.Stat(gitPath)
if err != nil {
@@ -26,12 +22,39 @@ func main() {
os.Exit(1)
}
+ topPart := genTopPart(repo)
+
+ indexPage(topPart, output)
+ licensePage(topPart, repo, output)
+}
+
+func indexPage(topPart string, output string) {
outputFile := filepath.Join(output, "index.html")
file, _ := os.Create(outputFile)
+ defer file.Close()
- file.WriteString(indexPage())
+ file.WriteString(topPart)
+ file.WriteString("<h4>Commits</h4>")
+ file.WriteString("<h4>Read Me</h4>")
+ file.WriteString("\n</body>")
}
-func indexPage() string {
- return topPart
+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>")
}
diff --git a/shindex/shindex.go b/shindex/shindex.go
index 7587e6f..02b704f 100644
--- a/shindex/shindex.go
+++ b/shindex/shindex.go
@@ -7,7 +7,7 @@ import (
"path/filepath"
"strings"
- "shroomgit/config"
+ "shroomgit/shared"
)
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 := getRepoName(repo)
+ repoName, desc := shared.GetRepoNameAndDesc(repo)
cmd := exec.Command(
"git",
"-C", repo,
@@ -34,11 +34,7 @@ func gitTable(args []string) {
"--pretty=format:%cd",
"--date=format:%Y-%m-%d",
)
- descFile := filepath.Join(repo, ".git", "description")
- desc := ""
- if data, err := os.ReadFile(descFile); err == nil {
- desc = string(data)
- }
+
lastCommit, _ := cmd.Output()
license := detectLicense(repo)
@@ -73,7 +69,7 @@ func gitTable(args []string) {
}
func basicPart() {
- config := config.Shindex
+ config := shared.Shindex
fmt.Println("<!DOCTYPE html>")
fmt.Println("<html>")
fmt.Println("<head>")
@@ -95,29 +91,6 @@ func basicPart() {
fmt.Println("<hr>")
}
-func getRepoName(repo string) string {
- gitConfig := filepath.Join(repo, ".git", "config")
- data, err := os.ReadFile(gitConfig)
- if err != nil {
- return filepath.Base(repo)
- }
-
- 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]
- }
- }
-
- return filepath.Base(repo)
-}
-
// Not very reliable, will fix later
func detectLicense(repo string) string {
files := []string{"LICENSE", "LICENSE.txt", "LICENSE.md", "license"}