commit
message
Showing files changed on log page
author
Ben Vogt <[email protected]>
date
2023-04-03 23:21:34
stats
2 file(s) changed,
39 insertions(+),
32 deletions(-)
files
log.template.html
main.go
1diff --git a/log.template.html b/log.template.html
2index 9bbe959..b77ecae 100644
3--- a/log.template.html
4+++ b/log.template.html
5@@ -63,7 +63,7 @@
6 <td>{{ .Date }}</td>
7 <td class="commit"><a href="commit/{{ .Hash }}">{{ .Message }}</a></td>
8 <td>{{ .Author }}</td>
9- <td align="right">1</td>
10+ <td align="right">{{ .FileChangeCount }}</td>
11 <td align="right">+2</td>
12 <td align="right">-0</td>
13 </tr>
14diff --git a/main.go b/main.go
15index 2430b55..58b1ad0 100644
16--- a/main.go
17+++ b/main.go
18@@ -116,16 +116,9 @@ func main() {
19 debug("clone = %v", config.CloneDir)
20 debug("base-url = %v", config.BaseURL)
21 r := CloneAndInfo()
22- BuildLogPage(r)
23- BuildFilesPages()
24- BuildSingleFilePages()
25-}
26-
27-type TrackedFileMetaData struct {
28- Mode string
29- Name string
30- Size string
31- Origin string
32+ RenderLogPage(r)
33+ RenderAllFilesPage()
34+ RenderSingleFilePages()
35 }
36
37 type TrackedFile struct {
38@@ -141,7 +134,7 @@ type TrackedFile struct {
39 Content template.HTML
40 }
41
42-func (f *TrackedFile) SaveTemplate(t *template.Template) {
43+func (f *TrackedFile) Render(t *template.Template) {
44 lexer := lexers.Match(f.DestinationDir)
45 if lexer == nil {
46 lexer = lexers.Fallback
47@@ -177,31 +170,39 @@ func (f *TrackedFile) SaveTemplate(t *template.Template) {
48 checkErr(err)
49 }
50
51-type GshrCommit struct {
52- Author string
53- Date string
54- Hash string
55- Message string
56+type Commit struct {
57+ Author string
58+ Date string
59+ Hash string
60+ Message string
61+ FileChangeCount int
62 }
63
64 type LogPage struct {
65 BaseURL string
66- Commits []GshrCommit
67+ Commits []Commit
68 }
69
70-func (mi *LogPage) SaveTemplate(t *template.Template) {
71+func (mi *LogPage) Render(t *template.Template) {
72 output, err := os.Create(path.Join(config.OutputDir, "log.html"))
73 checkErr(err)
74 err = t.Execute(output, mi)
75 checkErr(err)
76 }
77
78+type TrackedFileMetaData struct {
79+ Mode string
80+ Name string
81+ Size string
82+ Origin string
83+}
84+
85 type FilesIndex struct {
86 BaseURL string
87 Files []TrackedFileMetaData
88 }
89
90-func (fi *FilesIndex) SaveTemplate(t *template.Template) {
91+func (fi *FilesIndex) Render(t *template.Template) {
92 output, err := os.Create(path.Join(config.OutputDir, "files.html"))
93 checkErr(err)
94 err = t.Execute(output, fi)
95@@ -216,21 +217,24 @@ func CloneAndInfo() *git.Repository {
96 return r
97 }
98
99-func BuildLogPage(r *git.Repository) {
100+func RenderLogPage(r *git.Repository) {
101 t, err := template.New("log").Parse(logTemplateHtml)
102 checkErr(err)
103- commits := make([]GshrCommit, 0)
104+ commits := make([]Commit, 0)
105 ref, err := r.Head()
106 checkErr(err)
107 cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})
108 checkErr(err)
109
110 err = cIter.ForEach(func(c *object.Commit) error {
111- commits = append(commits, GshrCommit{
112- Author: c.Author.Name,
113- Message: c.Message,
114- Date: c.Author.When.UTC().Format("2006-01-02 15:04:05"),
115- Hash: c.Hash.String(),
116+ stats, err := c.Stats()
117+ checkErr(err)
118+ commits = append(commits, Commit{
119+ Author: c.Author.Name,
120+ Message: c.Message,
121+ Date: c.Author.When.UTC().Format("2006-01-02 15:04:05"),
122+ Hash: c.Hash.String(),
123+ FileChangeCount: len(stats),
124 })
125 return nil
126 })
127@@ -240,10 +244,10 @@ func BuildLogPage(r *git.Repository) {
128 BaseURL: config.BaseURL,
129 Commits: commits,
130 }
131- m.SaveTemplate(t)
132+ m.Render(t)
133 }
134
135-func BuildFilesPages() {
136+func RenderAllFilesPage() {
137 t, err := template.New("files").Parse(filesTemplateHtml)
138 checkErr(err)
139 trackedFiles := make([]TrackedFileMetaData, 0)
140@@ -272,10 +276,10 @@ func BuildFilesPages() {
141 BaseURL: config.BaseURL,
142 Files: trackedFiles,
143 }
144- index.SaveTemplate(t)
145+ index.Render(t)
146 }
147
148-func BuildSingleFilePages() {
149+func RenderSingleFilePages() {
150 t, err := template.New("file").Parse(fileTemplateHtml)
151 checkErr(err)
152 err = filepath.Walk(config.CloneDir, func(filename string, info fs.FileInfo, err error) error {
153@@ -297,7 +301,7 @@ func BuildSingleFilePages() {
154 Destination: outputName,
155 DestinationDir: path.Join(config.OutputDir, "files", partialPath),
156 }
157- tf.SaveTemplate(t)
158+ tf.Render(t)
159 }
160 return nil
161 })