commit
message
Splitting out config
author
Ben Vogt <[email protected]>
date
2023-04-04 21:46:53
stats
4 file(s) changed,
115 insertions(+),
119 deletions(-)
files
README.md
config.go
main.go
templates/partials.html
1diff --git a/README.md b/README.md
2index dbd365b..9de7085 100644
3--- a/README.md
4+++ b/README.md
5@@ -6,5 +6,4 @@ Git static host repo.
6
7 Tasks to do:
8
9-* README and LICENSE linking in main page.
10 * Multi-repo namespacing.
11\ No newline at end of file
12diff --git a/config.go b/config.go
13new file mode 100644
14index 0000000..fb73fb4
15--- /dev/null
16+++ b/config.go
17@@ -0,0 +1,112 @@
18+package main
19+
20+type Config struct {
21+ DebugOn bool
22+ Repo string
23+ OutputDir string
24+ CloneDir string
25+ RepoData RepoData
26+ AllowedLicenseFiles map[string]bool
27+ AllowedReadMeFiles map[string]bool
28+ TextExtensions map[string]bool
29+ PlainFiles map[string]bool
30+}
31+
32+func DefaultConfig() Config {
33+ return Config{
34+ DebugOn: true,
35+ Repo: "",
36+ OutputDir: "",
37+ CloneDir: "",
38+ RepoData: RepoData{
39+ Name: "",
40+ GitURL: "",
41+ Description: "",
42+ BaseURL: "/",
43+ ReadMePath: "",
44+ LicenseFilePath: "",
45+ },
46+ TextExtensions: map[string]bool{
47+ ".c": true,
48+ ".cc": true,
49+ ".conf": true,
50+ ".config": true,
51+ ".cpp": true,
52+ ".cs": true,
53+ ".css": true,
54+ ".csv": true,
55+ ".Dockerfile": true,
56+ ".gitignore": true,
57+ ".gitmodules": true,
58+ ".go": true,
59+ ".h": true,
60+ ".htm": true,
61+ ".html": true,
62+ ".iml": true,
63+ ".js": true,
64+ ".json": true,
65+ ".jsx": true,
66+ ".less": true,
67+ ".lock": true,
68+ ".log": true,
69+ ".Makefile": true,
70+ ".md": true,
71+ ".mod": true,
72+ ".php": true,
73+ ".py": true,
74+ ".rb": true,
75+ ".rs": true,
76+ ".scss": true,
77+ ".sql": true,
78+ ".sum": true,
79+ ".svg": true,
80+ ".toml": true,
81+ ".ts": true,
82+ ".tsv": true,
83+ ".tsx": true,
84+ ".txt": true,
85+ ".xml": true,
86+ ".yaml": true,
87+ ".yml": true,
88+ },
89+ PlainFiles: map[string]bool{
90+ "Dockerfile": true,
91+ "license-mit": true,
92+ "LICENSE-MIT": true,
93+ "license": true,
94+ "LICENSE": true,
95+ "Makefile": true,
96+ "readme": true,
97+ "Readme": true,
98+ "ReadMe": true,
99+ "README": true,
100+ },
101+ AllowedLicenseFiles: map[string]bool{
102+ "license-mit": true,
103+ "LICENSE-MIT": true,
104+ "license.md": true,
105+ "LICENSE.md": true,
106+ "license.txt": true,
107+ "LICENSE.txt": true,
108+ "LICENSE": true,
109+ },
110+ AllowedReadMeFiles: map[string]bool{
111+ "readme.md": true,
112+ "Readme.md": true,
113+ "ReadMe.md": true,
114+ "README.md": true,
115+ "readme.txt": true,
116+ "README.txt": true,
117+ "README": true,
118+ },
119+ }
120+}
121+
122+type RepoData struct {
123+ Name string
124+ GitURL string
125+ Description string
126+ BaseURL string
127+ ReadMePath string
128+ LicenseFilePath string
129+}
130diff --git a/main.go b/main.go
131index cc4ed00..61cad4a 100644
132--- a/main.go
133+++ b/main.go
134@@ -23,118 +23,6 @@ var htmlTemplates embed.FS
135
136 var config Config
137
138-type Config struct {
139- DebugOn bool
140- Repo string
141- OutputDir string
142- CloneDir string
143- BaseURL string
144- RepoData RepoData
145- AllowedLicenseFiles map[string]bool
146- AllowedReadMeFiles map[string]bool
147- TextExtensions map[string]bool
148- PlainFiles map[string]bool
149-}
150-
151-func DefaultConfig() Config {
152- config := Config{
153- DebugOn: true,
154- Repo: "",
155- OutputDir: "",
156- CloneDir: "",
157- RepoData: RepoData{
158- Name: "",
159- Description: "",
160- BaseURL: "/",
161- },
162- TextExtensions: map[string]bool{
163- ".c": true,
164- ".cc": true,
165- ".conf": true,
166- ".config": true,
167- ".cpp": true,
168- ".cs": true,
169- ".css": true,
170- ".csv": true,
171- ".Dockerfile": true,
172- ".gitignore": true,
173- ".gitmodules": true,
174- ".go": true,
175- ".h": true,
176- ".htm": true,
177- ".html": true,
178- ".iml": true,
179- ".js": true,
180- ".json": true,
181- ".jsx": true,
182- ".less": true,
183- ".lock": true,
184- ".log": true,
185- ".Makefile": true,
186- ".md": true,
187- ".mod": true,
188- ".php": true,
189- ".py": true,
190- ".rb": true,
191- ".rs": true,
192- ".scss": true,
193- ".sql": true,
194- ".sum": true,
195- ".svg": true,
196- ".toml": true,
197- ".ts": true,
198- ".tsv": true,
199- ".tsx": true,
200- ".txt": true,
201- ".xml": true,
202- ".yaml": true,
203- ".yml": true,
204- },
205- PlainFiles: map[string]bool{
206- "Dockerfile": true,
207- "license-mit": true,
208- "LICENSE-MIT": true,
209- "license": true,
210- "LICENSE": true,
211- "Makefile": true,
212- "readme": true,
213- "Readme": true,
214- "ReadMe": true,
215- "README": true,
216- },
217- AllowedLicenseFiles: map[string]bool{
218- "license-mit": true,
219- "LICENSE-MIT": true,
220- "license.md": true,
221- "LICENSE.md": true,
222- "license.txt": true,
223- "LICENSE.txt": true,
224- "LICENSE": true,
225- },
226- AllowedReadMeFiles: map[string]bool{
227- "readme.md": true,
228- "Readme.md": true,
229- "ReadMe.md": true,
230- "README.md": true,
231- "readme.txt": true,
232- "README.txt": true,
233- "README": true,
234- },
235- }
236- return config
237-}
238-
239-type RepoData struct {
240- Name string
241- GitURL string
242- Description string
243- BaseURL string
244- HasReadMe bool
245- ReadMePath string
246- HasLicenseFile bool
247- LicenseFilePath string
248-}
249-
250 func main() {
251 config = DefaultConfig()
252 flag.StringVar(&config.Repo, "repo", "", "Repo to use.")
253@@ -160,12 +48,10 @@ func main() {
254 debug("repo = %v", config.Repo)
255 debug("output = %v", config.OutputDir)
256 debug("clone = %v", config.CloneDir)
257- debug("base-url = %v", config.BaseURL)
258+ debug("base-url = %v", config.RepoData.BaseURL)
259 r := CloneAndInfo()
260 config.RepoData.ReadMePath = findFileInRoot(config.AllowedReadMeFiles)
261- config.RepoData.HasReadMe = config.RepoData.ReadMePath != ""
262 config.RepoData.LicenseFilePath = findFileInRoot(config.AllowedLicenseFiles)
263- config.RepoData.HasLicenseFile = config.RepoData.LicenseFilePath != ""
264 RenderLogPage(r)
265 RenderAllCommitPages(r)
266 RenderAllFilesPage()
267diff --git a/templates/partials.html b/templates/partials.html
268index d263e5d..6d8a1aa 100644
269--- a/templates/partials.html
270+++ b/templates/partials.html
271@@ -35,13 +35,13 @@
272 <a href="{{ .BaseURL }}log.html">Log</a>
273 |
274 <a href="{{ .BaseURL }}files.html">Files</a>
275- {{ if .HasReadMe }}
276+ {{ if not (eq .ReadMePath "") }}
277 |
278 <a href="{{ .BaseURL }}files/{{ .ReadMePath }}/index.html">
279 {{ .ReadMePath }}
280 </a>
281 {{ end }}
282- {{ if .HasLicenseFile }}
283+ {{ if not (eq .LicenseFilePath "") }}
284 |
285 <a href="{{ .BaseURL }}files/{{ .LicenseFilePath }}/index.html">
286 {{ .LicenseFilePath }}