gshr
git static host repo -- generates static html for repos
git clone https://git.vogt.world/gshr.git
Log | Files | README.md | LICENSE
← Commit log
commit
message
Fixing some templating issues
author
Ben Vogt <[email protected]>
date
2023-04-04 19:31:59
stats
6 file(s) changed, 19 insertions(+), 27 deletions(-)
files
Makefile
files.go
log.go
main.go
templates/files.html
templates/log.html
  1diff --git a/Makefile b/Makefile
  2index b6bc35d..3ebed4c 100644
  3--- a/Makefile
  4+++ b/Makefile
  5@@ -19,7 +19,7 @@ target/cloning: target
  6 clean:
  7 	rm -rf target/*
  8 
  9-target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin: Makefile target
 10+target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin: Makefile target $(wildcard *.go)
 11 	go build -o target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin $(wildcard *.go)
 12 
 13 dev: Makefile target target/output target/cloning target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin
 14@@ -27,7 +27,7 @@ dev: Makefile target target/output target/cloning target/gshr-${OS}-${ARCH}-${EN
 15     --name="gshr" \
 16     --desc="git static host repo -- generates static html for repo" \
 17     --repo=/Users/bvogt/dev/src/ben/gshr \
 18-    --git-url="[email protected]:./gshr.git" \
 19+    --git-url="[email protected]:vogtb/gshr.git" \
 20     --output=$(PWD)/target/output \
 21     --clone=$(PWD)/target/cloning \
 22 		&& \
 23diff --git a/files.go b/files.go
 24index 13f3a47..57ee8dc 100644
 25--- a/files.go
 26+++ b/files.go
 27@@ -11,11 +11,10 @@ import (
 28 )
 29 
 30 type FileOverview struct {
 31-	BaseURL string
 32-	Mode    string
 33-	Name    string
 34-	Size    string
 35-	Origin  string
 36+	Mode   string
 37+	Name   string
 38+	Size   string
 39+	Origin string
 40 }
 41 
 42 type FilesPage struct {
 43@@ -45,11 +44,10 @@ func RenderAllFilesPage() {
 44 			Name, _ := strings.CutPrefix(filename, config.CloneDir)
 45 			Name, _ = strings.CutPrefix(Name, "/")
 46 			tf := FileOverview{
 47-				BaseURL: config.BaseURL,
 48-				Origin:  filename,
 49-				Name:    Name,
 50-				Mode:    info.Mode().String(),
 51-				Size:    fmt.Sprintf("%v", info.Size()),
 52+				Origin: filename,
 53+				Name:   Name,
 54+				Mode:   info.Mode().String(),
 55+				Size:   fmt.Sprintf("%v", info.Size()),
 56 			}
 57 			files = append(files, tf)
 58 		}
 59diff --git a/log.go b/log.go
 60index 05414df..6d3088d 100644
 61--- a/log.go
 62+++ b/log.go
 63@@ -10,7 +10,6 @@ import (
 64 )
 65 
 66 type LogPageCommit struct {
 67-	BaseURL         string
 68 	Author          string
 69 	Date            string
 70 	Hash            string
 71@@ -52,7 +51,6 @@ func RenderLogPage(r *git.Repository) {
 72 		}
 73 		checkErr(err)
 74 		commits = append(commits, LogPageCommit{
 75-			BaseURL:         config.BaseURL,
 76 			Author:          c.Author.Name,
 77 			Message:         c.Message,
 78 			Date:            c.Author.When.UTC().Format("2006-01-02 15:04:05"),
 79diff --git a/main.go b/main.go
 80index 7b8f8b5..5647f56 100644
 81--- a/main.go
 82+++ b/main.go
 83@@ -34,7 +34,6 @@ func DefaultConfig() Config {
 84 		DebugOn:   true,
 85 		Repo:      "",
 86 		OutputDir: "",
 87-		BaseURL:   "/",
 88 		CloneDir:  "",
 89 		RepoData: RepoData{
 90 			Name:        "",
 91@@ -107,7 +106,7 @@ func main() {
 92 	flag.BoolVar(&config.DebugOn, "debug", true, "Run in debug mode.")
 93 	flag.StringVar(&config.OutputDir, "output", "", "Dir of output.")
 94 	flag.StringVar(&config.CloneDir, "clone", "", "Directory to clone into. Defaults to /tmp/${rand}")
 95-	flag.StringVar(&config.BaseURL, "base-url", "/", "Base URL for serving.")
 96+	flag.StringVar(&config.RepoData.BaseURL, "base-url", "/", "Base URL for serving.")
 97 	flag.StringVar(&config.RepoData.GitURL, "git-url", "", "Show where repo is hosted.")
 98 	flag.StringVar(&config.RepoData.Name, "name", "untitled repo", "Name for display")
 99 	flag.StringVar(&config.RepoData.Description, "desc", "untitled repo", "Description for display")
100@@ -121,8 +120,7 @@ func main() {
101 		config.CloneDir = fmt.Sprintf("/tmp/gshr-temp-clone-%v", rand.Uint32())
102 	}
103 
104-	config.BaseURL = path.Join(config.BaseURL, "/")
105-	config.RepoData.BaseURL = config.BaseURL
106+	config.RepoData.BaseURL = path.Join(config.RepoData.BaseURL, "/")
107 
108 	debug("repo = %v", config.Repo)
109 	debug("output = %v", config.OutputDir)
110diff --git a/templates/files.html b/templates/files.html
111index e19225d..1d98b3b 100644
112--- a/templates/files.html
113+++ b/templates/files.html
114@@ -22,7 +22,7 @@
115           <tr>
116             <td>{{ .Mode }}</td>
117             <td>
118-              <a href="{{ .BaseURL }}files/{{ .Name }}/index.html">
119+              <a href="{{ $.RepoData.BaseURL }}files/{{ .Name }}/index.html">
120                 {{ .Name }}
121               </a>
122             </td>
123diff --git a/templates/log.html b/templates/log.html
124index a2d5c75..1a4cc46 100644
125--- a/templates/log.html
126+++ b/templates/log.html
127@@ -21,16 +21,16 @@
128           </tr>
129         </thead>
130         <tbody>
131-          {{ range $c := .Commits }}
132+          {{ range .Commits }}
133           <tr>
134-            <td>{{ $c.Date }}</td>
135+            <td>{{ .Date }}</td>
136             <td class="commit">
137-              <a href="{{ .BaseURL }}commit/{{ $c.Hash }}">{{ $c.Message }}</a>
138+              <a href="{{ $.RepoData.BaseURL }}commit/{{ .Hash }}">{{ .Message }}</a>
139             </td>
140-            <td>{{ $c.Author }}</td>
141-            <td align="right">{{ $c.FileChangeCount }}</td>
142-            <td align="right">+{{ $c.LinesAdded }}</td>
143-            <td align="right">-{{ $c.LinesDeleted }}</td>
144+            <td>{{ .Author }}</td>
145+            <td align="right">{{ .FileChangeCount }}</td>
146+            <td align="right">+{{ .LinesAdded }}</td>
147+            <td align="right">-{{ .LinesDeleted }}</td>
148           </tr>
149           {{ end }}
150         </tbody>