commit
message
Adding name and description
author
Ben Vogt <[email protected]>
date
2023-04-04 19:15:50
stats
11 file(s) changed,
77 insertions(+),
51 deletions(-)
files
Makefile
commit.go
file.go
files.go
log.go
main.go
templates/commit.html
templates/file.html
templates/files.html
templates/log.html
templates/partials.html
1diff --git a/Makefile b/Makefile
2index 7653b76..f2c0199 100644
3--- a/Makefile
4+++ b/Makefile
5@@ -10,24 +10,29 @@ rfind=$(shell find $1 -type f -not -path "./target/*")
6 target:
7 mkdir -p target
8
9-output:
10+target/output: target
11 mkdir -p target/output
12
13-cloning:
14+target/cloning: target
15 mkdir -p target/cloning
16
17 clean:
18 rm -rf target/*
19
20-target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin:
21+target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin: Makefile target
22 go build -o target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin $(wildcard *.go)
23
24-dev: target output cloning target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin
25+dev: Makefile target target/output target/cloning target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin
26 ./target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin \
27+ --name="gshr" \
28+ --desc="git static host repo -- generates static html for repo" \
29 --repo=/Users/bvogt/dev/src/ben/gshr \
30 --output=$(PWD)/target/output \
31 --clone=$(PWD)/target/cloning \
32 && \
33 cp gshr.css $(PWD)/target/output/ && \
34 cd $(PWD)/target/output && \
35- python3 -m http.server 8000
36\ No newline at end of file
37+ python3 -m http.server 8000
38+
39+fmt:
40+ go fmt
41\ No newline at end of file
42diff --git a/commit.go b/commit.go
43index f7a2d06..8bac22d 100644
44--- a/commit.go
45+++ b/commit.go
46@@ -9,8 +9,8 @@ import (
47 "github.com/go-git/go-git/v5/plumbing/object"
48 )
49
50-type CommitDetail struct {
51- BaseURL string
52+type CommitPage struct {
53+ RepoData RepoData
54 Author string
55 AuthorEmail string
56 Date string
57@@ -21,7 +21,7 @@ type CommitDetail struct {
58 LinesDeleted int
59 }
60
61-func (c *CommitDetail) Render(t *template.Template) {
62+func (c *CommitPage) Render(t *template.Template) {
63 err := os.MkdirAll(path.Join(config.OutputDir, "commit", c.Hash), 0755)
64 checkErr(err)
65 output, err := os.Create(path.Join(config.OutputDir, "commit", c.Hash, "index.html"))
66@@ -47,8 +47,8 @@ func RenderAllCommitPages(r *git.Repository) {
67 deleted += stat.Deletion
68 }
69 checkErr(err)
70- commitDetail := CommitDetail{
71- BaseURL: config.BaseURL,
72+ (&CommitPage{
73+ RepoData: config.RepoData,
74 Author: c.Author.Name,
75 AuthorEmail: c.Author.Email,
76 Message: c.Message,
77@@ -57,8 +57,7 @@ func RenderAllCommitPages(r *git.Repository) {
78 FileChangeCount: len(stats),
79 LinesAdded: added,
80 LinesDeleted: deleted,
81- }
82- commitDetail.Render(t)
83+ }).Render(t)
84 return nil
85 })
86 checkErr(err)
87diff --git a/file.go b/file.go
88index 2845f46..14c75bf 100644
89--- a/file.go
90+++ b/file.go
91@@ -14,8 +14,8 @@ import (
92 "github.com/alecthomas/chroma/styles"
93 )
94
95-type TrackedFile struct {
96- BaseURL string
97+type FilePage struct {
98+ RepoData RepoData
99 Mode string
100 Name string
101 Size string
102@@ -27,7 +27,7 @@ type TrackedFile struct {
103 Content template.HTML
104 }
105
106-func (f *TrackedFile) Render(t *template.Template) {
107+func (f *FilePage) Render(t *template.Template) {
108 lexer := lexers.Match(f.DestinationDir)
109 if lexer == nil {
110 lexer = lexers.Fallback
111@@ -77,15 +77,14 @@ func RenderSingleFilePages() {
112 partialPath, _ := strings.CutPrefix(filename, config.CloneDir)
113 outputName := path.Join(config.OutputDir, "files", partialPath, "index.html")
114 debug("reading = %v", partialPath)
115- tf := TrackedFile{
116- BaseURL: config.BaseURL,
117+ (&FilePage{
118+ RepoData: config.RepoData,
119 Extension: ext,
120 CanRender: canRenderExtension || canRenderByFullName,
121 Origin: filename,
122 Destination: outputName,
123 DestinationDir: path.Join(config.OutputDir, "files", partialPath),
124- }
125- tf.Render(t)
126+ }).Render(t)
127 }
128 return nil
129 })
130diff --git a/files.go b/files.go
131index 613bb4c..13f3a47 100644
132--- a/files.go
133+++ b/files.go
134@@ -10,7 +10,7 @@ import (
135 "strings"
136 )
137
138-type TrackedFileMetaData struct {
139+type FileOverview struct {
140 BaseURL string
141 Mode string
142 Name string
143@@ -18,12 +18,12 @@ type TrackedFileMetaData struct {
144 Origin string
145 }
146
147-type FilesIndex struct {
148- BaseURL string
149- Files []TrackedFileMetaData
150+type FilesPage struct {
151+ RepoData RepoData
152+ Files []FileOverview
153 }
154
155-func (fi *FilesIndex) Render(t *template.Template) {
156+func (fi *FilesPage) Render(t *template.Template) {
157 output, err := os.Create(path.Join(config.OutputDir, "files.html"))
158 checkErr(err)
159 err = t.Execute(output, fi)
160@@ -33,7 +33,7 @@ func (fi *FilesIndex) Render(t *template.Template) {
161 func RenderAllFilesPage() {
162 t, err := template.ParseFS(htmlTemplates, "templates/files.html", "templates/partials.html")
163 checkErr(err)
164- trackedFiles := make([]TrackedFileMetaData, 0)
165+ files := make([]FileOverview, 0)
166 err = filepath.Walk(config.CloneDir, func(filename string, info fs.FileInfo, err error) error {
167 if info.IsDir() && info.Name() == ".git" {
168 return filepath.SkipDir
169@@ -44,21 +44,21 @@ func RenderAllFilesPage() {
170 checkErr(err)
171 Name, _ := strings.CutPrefix(filename, config.CloneDir)
172 Name, _ = strings.CutPrefix(Name, "/")
173- tf := TrackedFileMetaData{
174+ tf := FileOverview{
175 BaseURL: config.BaseURL,
176 Origin: filename,
177 Name: Name,
178 Mode: info.Mode().String(),
179 Size: fmt.Sprintf("%v", info.Size()),
180 }
181- trackedFiles = append(trackedFiles, tf)
182+ files = append(files, tf)
183 }
184 return nil
185 })
186 checkErr(err)
187- index := FilesIndex{
188- BaseURL: config.BaseURL,
189- Files: trackedFiles,
190+ index := FilesPage{
191+ RepoData: config.RepoData,
192+ Files: files,
193 }
194 index.Render(t)
195 }
196diff --git a/log.go b/log.go
197index c885902..05414df 100644
198--- a/log.go
199+++ b/log.go
200@@ -9,7 +9,7 @@ import (
201 "github.com/go-git/go-git/v5/plumbing/object"
202 )
203
204-type Commit struct {
205+type LogPageCommit struct {
206 BaseURL string
207 Author string
208 Date string
209@@ -21,8 +21,8 @@ type Commit struct {
210 }
211
212 type LogPage struct {
213- BaseURL string
214- Commits []Commit
215+ RepoData RepoData
216+ Commits []LogPageCommit
217 }
218
219 func (mi *LogPage) Render(t *template.Template) {
220@@ -35,7 +35,7 @@ func (mi *LogPage) Render(t *template.Template) {
221 func RenderLogPage(r *git.Repository) {
222 t, err := template.ParseFS(htmlTemplates, "templates/log.html", "templates/partials.html")
223 checkErr(err)
224- commits := make([]Commit, 0)
225+ commits := make([]LogPageCommit, 0)
226 ref, err := r.Head()
227 checkErr(err)
228 cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})
229@@ -51,7 +51,7 @@ func RenderLogPage(r *git.Repository) {
230 deleted += stat.Deletion
231 }
232 checkErr(err)
233- commits = append(commits, Commit{
234+ commits = append(commits, LogPageCommit{
235 BaseURL: config.BaseURL,
236 Author: c.Author.Name,
237 Message: c.Message,
238@@ -65,9 +65,8 @@ func RenderLogPage(r *git.Repository) {
239 })
240
241 checkErr(err)
242- m := LogPage{
243- BaseURL: config.BaseURL,
244- Commits: commits,
245- }
246- m.Render(t)
247+ (&LogPage{
248+ RepoData: config.RepoData,
249+ Commits: commits,
250+ }).Render(t)
251 }
252diff --git a/main.go b/main.go
253index 54fdc37..0ce88a2 100644
254--- a/main.go
255+++ b/main.go
256@@ -24,6 +24,7 @@ type Config struct {
257 OutputDir string
258 CloneDir string
259 BaseURL string
260+ RepoData RepoData
261 TextExtensions map[string]bool
262 PlainFiles map[string]bool
263 }
264@@ -35,6 +36,11 @@ func DefaultConfig() Config {
265 OutputDir: "",
266 BaseURL: "/",
267 CloneDir: "",
268+ RepoData: RepoData{
269+ Name: "",
270+ Description: "",
271+ BaseURL: "/",
272+ },
273 TextExtensions: map[string]bool{
274 ".c": true,
275 ".cc": true,
276@@ -88,13 +94,21 @@ func DefaultConfig() Config {
277 }
278 }
279
280+type RepoData struct {
281+ Name string
282+ Description string
283+ BaseURL string
284+}
285+
286 func main() {
287 config = DefaultConfig()
288 flag.StringVar(&config.Repo, "repo", "", "Repo to use.")
289 flag.BoolVar(&config.DebugOn, "debug", true, "Run in debug mode.")
290 flag.StringVar(&config.OutputDir, "output", "", "Dir of output.")
291 flag.StringVar(&config.CloneDir, "clone", "", "Directory to clone into. Defaults to /tmp/${rand}")
292- flag.StringVar(&config.BaseURL, "base-url", "/", "Base URL for loading styles.")
293+ flag.StringVar(&config.BaseURL, "base-url", "/", "Base URL for serving.")
294+ flag.StringVar(&config.RepoData.Name, "name", "untitled repo", "Name for display")
295+ flag.StringVar(&config.RepoData.Description, "desc", "untitled repo", "Description for display")
296 flag.Parse()
297
298 if config.Repo == "" {
299@@ -106,6 +120,7 @@ func main() {
300 }
301
302 config.BaseURL = path.Join(config.BaseURL, "/")
303+ config.RepoData.BaseURL = config.BaseURL
304
305 debug("repo = %v", config.Repo)
306 debug("output = %v", config.OutputDir)
307diff --git a/templates/commit.html b/templates/commit.html
308index 6b3ae7c..215874d 100644
309--- a/templates/commit.html
310+++ b/templates/commit.html
311@@ -2,18 +2,22 @@
312 <html lang="en">
313
314 <head>
315- {{ template "head" . }}
316+ {{ template "head" .RepoData }}
317 </head>
318
319 <body>
320 <div class="content">
321- {{ template "metadata" . }}
322+ {{ template "metadata" .RepoData }}
323 <div class="commit-detail">
324 <table>
325 <tbody>
326 <tr>
327 <td><b>commit: </b></td>
328- <td><a href="{{ .BaseURL }}commit/{{ .Hash }}/">{{ .Hash }}</a></td>
329+ <td>
330+ <a href="{{ .RepoData.BaseURL }}commit/{{ .Hash }}/">
331+ {{ .Hash }}
332+ </a>
333+ </td>
334 </tr>
335 <tr>
336 <td><b>author: </b></td>
337diff --git a/templates/file.html b/templates/file.html
338index 7a44c82..894f450 100644
339--- a/templates/file.html
340+++ b/templates/file.html
341@@ -2,12 +2,12 @@
342 <html lang="en">
343
344 <head>
345- {{ template "head" . }}
346+ {{ template "head" .RepoData }}
347 </head>
348
349 <body>
350 <div class="content">
351- {{ template "metadata" . }}
352+ {{ template "metadata" .RepoData }}
353 <div class="file">
354 {{ if .CanRender }}
355 {{ .Content }}
356diff --git a/templates/files.html b/templates/files.html
357index ede8744..e19225d 100644
358--- a/templates/files.html
359+++ b/templates/files.html
360@@ -2,12 +2,12 @@
361 <html lang="en">
362
363 <head>
364- {{ template "head" . }}
365+ {{ template "head" .RepoData }}
366 </head>
367
368 <body>
369 <div class="content">
370- {{ template "metadata" . }}
371+ {{ template "metadata" .RepoData }}
372 <div class="files">
373 <table>
374 <thead>
375@@ -21,7 +21,11 @@
376 {{ range .Files }}
377 <tr>
378 <td>{{ .Mode }}</td>
379- <td><a href="{{ .BaseURL }}files/{{ .Name }}/index.html">{{ .Name }}</a></td>
380+ <td>
381+ <a href="{{ .BaseURL }}files/{{ .Name }}/index.html">
382+ {{ .Name }}
383+ </a>
384+ </td>
385 <td>{{ .Size }}</td>
386 </tr>
387 {{ end }}
388diff --git a/templates/log.html b/templates/log.html
389index 0954939..a2d5c75 100644
390--- a/templates/log.html
391+++ b/templates/log.html
392@@ -2,12 +2,12 @@
393 <html lang="en">
394
395 <head>
396- {{ template "head" . }}
397+ {{ template "head" .RepoData }}
398 </head>
399
400 <body>
401 <div class="content">
402- {{ template "metadata" . }}
403+ {{ template "metadata" .RepoData }}
404 <div class="log">
405 <table>
406 <thead>
407diff --git a/templates/partials.html b/templates/partials.html
408index 5a2191a..901b147 100644
409--- a/templates/partials.html
410+++ b/templates/partials.html
411@@ -19,9 +19,9 @@
412 <tbody>
413 <tr>
414 <td>
415- <h1>www</h1>
416+ <h1>{{ .Name }}</h1>
417 <span class="desc">
418- personal website hosted at https:://www.vogt.world/
419+ {{ .Description }}
420 </span>
421 </td>
422 </tr>