- commit
- befe10e
- parent
- 002fb3a
- author
- Eric Bower
- date
- 2023-06-19 04:08:50 +0000 UTC
refactor: html links mostly working
10 files changed,
+135,
-105
+3,
-1
1@@ -12,6 +12,8 @@
2
3 <link rel="stylesheet" href="/main.css" />
4 </head>
5- <body>{{template "content" .}}</body>
6+ <body>
7+ {{template "content" .}}
8+ </body>
9 </html>
10 {{end}}
+48,
-47
1@@ -1,49 +1,50 @@
2-{{- template "base" . -}}
3+{{template "base" .}}
4 {{define "title"}}commit log{{end}}
5
6-{{- define "content"}}
7-
8-<dl>
9- <dt>commit</dt>
10- <dd><a href="{{.Data.CommitURL}}">{{.Data.Commit.ID}}</a></dd>
11-
12- <dt>parent</dt>
13- <dd><a href="{{.Data.ParentURL}}">parent {{.Data.Parent}}</a></dd>
14-
15- <dt>author</dt>
16- <dd>{{.Data.Commit.Author.Name}}</dd>
17-
18- <dt>date</dt>
19- <dd>{{.Data.Commit.Author.When}}</dd>
20-</dl>
21-
22-<p>
23-{{.Data.Commit.Message}}
24-</p>
25-
26-<p>
27- <strong>{{.Data.Diff.NumFiles}}</strong> files changed,
28- <span class="color-green">+{{.Data.Diff.TotalAdditions}}</span>,
29- <span class="color-red">-{{.Data.Diff.TotalDeletions}}</span>
30-</p>
31-
32-{{range .Data.Diff.Files}}
33-
34-<p>
35- {{.OldMode}} {{.OldName}} => {{.Mode}} {{.Name}}
36-</p>
37-
38-<div>
39- <span class="color-green">+{{.NumAdditions}}</span>,
40- <span class="color-red">-{{.NumDeletions}}</span>
41-</div>
42-
43-<pre>
44-{{- range .Sections}}
45-{{- range .Lines}}
46-{{.Content}}
47-{{- end}}
48-{{- end}}
49-</pre>
50-{{- end}}
51-{{- end }}
52+{{define "content"}}
53+ {{template "header" .}}
54+
55+ <dl>
56+ <dt>commit</dt>
57+ <dd><a href="{{.Data.CommitURL}}">{{.Data.Commit.ID}}</a></dd>
58+
59+ <dt>parent</dt>
60+ <dd><a href="{{.Data.ParentURL}}">parent {{.Data.Parent}}</a></dd>
61+
62+ <dt>author</dt>
63+ <dd>{{.Data.Commit.Author.Name}}</dd>
64+
65+ <dt>date</dt>
66+ <dd>{{.Data.Commit.Author.When}}</dd>
67+ </dl>
68+
69+ <p>
70+ {{.Data.Commit.Message}}
71+ </p>
72+
73+ <p>
74+ <strong>{{.Data.Diff.NumFiles}}</strong> files changed,
75+ <span class="color-green">+{{.Data.Diff.TotalAdditions}}</span>,
76+ <span class="color-red">-{{.Data.Diff.TotalDeletions}}</span>
77+ </p>
78+
79+ {{range .Data.Diff.Files}}
80+
81+ <p>
82+ {{.OldMode}} {{.OldName}} => {{.Mode}} {{.Name}}
83+ </p>
84+
85+ <div>
86+ <span class="color-green">+{{.NumAdditions}}</span>,
87+ <span class="color-red">-{{.NumDeletions}}</span>
88+ </div>
89+
90+ <pre>
91+ {{range .Sections}}
92+ {{range .Lines}}
93+ {{.Content}}
94+ {{end}}
95+ {{end}}
96+ </pre>
97+ {{end}}
98+{{end}}
+7,
-7
1@@ -1,10 +1,10 @@
2-{{- template "base" . -}}
3+{{template "base" .}}
4 {{define "title"}}file{{end}}
5
6-{{- define "content"}}
7-<h1>{{.Name}}</h1>
8+{{define "content"}}
9+ {{template "header" .}}
10
11-<pre>
12-{{.Data.Contents}}
13-</pre>
14-{{- end }}
15+ <h1>{{.Name}}</h1>
16+
17+ <pre>{{.Data.Contents}}</pre>
18+{{end }}
+6,
-3
1@@ -1,5 +1,8 @@
2-{{- define "header" -}}
3-<h1>{{.RepoName}}</h1>
4+{{define "header"}}
5+<h1>
6+ <a href="/">repos</a>
7+ <span> / {{.RepoName}}</span>
8+</h1>
9
10 <div>
11 <a href="{{.Repo.SummaryURL}}">summary</a> |
12@@ -11,4 +14,4 @@
13 <p>git clone {{.Repo.CloneURL}}</p>
14
15 <hr />
16-{{end -}}
17+{{end}}
+9,
-7
1@@ -1,10 +1,12 @@
2-{{- template "base" . -}}
3+{{template "base" .}}
4
5 {{define "title"}}index{{end}}
6
7-{{- define "content" -}}
8-<h1>repos</h1>
9-{{- range .RepoList}}
10-<a href="{{.URL}}">{{.Name}}</a>
11-{{- end}}
12-{{- end -}}
13+{{define "content"}}
14+ <h1>repos</h1>
15+ {{range .RepoList}}
16+ <div>
17+ <a href="{{.URL}}">{{.Name}}</a>
18+ </div>
19+ {{end}}
20+{{end}}
+10,
-8
1@@ -1,11 +1,13 @@
2-{{- template "base" . -}}
3+{{template "base" .}}
4
5 {{define "title"}}log{{end}}
6
7-{{- define "content" -}}
8-{{- range .Data.Log}}
9-<p>
10-{{.Author.When}} <a href="{{.URL}}">{{.Summary}}</a> {{.Author.Name}}
11-</p>
12-{{- end}}
13-{{- end -}}
14+{{define "content"}}
15+ {{template "header" .}}
16+
17+ {{range .Data.Log}}
18+ <p>
19+ {{.Author.When}} <a href="{{.URL}}">{{.Summary}}</a> {{.Author.Name}}
20+ </p>
21+ {{end}}
22+{{end}}
+14,
-12
1@@ -1,15 +1,17 @@
2-{{- template "base" . -}}
3+{{template "base" .}}
4
5 {{define "title"}}refs{{end}}
6
7-{{- define "content"}}
8-<h2>branches</h2>
9-{{- range .Data.Branches}}
10-<p>{{.Refspec}}</p>
11-{{- end}}
12-
13-<h2>tags</h2>
14-{{- range .Data.Tags}}
15-<p>{{.Refspec}}</p>
16-{{- end}}
17-{{- end -}}
18+{{define "content"}}
19+ {{template "header" .}}
20+
21+ <h2>branches</h2>
22+ {{range .Data.Branches}}
23+ <p>{{.Refspec}}</p>
24+ {{end}}
25+
26+ <h2>tags</h2>
27+ {{range .Data.Tags}}
28+ <p>{{.Refspec}}</p>
29+ {{end}}
30+{{end}}
+5,
-4
1@@ -1,7 +1,8 @@
2-{{- template "base" . -}}
3+{{template "base" .}}
4
5 {{define "title"}}summary{{end}}
6
7-{{- define "content" -}}
8-<p>{{.Data.Readme}}</p>
9-{{- end -}}
10+{{define "content"}}
11+ {{template "header" .}}
12+ <p>{{.Data.Readme}}</p>
13+{{end}}
+11,
-6
1@@ -1,9 +1,14 @@
2-{{- template "base" . -}}
3+{{template "base" .}}
4
5-{{define "title"}}summary{{end}}
6+{{define "title"}}tree{{end}}
7
8 {{define "content"}}
9-{{- range .Data.Tree}}
10-<p>{{.URL}} {{.Path}} {{.NumLines}}</p>
11-{{- end}}
12-{{- end -}}
13+ {{template "header" .}}
14+
15+ {{range .Data.Tree}}
16+ <div>
17+ <a href="{{.URL}}">{{.Path}}</a>
18+ <span> (lines: {{.NumLines}})</span>
19+ </div>
20+ {{end}}
21+{{end}}
M
main.go
+22,
-10
1@@ -63,16 +63,13 @@ type CommitPageData struct {
2 CommitURL string
3 }
4
5-type WriteFile struct {
6- Repo *RepoData
7-}
8-
9 type WriteData struct {
10 Name string
11 Template string
12 Data interface{}
13 RepoName string
14 Subdir string
15+ Repo *RepoData
16 }
17
18 func bail(err error) {
19@@ -136,13 +133,13 @@ func writeHtml(data *WriteData) {
20 bail(err)
21
22 outdir := viper.GetString("outdir")
23- dir := path.Join(outdir, "html", data.RepoName, data.Subdir)
24+ dir := path.Join(outdir, data.RepoName, data.Subdir)
25 fmt.Println(dir)
26 fmt.Println(data.Name)
27 err = os.MkdirAll(dir, os.ModePerm)
28 bail(err)
29
30- w, err := os.OpenFile(path.Join(dir, data.Name), os.O_WRONLY|os.O_CREATE, 0600)
31+ w, err := os.OpenFile(path.Join(dir, data.Name), os.O_WRONLY|os.O_CREATE, 0755)
32 bail(err)
33
34 err = ts.Execute(w, data)
35@@ -166,7 +163,7 @@ func writeIndex(data *IndexPage) {
36 err = os.MkdirAll(dir, os.ModePerm)
37 bail(err)
38
39- w, err := os.OpenFile(path.Join(dir, "index.html"), os.O_WRONLY|os.O_CREATE, 0600)
40+ w, err := os.OpenFile(path.Join(dir, "index.html"), os.O_WRONLY|os.O_CREATE, 0755)
41 bail(err)
42
43 err = ts.Execute(w, data)
44@@ -178,6 +175,7 @@ func writeSummary(data *PageData) {
45 Template: "./html/summary.page.tmpl",
46 Data: data,
47 RepoName: data.Repo.Name,
48+ Repo: data.Repo,
49 })
50 }
51 func writeTree(data *PageData) {
52@@ -186,6 +184,7 @@ func writeTree(data *PageData) {
53 Template: "./html/tree.page.tmpl",
54 Data: data,
55 RepoName: data.Repo.Name,
56+ Repo: data.Repo,
57 })
58 }
59 func writeLog(data *PageData) {
60@@ -194,6 +193,7 @@ func writeLog(data *PageData) {
61 Template: "./html/log.page.tmpl",
62 Data: data,
63 RepoName: data.Repo.Name,
64+ Repo: data.Repo,
65 })
66 }
67 func writeRefs(data *PageData) {
68@@ -202,6 +202,7 @@ func writeRefs(data *PageData) {
69 Template: "./html/refs.page.tmpl",
70 Data: data,
71 RepoName: data.Repo.Name,
72+ Repo: data.Repo,
73 })
74 }
75
76@@ -222,6 +223,7 @@ func writeHTMLTreeFiles(data *PageData) {
77 Data: &FileData{Contents: string(b)},
78 RepoName: data.Repo.Name,
79 Subdir: path.Join("tree", data.RevName, d),
80+ Repo: data.Repo,
81 })
82 }
83 }
84@@ -277,6 +279,7 @@ func writeLogDiffs(project string, repo *git.Repository, data *PageData, cache m
85 Data: commitData,
86 RepoName: data.Repo.Name,
87 Subdir: "commits",
88+ Repo: data.Repo,
89 })
90 lastCommit = commit
91 }
92@@ -302,7 +305,9 @@ func writeRepo(root string) {
93 tags, _ := repo.ShowRef(git.ShowRefOptions{Heads: false, Tags: true})
94
95 cache := make(map[string]bool)
96- for _, rev := range heads {
97+ rev := findDefaultBranch(heads)
98+ if rev != nil {
99+ // for _, rev := range heads {
100 _, revName := path.Split(rev.Refspec)
101 data := &PageData{
102 Branches: heads,
103@@ -334,7 +339,14 @@ func writeBranch(repo *git.Repository, pageData *PageData, cache map[string]bool
104 entries := []*TreeItem{}
105 treeEntries := walkTree(tree, pageData.RevName, "", entries)
106 for _, entry := range treeEntries {
107- entry.URL = path.Join("/", pageData.Repo.Name, "tree", pageData.RevName, entry.Path)
108+ entry.Path = strings.TrimPrefix(entry.Path, "/")
109+ entry.URL = path.Join(
110+ "/",
111+ pageData.Repo.Name,
112+ "tree",
113+ pageData.RevName,
114+ fmt.Sprintf("%s.html", entry.Path),
115+ )
116 }
117
118 pageData.Log = logs
119@@ -367,7 +379,7 @@ func main() {
120 name := repoName(r)
121 url := path.Join("/", name, "index.html")
122 repoList = append(repoList, &RepoItemData{
123- URL: url,
124+ URL: url,
125 Name: name,
126 })
127 }