repos / pgit

static site generator for git
git clone https://github.com/picosh/pgit.git

commit
7233123
parent
1833a80
author
Eric Bower
date
2023-08-13 18:53:59 +0000 UTC
refactor: templates
12 files changed,  +49, -33
M .github/workflows/static.yml
+0, -1
1@@ -21,7 +21,6 @@ jobs:
2       - name: generate site
3         run: |
4           pgit --out ./public --label pgit --desc "static site generator for git" --clone-url "https://github.com/picosh/pgit.git" --revs main
5-          pgit --out ./public --assets
6       - name: Set outputs
7         id: vars
8         run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
A README.md
+13, -0
 1@@ -0,0 +1,13 @@
 2+# pgit
 3+
 4+A static site generator for git
 5+
 6+# usage
 7+
 8+```bash
 9+make build
10+```
11+
12+```bash
13+./pgit --revs main --label pico --out ./public
14+```
M html/base.layout.tmpl
+15, -9
 1@@ -1,16 +1,22 @@
 2 {{define "base"}}
 3 <!doctype html>
 4 <html lang="en">
 5-    <head>
 6-        <meta charset='utf-8'>
 7-        <meta name="viewport" content="width=device-width, initial-scale=1" />
 8-        <title>{{template "title" .}}</title>
 9+  <head>
10+    <meta charset='utf-8'>
11+    <meta name="viewport" content="width=device-width, initial-scale=1" />
12+    <title>{{template "title" .}}</title>
13 
14-        <meta name="keywords" content="git code forge repo repository" />
15+    <meta name="keywords" content="git code forge repo repository" />
16 
17-        <link rel="stylesheet" href="/main.css" />
18-        <link rel="stylesheet" href="/syntax.css" />
19-    </head>
20-    <body>{{template "content" .}}</body>
21+    <link rel="stylesheet" href="/main.css" />
22+    <link rel="stylesheet" href="/syntax.css" />
23+  </head>
24+  <body>
25+    <header>{{template "header" .}}</header>
26+    <hr />
27+    <main>{{template "content" .}}</main>
28+    <hr />
29+    <footer>{{template "footer" .}}</footer>
30+  </body>
31 </html>
32 {{end}}
M html/commit.page.tmpl
+0, -2
1@@ -2,8 +2,6 @@
2 {{define "title"}}commit log{{end}}
3 
4 {{define "content"}}
5-  {{template "header" .}}
6-
7   <dl>
8     <dt>commit</dt>
9     <dd><a href="{{.CommitURL}}">{{.CommitID}}</a></dd>
M html/file.page.tmpl
+1, -3
 1@@ -2,8 +2,6 @@
 2 {{define "title"}}file{{end}}
 3 
 4 {{define "content"}}
 5-  {{template "header" .}}
 6-
 7-  <h1 class="text-lg">{{.Path}}</h1>
 8+  <h2 class="text-lg">{{.Path}}</h2>
 9   {{.Contents}}
10 {{end }}
A html/footer.partial.tmpl
+5, -0
1@@ -0,0 +1,5 @@
2+{{define "footer"}}
3+<div>
4+  published with <a href="https://pgs.sh">pgs.sh</a>
5+</div>
6+{{end}}
M html/header.partial.tmpl
+8, -6
 1@@ -1,20 +1,22 @@
 2 {{define "header"}}
 3-<h1 class="text-xl">
 4-  {{.Repo.RepoName}}
 5+<h1 class="text-xl flex gap">
 6+  {{if .SiteURLs.HomeURL}}
 7+    <a href="{{.SiteURLs.HomeURL}}">repos</a>
 8+    <span>/</span>
 9+  {{end}}
