gshr
git static host repo -- generates static html for repos
git clone https://git.vogt.world/gshr.git
Log | Files | README.md | LICENSE
← Commit log
commit
message
Embedding templates
author
Ben Vogt <[email protected]>
date
2023-04-03 23:04:48
stats
1 file(s) changed, 16 insertions(+), 4 deletions(-)
files
main.go
 1diff --git a/main.go b/main.go
 2index f4b615e..2430b55 100644
 3--- a/main.go
 4+++ b/main.go
 5@@ -2,6 +2,7 @@ package main
 6 
 7 import (
 8 	"bytes"
 9+	_ "embed"
10 	"errors"
11 	"flag"
12 	"fmt"
13@@ -20,6 +21,15 @@ import (
14 	"github.com/go-git/go-git/v5/plumbing/object"
15 )
16 
17+//go:embed file.template.html
18+var fileTemplateHtml string
19+
20+//go:embed files.template.html
21+var filesTemplateHtml string
22+
23+//go:embed log.template.html
24+var logTemplateHtml string
25+
26 var (
27 	config Config
28 )
29@@ -207,7 +217,8 @@ func CloneAndInfo() *git.Repository {
30 }
31 
32 func BuildLogPage(r *git.Repository) {
33-	t, err := template.ParseFiles("log.template.html")
34+	t, err := template.New("log").Parse(logTemplateHtml)
35+	checkErr(err)
36 	commits := make([]GshrCommit, 0)
37 	ref, err := r.Head()
38 	checkErr(err)
39@@ -233,7 +244,8 @@ func BuildLogPage(r *git.Repository) {
40 }
41 
42 func BuildFilesPages() {
43-	t, err := template.ParseFiles("files.template.html")
44+	t, err := template.New("files").Parse(filesTemplateHtml)
45+	checkErr(err)
46 	trackedFiles := make([]TrackedFileMetaData, 0)
47 	err = filepath.Walk(config.CloneDir, func(filename string, info fs.FileInfo, err error) error {
48 		if info.IsDir() && info.Name() == ".git" {
49@@ -264,9 +276,8 @@ func BuildFilesPages() {
50 }
51 
52 func BuildSingleFilePages() {
53-	t, err := template.ParseFiles("file.template.html")
54+	t, err := template.New("file").Parse(fileTemplateHtml)
55 	checkErr(err)
56-
57 	err = filepath.Walk(config.CloneDir, func(filename string, info fs.FileInfo, err error) error {
58 		if info.IsDir() && info.Name() == ".git" {
59 			return filepath.SkipDir