repos / pgit

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

commit
002fb3a
parent
1b38e02
author
Eric Bower
date
2023-06-18 20:20:30 +0000 UTC
chore: connect pages together
3 files changed,  +52, -6
A Dockerfile
+3, -0
1@@ -0,0 +1,3 @@
2+FROM nginx
3+COPY ./public /usr/share/nginx/html
4+EXPOSE 80
M Makefile
+8, -0
 1@@ -1,3 +1,11 @@
 2+clean:
 3+	rm -rf ./public
 4+.PHONY: clean
 5+
 6 build:
 7 	go build -o pgit ./main.go
 8 .PHONY: build
 9+
10+static: build clean
11+	./pgit
12+.PHONY:
M main.go
+41, -6
 1@@ -82,7 +82,7 @@ func bail(err error) {
 2 }
 3 
 4 func CommitURL(repo string, commitID string) string {
 5-	return fmt.Sprintf("/%s/commits/%s.gmi", repo, commitID)
 6+	return fmt.Sprintf("/%s/commits/%s.html", repo, commitID)
 7 }
 8 
 9 func repoName(root string) string {
10@@ -149,9 +149,32 @@ func writeHtml(data *WriteData) {
11 	bail(err)
12 }
13 
14+func writeIndex(data *IndexPage) {
15+	files := []string{"./html/index.page.tmpl"}
16+	files = append(
17+		files,
18+		"./html/header.partial.tmpl",
19+		"./html/base.layout.tmpl",
20+	)
21+
22+	ts, err := html.ParseFiles(files...)
23+	bail(err)
24+
25+	outdir := viper.GetString("outdir")
26+	dir := path.Join(outdir)
27+	fmt.Println(dir)
28+	err = os.MkdirAll(dir, os.ModePerm)
29+	bail(err)
30+
31+	w, err := os.OpenFile(path.Join(dir, "index.html"), os.O_WRONLY|os.O_CREATE, 0600)
32+	bail(err)
33+
34+	err = ts.Execute(w, data)
35+	bail(err)
36+}
37 func writeSummary(data *PageData) {
38 	writeHtml(&WriteData{
39-		Name:     "summary.html",
40+		Name:     "index.html",
41 		Template: "./html/summary.page.tmpl",
42 		Data:     data,
43 		RepoName: data.Repo.Name,
44@@ -266,10 +289,10 @@ func writeRepo(root string) {
45 	name := repoName(root)
46 	repoData := &RepoData{
47 		Name:       name,
48-		SummaryURL: fmt.Sprintf("/%s/summary", name),
49-		TreeURL:    fmt.Sprintf("/%s/tree", name),
50-		LogURL:     fmt.Sprintf("/%s/log", name),
51-		RefsURL:    fmt.Sprintf("/%s/refs", name),
52+		SummaryURL: fmt.Sprintf("/%s/index.html", name),
53+		TreeURL:    fmt.Sprintf("/%s/tree.html", name),
54+		LogURL:     fmt.Sprintf("/%s/log.html", name),
55+		RefsURL:    fmt.Sprintf("/%s/refs.html", name),
56 		CloneURL:   fmt.Sprintf("/%s.git", name),
57 	}
58 
59@@ -339,6 +362,18 @@ func main() {
60 	bail(err)
61 
62 	repos := viper.GetStringSlice("repos")
63+	repoList := []*RepoItemData{}
64+	for _, r := range repos {
65+		name := repoName(r)
66+		url := path.Join("/", name, "index.html")
67+		repoList = append(repoList, &RepoItemData{
68+			URL: url,
69+			Name: name,
70+		})
71+	}
72+	writeIndex(&IndexPage{
73+		RepoList: repoList,
74+	})
75 	for _, r := range repos {
76 		writeRepo(r)
77 	}