10+  <span>{{.Repo.RepoName}}</span>
11 </h1>
12 
13-<div class="text-lg">
14+<nav class="text-lg">
15   <a href="{{.SiteURLs.SummaryURL}}">summary</a> |
16   <a href="{{.SiteURLs.RefsURL}}">refs</a> |
17   <span class="font-bold">{{.RevData.RevName}}</span> |
18   <a href="{{.RevData.TreeURL}}">tree</a> |
19   <a href="{{.RevData.LogURL}}">log</a>
20-</div>
21+</nav>
22 
23 <div class="mt-lg">
24   <div class="text-lg">{{.Repo.Desc}}</div>
25   <pre style="margin: 0;">git clone {{.SiteURLs.CloneURL}}</pre>
26 </div>
27-
28-<hr />
29 {{end}}
M html/log.page.tmpl
+0, -2
1@@ -3,8 +3,6 @@
2 {{define "title"}}log{{end}}
3 
4 {{define "content"}}
5-  {{template "header" .}}
6-
7   <div>
8   {{range .Logs}}
9     <div class="box">
M html/refs.page.tmpl
+1, -3
 1@@ -3,9 +3,7 @@
 2 {{define "title"}}refs{{end}}
 3 
 4 {{define "content"}}
 5-  {{template "header" .}}
 6-
 7-  <h2 class="text-md font-bold">refs</h2>
 8+  <h2 class="text-lg font-bold">refs</h2>
 9 
10   <ul>
11   {{range .Refs}}
M html/summary.page.tmpl
+0, -2
1@@ -3,7 +3,5 @@
2 {{define "title"}}summary{{end}}
3 
4 {{define "content"}}
5-  {{template "header" .}}
6-
7   {{.Readme}}
8 {{end}}
M html/tree.page.tmpl
+0, -2
1@@ -3,8 +3,6 @@
2 {{define "title"}}tree{{end}}
3 
4 {{define "content"}}
5-  {{template "header" .}}
6-
7   <div>
8   {{range .Tree}}
9     <div class="flex justify-between items-center gap my-sm border-b">
M main.go
+6, -3
 1@@ -56,7 +56,7 @@ type Config struct {
 2 	HideTreeLastCommit bool
 3 
 4 	// user-defined urls
 5-	HomeUrl  template.URL
 6+	HomeURL  template.URL
 7 	CloneURL template.URL
 8 
 9 	// computed
10@@ -135,7 +135,7 @@ type BranchOutput struct {
11 }
12 
13 type SiteURLs struct {
14-	RootURL    template.URL
15+	HomeURL    template.URL
16 	CloneURL   template.URL
17 	SummaryURL template.URL
18 	RefsURL    template.URL
19@@ -313,6 +313,7 @@ func (c *Config) writeHtml(writeData *WriteData) {
20 		efs,
21 		writeData.Template,
22 		"html/header.partial.tmpl",
23+		"html/footer.partial.tmpl",
24 		"html/base.layout.tmpl",
25 	)
26 	bail(err)
27@@ -531,7 +532,7 @@ func (c *Config) getCommitURL(commitID string) template.URL {
28 
29 func (c *Config) getURLs() *SiteURLs {
30 	return &SiteURLs{
31-		RootURL:    c.HomeUrl,
32+		HomeURL:    c.HomeURL,
33 		CloneURL:   c.CloneURL,
34 		RefsURL:    c.getRefsURL(),
35 		SummaryURL: c.getSummaryURL(),
36@@ -752,6 +753,7 @@ func main() {
37 	var themeFlag = flag.String("theme", "dracula", "theme to use for site")
38 	var labelFlag = flag.String("label", "", "pretty name for the subdir where we create the repo, default is last folder in --repo")
39 	var cloneFlag = flag.String("clone-url", "", "git clone URL")
40+	var homeFlag = flag.String("home-url", "", "URL for breadcumbs to get to list of repositories")
41 	var descFlag = flag.String("desc", "", "description for repo")
42 	var maxCommitsFlag = flag.Int("max-commits", 0, "maximum number of commits to generate")
43 	var hideTreeLastCommitFlag = flag.Bool("hide-tree-last-commit", false, "dont calculate last commit for each file in the tree")
44@@ -791,6 +793,7 @@ func main() {
45 		Theme:              theme,
46 		Logger:             logger,
47 		CloneURL:           template.URL(*cloneFlag),
48+		HomeURL:            template.URL(*homeFlag),
49 		Desc:               *descFlag,
50 		MaxCommits:         *maxCommitsFlag,
51 		HideTreeLastCommit: *hideTreeLastCommitFlag,