Commit e51bb05

Eric Bower  ·  2023-08-05 14:53:20 -0400 EDT
parent d19c0db
content edits
8 files changed,  +71, -48
+2, -0
......@@ -3,6 +3,8 @@ repos:
33 - path: /home/erock/dev/pico/pico
44 refs:
55 - main
6+ desc: pico services - prose.sh, lists.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
67 - path: /home/erock/dev/pico/pico-ops
78 refs:
89 - main
10+ desc: infra for pico services
+1, -3
......@@ -13,8 +13,6 @@
1313 <link rel="stylesheet" href="/main.css" />
1414 <link rel="stylesheet" href="/syntax.css" />
1515 </head>
16- <body>
17- {{template "content" .}}
18- </body>
16+ <body>{{template "content" .}}</body>
1917 </html>
2018 {{end}}
+1, -1
......@@ -22,7 +22,7 @@
2222
2323 <div class="box mono">
2424 <div>
25- <strong>{{.Data.Diff.NumFiles}}</strong> files changed,&nbps;
25+ <strong>{{.Data.Diff.NumFiles}}</strong> files changed,&nbsp;
2626 <span class="color-green">+{{.Data.Diff.TotalAdditions}}</span>,
2727 <span class="color-red">-{{.Data.Diff.TotalDeletions}}</span>
2828 </div>
+10, -7
......@@ -1,17 +1,20 @@
11 {{define "header"}}
2-<h1>
2+<h1 class="text-xl">
33 <a href="/">repos</a>
44 <span>&nbsp;/&nbsp;{{.RepoName}}</span>
55 </h1>
66
7-<div>
8- <a href="{{.Repo.SummaryURL}}">summary</a> |
9- <a href="{{.Repo.TreeURL}}">tree</a> |
10- <a href="{{.Repo.LogURL}}">log</a> |
11- <a href="{{.Repo.RefsURL}}">refs</a>
7+<div class="text-lg">
8+ <a href="{{.Repo.SummaryURL}}">summary</a> |
9+ <a href="{{.Repo.TreeURL}}">tree</a> |
10+ <a href="{{.Repo.LogURL}}">log</a> |
11+ <a href="{{.Repo.RefsURL}}">refs</a>
1212 </div>
1313
14-<p>git clone {{.Repo.CloneURL}}</p>
14+<div class="my">
15+ <div class="text-lg">{{.Repo.Desc}}</div>
16+ <pre style="margin: 0;">git clone {{.Repo.CloneURL}}</pre>
17+</div>
1518
1619 <hr />
1720 {{end}}
+2, -1
......@@ -4,5 +4,6 @@
44
55 {{define "content"}}
66 {{template "header" .}}
7- <p>{{.Data.Readme}}</p>
7+
8+ {{.Data.Readme}}
89 {{end}}
+9, -3
......@@ -5,10 +5,16 @@
55 {{define "content"}}
66 {{template "header" .}}
77
8+ <div>
89 {{range .Data.Tree}}
9- <div>
10- <a href="{{.URL}}">{{.Path}}</a>
11- <span> (lines: {{.NumLines}})</span>
10+ <div class="flex justify-between mt">
11+ <div class="text-md">
12+ <a href="{{.URL}}">{{.Path}}</a>
13+ </div>
14+ <div class="mono">
15+ <span>lines: {{.NumLines}}</span>
16+ </div>
1217 </div>
1318 {{end}}
19+ </div>
1420 {{end}}
+37, -32
......@@ -26,6 +26,7 @@ type IndexPage struct {
2626
2727 type RepoData struct {
2828 Name string
29+ Desc string
2930 SummaryURL string
3031 TreeURL string
3132 LogURL string
......@@ -51,7 +52,7 @@ type PageData struct {
5152 Branches []*git.Reference
5253 Tags []*git.Reference
5354 Tree []*TreeItem
54- Readme string
55+ Readme template.HTML
5556 Rev *git.Reference
5657 RevName string
5758 }
......@@ -219,16 +220,7 @@ func writeRootSummary(data *PageData) {
219220 Repo: data.Repo,
220221 })
221222 }
222-func writeSummary(data *PageData) {
223- writeHtml(&WriteData{
224- Name: "index.html",
225- Subdir: filepath.Join("tree", data.RevName),
226- Template: "./html/summary.page.tmpl",
227- Data: data,
228- RepoName: data.Repo.Name,
229- Repo: data.Repo,
230- })
231-}
223+
232224 func writeTree(data *PageData) {
233225 writeHtml(&WriteData{
234226 Name: "index.html",
......@@ -263,7 +255,8 @@ type FileData struct {
263255 Contents template.HTML
264256 }
265257
266-func writeHTMLTreeFiles(data *PageData) {
258+func writeHTMLTreeFiles(data *PageData) string {
259+ readme := ""
267260 for _, file := range data.Tree {
268261 b, err := file.Entry.Blob().Bytes()
269262 bail(err)
......@@ -271,9 +264,13 @@ func writeHTMLTreeFiles(data *PageData) {
271264
272265 d := filepath.Dir(file.Path)
273266 contents, err := pastes.ParseText(file.Entry.Name(), string(b))
274- if err != nil {
275- panic(err)
267+ bail(err)
268+
269+ nameLower := strings.ToLower(file.Entry.Name())
270+ if nameLower == "readme.md" {
271+ readme = contents
276272 }
273+
277274 writeHtml(&WriteData{
278275 Name: fmt.Sprintf("%s.html", file.Entry.Name()),
279276 Template: "./html/file.page.tmpl",
......@@ -283,6 +280,7 @@ func writeHTMLTreeFiles(data *PageData) {
283280 Repo: data.Repo,
284281 })
285282 }
283+ return readme
286284 }
287285
288286 func writeLogDiffs(project string, repo *git.Repository, data *PageData, cache map[string]bool) {
......@@ -340,9 +338,8 @@ func writeLogDiffs(project string, repo *git.Repository, data *PageData, cache m
340338 }
341339 }
342340 finContent, err := pastes.ParseText("commit.diff", content)
343- if err != nil {
344- panic(err)
345- }
341+ bail(err)
342+
346343 fl.Content = template.HTML(finContent)
347344 fls = append(fls, fl)
348345 }
......@@ -373,6 +370,7 @@ func writeRepo(config *RepoConfig) {
373370 bail(err)
374371
375372 name := repoName(config.Path)
373+ desc := config.Desc
376374
377375 heads, err := repo.ShowRef(git.ShowRefOptions{Heads: true, Tags: false})
378376 bail(err)
......@@ -385,6 +383,7 @@ func writeRepo(config *RepoConfig) {
385383
386384 repoData := &RepoData{
387385 Name: name,
386+ Desc: desc,
388387 SummaryURL: fmt.Sprintf("/%s/index.html", name),
389388 TreeURL: fmt.Sprintf("/%s/tree/%s/index.html", name, revName),
390389 LogURL: fmt.Sprintf("/%s/logs/%s/index.html", name, revName),
......@@ -396,17 +395,7 @@ func writeRepo(config *RepoConfig) {
396395
397396 cache := make(map[string]bool)
398397
399- data := &PageData{
400- Branches: heads,
401- Tags: tags,
402- Rev: rev,
403- RevName: revName,
404- Repo: repoData,
405- Readme: "",
406- }
407- writeRootSummary(data)
408- writeRefs(data)
409-
398+ readme := ""
410399 for _, revn := range config.Refs {
411400 for _, head := range heads {
412401 _, headName := filepath.Split(head.Refspec)
......@@ -419,15 +408,28 @@ func writeRepo(config *RepoConfig) {
419408 Rev: head,
420409 RevName: headName,
421410 Repo: repoData,
422- Readme: "",
423411 }
424412
425- writeBranch(repo, data, cache)
413+ branchReadme := writeBranch(repo, data, cache)
414+ if readme == "" {
415+ readme = branchReadme
416+ }
426417 }
427418 }
419+
420+ data := &PageData{
421+ Branches: heads,
422+ Tags: tags,
423+ Rev: rev,
424+ RevName: revName,
425+ Repo: repoData,
426+ Readme: template.HTML(readme),
427+ }
428+ writeRefs(data)
429+ writeRootSummary(data)
428430 }
429431
430-func writeBranch(repo *git.Repository, pageData *PageData, cache map[string]bool) {
432+func writeBranch(repo *git.Repository, pageData *PageData, cache map[string]bool) string {
431433 commits, err := repo.CommitsByPage(pageData.Rev.ID, 0, 100)
432434 bail(err)
433435
......@@ -459,7 +461,7 @@ func writeBranch(repo *git.Repository, pageData *PageData, cache map[string]bool
459461 pageData.Tree = treeEntries
460462
461463 writeLog(pageData)
462- writeHTMLTreeFiles(pageData)
464+ readme := writeHTMLTreeFiles(pageData)
463465 writeLogDiffs(pageData.Repo.Name, repo, pageData, cache)
464466
465467 for _, def := range defaultBranches {
......@@ -467,11 +469,14 @@ func writeBranch(repo *git.Repository, pageData *PageData, cache map[string]bool
467469 writeTree(pageData)
468470 }
469471 }
472+
473+ return readme
470474 }
471475
472476 type RepoConfig struct {
473477 Path string `mapstructure:"path"`
474478 Refs []string `mapstructure:"refs"`
479+ Desc string `mapstructure:"desc"`
475480 }
476481 type Config struct {
477482 Repos []*RepoConfig `mapstructure:"repos"`
+9, -1
......@@ -67,7 +67,7 @@ html {
6767
6868 body {
6969 margin: 0 auto;
70- max-width: 720px;
70+ max-width: 900px;
7171 }
7272
7373 img {
......@@ -115,6 +115,14 @@ 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+
118126 .mono {
119127 font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo,
120128 monospace;