Commit 134e2ae

Eric Bower  ·  2023-08-07 09:47:05 -0400 EDT
parent fe38cd8
copy changes
6 files changed,  +148, -141
+4, -0
......@@ -9,3 +9,7 @@ repos:
99 refs:
1010 - main
1111 desc: infra for pico services
12+ - path: /home/erock/dev/app-ui
13+ refs:
14+ - main
15+ desc: aptible's paas web application
+1, -1
......@@ -12,7 +12,7 @@
1212 <a href="{{.Repo.LogURL}}">log</a>
1313 </div>
1414
15-<div class="my">
15+<div class="mt-lg">
1616 <div class="text-lg">{{.Repo.Desc}}</div>
1717 <pre style="margin: 0;">git clone {{.Repo.CloneURL}}</pre>
1818 </div>
+9, -3
......@@ -8,10 +8,16 @@
88 <div>
99 {{range .Data.Log}}
1010 <div class="box">
11- <div>
12- <a href="{{.URL}}">{{.SummaryStr}}</a>
11+ <div class="flex justify-between items-center">
12+ <div>
13+ <a href="{{.URL}}">{{.SummaryStr}}</a>
14+ </div>
15+ <div>
16+ {{.ShortID}}
17+ </div>
1318 </div>
14- <div>
19+
20+ <div class="flex items-center">
1521 <span>{{.AuthorStr}}</span>
1622 <span>&nbsp;committed&nbsp;</span>
1723 <span>{{.WhenStr}}</span>
+6, -6
......@@ -7,17 +7,17 @@
77
88 <div>
99 {{range .Data.Tree}}
10- <div class="flex justify-between">
10+ <div class="flex justify-between items-center gap my-sm border-b">
1111 <div class="flex-1">
1212 <a href="{{.URL}}">{{.Path}}</a>
1313 </div>
1414
15- <div class="flex">
16- <div>
17- <a href="{{.CommitURL}}">{{.When}}</a>
15+ <div class="flex items-center gap">
16+ <div class="flex-1">
17+ <a href="{{.CommitURL}}" title="{{.Summary}}">{{.When}}</a>
1818 </div>
19- <div class="mono font-bold">
20- L{{.NumLines}}
19+ <div class="tree-size">
20+ {{if .IsTextFile}}{{.NumLines}} L{{else}}{{.Size}}{{end}}
2121 </div>
2222 </div>
2323 </div>
+101, -64
......@@ -9,9 +9,11 @@ import (
99 "sort"
1010 "strings"
1111
12+ "github.com/dustin/go-humanize"
1213 git "github.com/gogs/git-module"
1314 "github.com/mergestat/timediff"
1415 "github.com/picosh/pico/pastes"
16+ "github.com/picosh/pico/shared"
1517 "github.com/spf13/viper"
1618 )
1719
......@@ -38,35 +40,39 @@ type RepoData struct {
3840 RefsURL string
3941 CloneURL string
4042 MaxCommits int
41- RevName string
43+ RevName string
44+ Readme string
4245 }
4346
4447 type CommitData struct {
4548 SummaryStr string
46- URL string
47- WhenStr string
48- AuthorStr string
49+ URL string
50+ WhenStr string
51+ AuthorStr string
52+ ShortID string
4953 *git.Commit
5054 }
5155
5256 type TreeItem struct {
53- NumLines int
54- URL string
55- Path string
56- Entry *git.TreeEntry
57- CommitURL string
58- Desc string
59- When string
57+ IsTextFile bool
58+ Size string
59+ NumLines int
60+ URL string
61+ Path string
62+ Entry *git.TreeEntry
63+ CommitURL string
64+ Summary string
65+ When string
6066 }
6167
6268 type PageData struct {
63- Repo *RepoData
64- Log []*CommitData
65- Tree []*TreeItem
66- Readme template.HTML
67- Rev *git.Reference
68- RevName string
69- Refs []*RefInfo
69+ Repo *RepoData
70+ Log []*CommitData
71+ Tree []*TreeItem
72+ Readme template.HTML
73+ Rev *git.Reference
74+ RevName string
75+ Refs []*RefInfo
7076 }
7177
7278 type CommitPageData struct {
......@@ -107,6 +113,35 @@ type DiffRenderFile struct {
107113 NumDeletions int
108114 }
109115
116+type FileData struct {
117+ Contents template.HTML
118+ Name string
119+}
120+
121+type RefInfo struct {
122+ Refspec string
123+ URL template.URL
124+}
125+
126+type BranchOutput struct {
127+ Readme string
128+ LastCommit *git.Commit
129+}
130+
131+type RepoConfig struct {
132+ Path string `mapstructure:"path"`
133+ Refs []string `mapstructure:"refs"`
134+ Desc string `mapstructure:"desc"`
135+ MaxCommits int `mapstructure:"max_commits"`
136+ Readme string `mapstructure:"readme"`
137+}
138+
139+type Config struct {
140+ Repos []*RepoConfig `mapstructure:"repos"`
141+ URL string `mapstructure:"url"`
142+ Cache map[string]bool
143+}
144+
110145 func diffFileType(_type git.DiffFileType) string {
111146 if _type == git.DiffFileAdd {
112147 return "A"
......@@ -127,6 +162,10 @@ func bail(err error) {
127162 }
128163 }
129164
165+func toPretty(b int64) string {
166+ return humanize.Bytes(uint64(b))
167+}
168+
130169 func commitURL(repo string, commitID string) string {
131170 return fmt.Sprintf("/%s/commits/%s.html", repo, commitID)
132171 }
......@@ -135,6 +174,15 @@ func repoName(root string) string {
135174 _, file := filepath.Split(root)
136175 return file
137176 }
177+
178+func readmeFile(repo *RepoData) string {
179+ if repo.Readme == "" {
180+ return "readme.md"
181+ }
182+
183+ return strings.ToLower(repo.Readme)
184+}
185+
138186 func findDefaultBranch(config *RepoConfig, refs []*git.Reference) *git.Reference {
139187 branches := config.Refs
140188 if len(branches) == 0 {
......@@ -165,6 +213,7 @@ func walkTree(tree *git.Tree, branch string, curpath string, aggregate []*TreeIt
165213
166214 if entry.IsBlob() {
167215 aggregate = append(aggregate, &TreeItem{
216+ Size: toPretty(entry.Size()),
168217 Path: fname,
169218 Entry: entry,
170219 URL: filepath.Join("/", "tree", branch, "item", fname),
......@@ -188,12 +237,13 @@ func writeHtml(data *WriteData) {
188237
189238 outdir := viper.GetString("outdir")
190239 dir := filepath.Join(outdir, data.RepoName, data.Subdir)
191- fmt.Println(dir)
192- fmt.Println(data.Name)
193240 err = os.MkdirAll(dir, os.ModePerm)
194241 bail(err)
195242
196- w, err := os.OpenFile(filepath.Join(dir, data.Name), os.O_WRONLY|os.O_CREATE, 0755)
243+ fp := filepath.Join(dir, data.Name)
244+ fmt.Printf("writing (%s)\n", fp)
245+
246+ w, err := os.OpenFile(fp, os.O_WRONLY|os.O_CREATE, 0755)
197247 bail(err)
198248
199249 err = ts.Execute(w, data)
......@@ -213,11 +263,13 @@ func writeIndex(data *IndexPage) {
213263
214264 outdir := viper.GetString("outdir")
215265 dir := filepath.Join(outdir)
216- fmt.Println(dir)
217266 err = os.MkdirAll(dir, os.ModePerm)
218267 bail(err)
219268
220- w, err := os.OpenFile(filepath.Join(dir, "index.html"), os.O_WRONLY|os.O_CREATE, 0755)
269+ fp := filepath.Join(dir, "index.html")
270+ fmt.Printf("writing (%s)\n", fp)
271+
272+ w, err := os.OpenFile(fp, os.O_WRONLY|os.O_CREATE, 0755)
221273 bail(err)
222274
223275 err = ts.Execute(w, data)
......@@ -264,30 +316,36 @@ func writeRefs(data *PageData) {
264316 })
265317 }
266318
267-type FileData struct {
268- Contents template.HTML
269-}
270-
271319 func writeHTMLTreeFiles(data *PageData) string {
272320 readme := ""
273321 for _, file := range data.Tree {
274322 b, err := file.Entry.Blob().Bytes()
275323 bail(err)
276- file.NumLines = len(strings.Split(string(b), "\n"))
324+ str := string(b)
325+
326+ file.IsTextFile = shared.IsTextFile(str)
327+
328+ if file.IsTextFile {
329+ file.NumLines = len(strings.Split(str, "\n"))
330+ }
277331
278332 d := filepath.Dir(file.Path)
279333 contents, err := pastes.ParseText(file.Entry.Name(), string(b))
280334 bail(err)
281335
282336 nameLower := strings.ToLower(file.Entry.Name())
283- if nameLower == "readme.md" {
337+ summary := readmeFile(data.Repo)
338+ if nameLower == summary {
284339 readme = contents
285340 }
286341
287342 writeHtml(&WriteData{
288343 Name: fmt.Sprintf("%s.html", file.Entry.Name()),
289344 Template: "./html/file.page.tmpl",
290- Data: &FileData{Contents: template.HTML(contents)},
345+ Data: &FileData{
346+ Contents: template.HTML(contents),
347+ Name: file.Entry.Name(),
348+ },
291349 RepoName: data.Repo.Name,
292350 Subdir: filepath.Join("tree", data.RevName, "item", d),
293351 Repo: data.Repo,
......@@ -381,11 +439,6 @@ func (c *Config) writeLogDiffs(repo *git.Repository, pageData *PageData) {
381439 }
382440 }
383441
384-type RefInfo struct {
385- Refspec string
386- URL template.URL
387-}
388-
389442 func (c *Config) writeRepo(config *RepoConfig) *BranchOutput {
390443 repo, err := git.Open(config.Path)
391444 bail(err)
......@@ -410,7 +463,7 @@ func (c *Config) writeRepo(config *RepoConfig) *BranchOutput {
410463 LogURL: fmt.Sprintf("/%s/logs/%s/index.html", name, revName),
411464 RefsURL: fmt.Sprintf("/%s/refs.html", name),
412465 CloneURL: fmt.Sprintf("https://%s/%s.git", c.URL, name),
413- RevName: revName,
466+ RevName: revName,
414467 }
415468
416469 refInfoMap := map[string]*RefInfo{}
......@@ -436,7 +489,7 @@ func (c *Config) writeRepo(config *RepoConfig) *BranchOutput {
436489 LogURL: fmt.Sprintf("/%s/logs/%s/index.html", name, revn),
437490 RefsURL: fmt.Sprintf("/%s/refs.html", name),
438491 CloneURL: fmt.Sprintf("https://%s/%s.git", c.URL, name),
439- RevName: revn,
492+ RevName: revn,
440493 }
441494
442495 data := &PageData{
......@@ -479,22 +532,17 @@ func (c *Config) writeRepo(config *RepoConfig) *BranchOutput {
479532 })
480533
481534 data := &PageData{
482- Rev: rev,
483- RevName: revName,
484- Repo: repoData,
485- Readme: template.HTML(mainOutput.Readme),
486- Refs: refInfoList,
535+ Rev: rev,
536+ RevName: revName,
537+ Repo: repoData,
538+ Readme: template.HTML(mainOutput.Readme),
539+ Refs: refInfoList,
487540 }
488541 writeRefs(data)
489542 writeRootSummary(data)
490543 return mainOutput
491544 }
492545
493-type BranchOutput struct {
494- Readme string
495- LastCommit *git.Commit
496-}
497-
498546 func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOutput {
499547 output := &BranchOutput{}
500548 pageSize := pageData.Repo.MaxCommits
......@@ -512,11 +560,12 @@ func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOu
512560 }
513561
514562 logs = append(logs, &CommitData{
515- URL: commitURL(pageData.Repo.Name, commit.ID.String()),
563+ URL: commitURL(pageData.Repo.Name, commit.ID.String()),
564+ ShortID: commit.ID.String()[:7],
516565 SummaryStr: commit.Summary(),
517- AuthorStr: commit.Author.Name,
518- WhenStr: timediff.TimeDiff(commit.Author.When),
519- Commit: commit,
566+ AuthorStr: commit.Author.Name,
567+ WhenStr: timediff.TimeDiff(commit.Author.When),
568+ Commit: commit,
520569 })
521570 }
522571
......@@ -537,7 +586,7 @@ func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOu
537586 lc = lastCommits[0]
538587 }
539588 entry.CommitURL = commitURL(pageData.Repo.Name, lc.ID.String())
540- entry.Desc = lc.Summary()
589+ entry.Summary = lc.Summary()
541590 entry.When = timediff.TimeDiff(lc.Author.When)
542591 entry.URL = filepath.Join(
543592 "/",
......@@ -562,18 +611,6 @@ func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOu
562611 return output
563612 }
564613
565-type RepoConfig struct {
566- Path string `mapstructure:"path"`
567- Refs []string `mapstructure:"refs"`
568- Desc string `mapstructure:"desc"`
569- MaxCommits int `mapstructure:"max_commits"`
570-}
571-type Config struct {
572- Repos []*RepoConfig `mapstructure:"repos"`
573- URL string `mapstructure:"url"`
574- Cache map[string]bool
575-}
576-
577614 func main() {
578615 viper.SetDefault("outdir", "./public")
579616 viper.SetConfigName("config")
+27, -67
......@@ -115,32 +115,6 @@ pre {
115115 background-color: var(--pre) !important;
116116 }
117117
118-.my {
119- margin: 1rem 0;
120-}
121-
122-.mt {
123- margin-top: 1rem;
124-}
125-
126-.my-sm {
127- margin: 5px 0;
128-}
129-
130-.mono {
131- font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo,
132- monospace;
133-}
134-
135-.box {
136- font-size: 0.8rem;
137- border-radius: 5px;
138- padding: 1rem;
139- margin: 1rem 0;
140- overflow-x: auto;
141- background-color: var(--pre) !important;
142-}
143-
144118 small {
145119 font-size: 0.8rem;
146120 }
......@@ -263,6 +237,19 @@ figure {
263237 margin: 0;
264238 }
265239
240+.mono {
241+ font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo,
242+ monospace;
243+}
244+
245+.box {
246+ border-radius: 5px;
247+ padding: 1rem;
248+ margin: 1rem 0;
249+ overflow-x: auto;
250+ background-color: var(--pre) !important;
251+}
252+
266253 .color-green {
267254 color: var(--success);
268255 }
......@@ -271,10 +258,6 @@ figure {
271258 color: var(--error);
272259 }
273260
274-.post-date {
275- width: 130px;
276-}
277-
278261 .text-grey {
279262 color: var(--grey);
280263 }
......@@ -315,10 +298,6 @@ figure {
315298 font-style: italic;
316299 }
317300
318-.inline {
319- display: inline;
320-}
321-
322301 .flex {
323302 display: flex;
324303 }
......@@ -335,16 +314,8 @@ figure {
335314 margin-top: 0.5rem;
336315 }
337316
338-.mb {
339- margin-bottom: 0.5rem;
340-}
341-
342-.mr {
343- margin-right: 0.5rem;
344-}
345-
346-.ml {
347- margin-left: 0.5rem;
317+.mt-lg {
318+ margin-top: 1.35rem;
348319 }
349320
350321 .my {
......@@ -357,6 +328,11 @@ figure {
357328 margin-bottom: 1rem;
358329 }
359330
331+.my-sm {
332+ margin-top: 5px;
333+ margin-bottom: 5px;
334+}
335+
360336 .mx {
361337 margin-left: 0.5rem;
362338 margin-right: 0.5rem;
......@@ -375,23 +351,19 @@ figure {
375351 flex: 1;
376352 }
377353
378-.layout-aside {
379- max-width: 50rem;
354+.gap {
355+ gap: 1rem;
380356 }
381357
382-.layout-aside aside {
383- width: 200px;
358+.border-b {
359+ border-bottom: 1px solid #666;
384360 }
385361
386-.layout-aside img {
387- border-radius: 5px;
362+.tree-size {
363+ width: 60px;
388364 }
389365
390-#readme {
391- display: none;
392-}
393-
394-@media only screen and (max-width: 600px) {
366+@media only screen and (max-width: 900px) {
395367 body {
396368 padding: 1rem;
397369 }
......@@ -399,16 +371,4 @@ figure {
399371 header {
400372 margin: 0;
401373 }
402-
403- .layout-aside main {
404- flex-direction: column;
405- }
406-
407- aside {
408- display: none;
409- }
410-
411- #readme {
412- display: block;
413- }
414374 }