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
More todo items, adding renderable extensions
author
Ben Vogt <[email protected]>
date
2023-04-04 18:18:01
stats
2 file(s) changed, 20 insertions(+), 8 deletions(-)
files
README.md
main.go
 1diff --git a/README.md b/README.md
 2index 027e210..b8a4063 100644
 3--- a/README.md
 4+++ b/README.md
 5@@ -6,6 +6,7 @@ Git static host repo.
 6 
 7 Tasks to do:
 8 
 9+* Render full commit diff.
10 * Partial template for header.
11 * Better use of BaseURL.
12 * Show plain-text files (like Makefile) if possible.
13diff --git a/main.go b/main.go
14index 1c22143..f16a775 100644
15--- a/main.go
16+++ b/main.go
17@@ -44,6 +44,7 @@ type Config struct {
18 	CloneDir       string
19 	BaseURL        string
20 	TextExtensions map[string]bool
21+	PlainFiles     map[string]bool
22 }
23 
24 func DefaultConfig() Config {
25@@ -59,7 +60,10 @@ func DefaultConfig() Config {
26 			".conf":       true,
27 			".config":     true,
28 			".cpp":        true,
29+			".cs":         true,
30 			".css":        true,
31+			".csv":        true,
32+			".Dockerfile": true,
33 			".gitignore":  true,
34 			".gitmodules": true,
35 			".go":         true,
36@@ -83,14 +87,22 @@ func DefaultConfig() Config {
37 			".scss":       true,
38 			".sql":        true,
39 			".sum":        true,
40+			".svg":        true,
41 			".toml":       true,
42 			".ts":         true,
43+			".tsv":        true,
44 			".tsx":        true,
45 			".txt":        true,
46 			".xml":        true,
47 			".yaml":       true,
48 			".yml":        true,
49-			"Makefile":    true,
50+		},
51+		PlainFiles: map[string]bool{
52+			"Dockerfile": true,
53+			"LICENSE":    true,
54+			"Makefile":   true,
55+			"readme":     true,
56+			"README":     true,
57 		},
58 	}
59 }
60@@ -99,8 +111,8 @@ func main() {
61 	config = DefaultConfig()
62 	flag.StringVar(&config.Repo, "repo", "", "Repo to use.")
63 	flag.BoolVar(&config.DebugOn, "debug", true, "Run in debug mode.")
64-	flag.StringVar(&config.OutputDir, "output", "", "Directory of output.")
65-	flag.StringVar(&config.CloneDir, "clone", "", "Directory to clone into. Random directory in /tmp if omitted.")
66+	flag.StringVar(&config.OutputDir, "output", "", "Dir of output.")
67+	flag.StringVar(&config.CloneDir, "clone", "", "Directory to clone into. Defaults to /tmp/${rand}")
68 	flag.StringVar(&config.BaseURL, "base-url", "/", "Base URL for loading styles.")
69 	flag.Parse()
70 
71@@ -149,8 +161,7 @@ func (f *TrackedFile) Render(t *template.Template) {
72 	}
73 	err := os.MkdirAll(f.DestinationDir, 0775)
74 	checkErr(err)
75-	_, canRender := config.TextExtensions[f.Extension]
76-	if canRender {
77+	if f.CanRender {
78 		fileBytes, err := os.ReadFile(f.Origin)
79 		checkErr(err)
80 		fileStr := string(fileBytes)
81@@ -363,14 +374,15 @@ func RenderSingleFilePages() {
82 
83 		if !info.IsDir() {
84 			ext := filepath.Ext(filename)
85-			_, canRender := config.TextExtensions[ext]
86+			_, canRenderExtension := config.TextExtensions[ext]
87+			_, canRenderByFullName := config.PlainFiles[filepath.Base(filename)]
88 			partialPath, _ := strings.CutPrefix(filename, config.CloneDir)
89 			outputName := path.Join(config.OutputDir, "files", partialPath, "index.html")
90 			debug("reading = %v", partialPath)
91 			tf := TrackedFile{
92 				BaseURL:        config.BaseURL,
93 				Extension:      ext,
94-				CanRender:      canRender,
95+				CanRender:      canRenderExtension || canRenderByFullName,
96 				Origin:         filename,
97 				Destination:    outputName,
98 				DestinationDir: path.Join(config.OutputDir, "files", partialPath),