Commit 002fb3a

Eric Bower  ·  2023-06-18 16:20:30 -0400 EDT
parent 1b38e02
chore: connect pages together
3 files changed,  +52, -6
+3, -0
......@@ -0,0 +1,3 @@
1+FROM nginx
2+COPY ./public /usr/share/nginx/html
3+EXPOSE 80
+8, -0
......@@ -1,3 +1,11 @@
1+clean:
2+ rm -rf ./public
3+.PHONY: clean
4+
15 build:
26 go build -o pgit ./main.go
37 .PHONY: build
8+
9+static: build clean
10+ ./pgit
11+.PHONY:
+41, -6
......@@ -82,7 +82,7 @@ func bail(err error) {
8282 }
8383
8484 func CommitURL(repo string, commitID string) string {
85- return fmt.Sprintf("/%s/commits/%s.gmi", repo, commitID)
85+ return fmt.Sprintf("/%s/commits/%s.html", repo, commitID)
8686 }
8787
8888 func repoName(root string) string {
......@@ -149,9 +149,32 @@ func writeHtml(data *WriteData) {
149149 bail(err)
150150 }
151151
152+func writeIndex(data *IndexPage) {
153+ files := []string{"./html/index.page.tmpl"}
154+ files = append(
155+ files,
156+ "./html/header.partial.tmpl",
157+ "./html/base.layout.tmpl",
158+ )
159+
160+ ts, err := html.ParseFiles(files...)
161+ bail(err)
162+
163+ outdir := viper.GetString("outdir")
164+ dir := path.Join(outdir)
165+ fmt.Println(dir)
166+ err = os.MkdirAll(dir, os.ModePerm)
167+ bail(err)
168+
169+ w, err := os.OpenFile(path.Join(dir, "index.html"), os.O_WRONLY|os.O_CREATE, 0600)
170+ bail(err)
171+
172+ err = ts.Execute(w, data)
173+ bail(err)
174+}
152175 func writeSummary(data *PageData) {
153176 writeHtml(&WriteData{
154- Name: "summary.html",
177+ Name: "index.html",
155178 Template: "./html/summary.page.tmpl",
156179 Data: data,
157180 RepoName: data.Repo.Name,
......@@ -266,10 +289,10 @@ func writeRepo(root string) {
266289 name := repoName(root)
267290 repoData := &RepoData{
268291 Name: name,
269- SummaryURL: fmt.Sprintf("/%s/summary", name),
270- TreeURL: fmt.Sprintf("/%s/tree", name),
271- LogURL: fmt.Sprintf("/%s/log", name),
272- RefsURL: fmt.Sprintf("/%s/refs", name),
292+ SummaryURL: fmt.Sprintf("/%s/index.html", name),
293+ TreeURL: fmt.Sprintf("/%s/tree.html", name),
294+ LogURL: fmt.Sprintf("/%s/log.html", name),
295+ RefsURL: fmt.Sprintf("/%s/refs.html", name),
273296 CloneURL: fmt.Sprintf("/%s.git", name),
274297 }
275298
......@@ -339,6 +362,18 @@ func main() {
339362 bail(err)
340363
341364 repos := viper.GetStringSlice("repos")
365+ repoList := []*RepoItemData{}
366+ for _, r := range repos {
367+ name := repoName(r)
368+ url := path.Join("/", name, "index.html")
369+ repoList = append(repoList, &RepoItemData{
370+ URL: url,
371+ Name: name,
372+ })
373+ }
374+ writeIndex(&IndexPage{
375+ RepoList: repoList,
376+ })
342377 for _, r := range repos {
343378 writeRepo(r)
344379 }