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
Using templates for head and metadata
author
Ben Vogt <[email protected]>
date
2023-04-04 18:37:04
stats
7 file(s) changed, 49 insertions(+), 161 deletions(-)
files
README.md
main.go
templates/commit.html
templates/file.html
templates/files.html
templates/log.html
templates/partials.html
  1diff --git a/README.md b/README.md
  2index b8a4063..d8ac977 100644
  3--- a/README.md
  4+++ b/README.md
  5@@ -7,7 +7,6 @@ Git static host repo.
  6 Tasks to do:
  7 
  8 * Render full commit diff.
  9-* Partial template for header.
 10 * Better use of BaseURL.
 11 * Show plain-text files (like Makefile) if possible.
 12 * README and LICENSE linking in main page.
 13diff --git a/main.go b/main.go
 14index 5daa906..1505d6e 100644
 15--- a/main.go
 16+++ b/main.go
 17@@ -248,7 +248,7 @@ func CloneAndInfo() *git.Repository {
 18 }
 19 
 20 func RenderAllCommitPages(r *git.Repository) {
 21-	t, err := template.ParseFS(htmlTemplates, "templates/commit.html")
 22+	t, err := template.ParseFS(htmlTemplates, "templates/commit.html", "templates/partials.html")
 23 	checkErr(err)
 24 	ref, err := r.Head()
 25 	checkErr(err)
 26@@ -282,7 +282,7 @@ func RenderAllCommitPages(r *git.Repository) {
 27 }
 28 
 29 func RenderLogPage(r *git.Repository) {
 30-	t, err := template.ParseFS(htmlTemplates, "templates/log.html")
 31+	t, err := template.ParseFS(htmlTemplates, "templates/log.html", "templates/partials.html")
 32 	checkErr(err)
 33 	commits := make([]Commit, 0)
 34 	ref, err := r.Head()
 35@@ -322,7 +322,7 @@ func RenderLogPage(r *git.Repository) {
 36 }
 37 
 38 func RenderAllFilesPage() {
 39-	t, err := template.ParseFS(htmlTemplates, "templates/files.html")
 40+	t, err := template.ParseFS(htmlTemplates, "templates/files.html", "templates/partials.html")
 41 	checkErr(err)
 42 	trackedFiles := make([]TrackedFileMetaData, 0)
 43 	err = filepath.Walk(config.CloneDir, func(filename string, info fs.FileInfo, err error) error {
 44@@ -355,7 +355,7 @@ func RenderAllFilesPage() {
 45 }
 46 
 47 func RenderSingleFilePages() {
 48-	t, err := template.ParseFS(htmlTemplates, "templates/file.html")
 49+	t, err := template.ParseFS(htmlTemplates, "templates/file.html", "templates/partials.html")
 50 	checkErr(err)
 51 	err = filepath.Walk(config.CloneDir, func(filename string, info fs.FileInfo, err error) error {
 52 		if info.IsDir() && info.Name() == ".git" {
 53diff --git a/templates/commit.html b/templates/commit.html
 54index 589c3b8..6b3ae7c 100644
 55--- a/templates/commit.html
 56+++ b/templates/commit.html
 57@@ -2,49 +2,12 @@
 58 <html lang="en">
 59 
 60 <head>
 61-  <meta charset="utf-8">
 62-  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 63-  <meta name="viewport" content="width=device-width, initial-scale=1">
 64-  <meta http-equiv="X-UA-Compatible" content="IE=edge">
 65-  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
 66-  <title>gshr</title>
 67-  <link rel="stylesheet" href="{{ .BaseURL }}gshr.css" type="text/css">
 68-  <meta name="description"
 69-        content="git static host repo">
 70-  <meta property="og:site_name" content="gshr">
 71-  <meta property="og:type" content="article">
 72-  <meta property="article:author" content="gshr">
 73+  {{ template "head" . }}
 74 </head>
 75 
 76 <body>
 77   <div class="content">
 78-    <div class="metadata">
 79-      <table>
 80-        <tbody>
 81-          <tr>
 82-            <td>
 83-              <h1>www</h1>
 84-              <span class="desc">
 85-                personal website hosted at https:://www.vogt.world/
 86-              </span>
 87-            </td>
 88-          </tr>
 89-          <tr>
 90-            <td>
 91-              git clone
 92-              <a href="[email protected]:./www.gitc">[email protected]:./www.git</a>
 93-            </td>
 94-          </tr>
 95-          <tr>
 96-            <td>
 97-              <a href="{{ .BaseURL }}log.html">Log</a>
 98-              |
 99-              <a href="{{ .BaseURL }}files.html">Files</a>
100-            </td>
101-          </tr>
102-        </tbody>
103-      </table>
104-    </div>
105+    {{ template "metadata" . }}
106     <div class="commit-detail">
107       <table>
108         <tbody>
109diff --git a/templates/file.html b/templates/file.html
110index bebe396..7a44c82 100644
111--- a/templates/file.html
112+++ b/templates/file.html
113@@ -2,49 +2,12 @@
114 <html lang="en">
115 
116 <head>
117-  <meta charset="utf-8">
118-  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
119-  <meta name="viewport" content="width=device-width, initial-scale=1">
120-  <meta http-equiv="X-UA-Compatible" content="IE=edge">
121-  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
122-  <title>gshr</title>
123-  <link rel="stylesheet" href="{{ .BaseURL }}gshr.css" type="text/css">
124-  <meta name="description"
125-        content="git static host repo">
126-  <meta property="og:site_name" content="gshr">
127-  <meta property="og:type" content="article">
128-  <meta property="article:author" content="gshr">
129+  {{ template "head" . }}
130 </head>
131 
132 <body>
133   <div class="content">
134-    <div class="metadata">
135-      <table>
136-        <tbody>
137-          <tr>
138-            <td>
139-              <h1>www</h1>
140-              <span class="desc">
141-                personal website hosted at https:://www.vogt.world/
142-              </span>
143-            </td>
144-          </tr>
145-          <tr>
146-            <td>
147-              git clone
148-              <a href="[email protected]:./www.gitc">[email protected]:./www.git</a>
149-            </td>
150-          </tr>
151-          <tr>
152-            <td>
153-              <a href="{{ .BaseURL }}log.html">Log</a>
154-              |
155-              <a href="{{ .BaseURL }}files.html">Files</a>
156-            </td>
157-          </tr>
158-        </tbody>
159-      </table>
160-    </div>
161+    {{ template "metadata" . }}
162     <div class="file">
163       {{ if .CanRender }}
164       {{ .Content }}
165diff --git a/templates/files.html b/templates/files.html
166index eff7d8e..ede8744 100644
167--- a/templates/files.html
168+++ b/templates/files.html
169@@ -2,49 +2,12 @@
170 <html lang="en">
171 
172 <head>
173-  <meta charset="utf-8">
174-  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
175-  <meta name="viewport" content="width=device-width, initial-scale=1">
176-  <meta http-equiv="X-UA-Compatible" content="IE=edge">
177-  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
178-  <title>gshr</title>
179-  <link rel="stylesheet" href="{{ .BaseURL }}gshr.css" type="text/css">
180-  <meta name="description"
181-        content="git static host repo">
182-  <meta property="og:site_name" content="gshr">
183-  <meta property="og:type" content="article">
184-  <meta property="article:author" content="gshr">
185+  {{ template "head" . }}
186 </head>
187 
188 <body>
189   <div class="content">
190-    <div class="metadata">
191-      <table>
192-        <tbody>
193-          <tr>
194-            <td>
195-              <h1>www</h1>
196-              <span class="desc">
197-                personal website hosted at https:://www.vogt.world/
198-              </span>
199-            </td>
200-          </tr>
201-          <tr>
202-            <td>
203-              git clone
204-              <a href="[email protected]:./www.gitc">[email protected]:./www.git</a>
205-            </td>
206-          </tr>
207-          <tr>
208-            <td>
209-              <a href="{{ .BaseURL }}log.html">Log</a>
210-              |
211-              <a href="{{ .BaseURL }}files.html">Files</a>
212-            </td>
213-          </tr>
214-        </tbody>
215-      </table>
216-    </div>
217+    {{ template "metadata" . }}
218     <div class="files">
219       <table>
220         <thead>
221diff --git a/templates/log.html b/templates/log.html
222index 12af107..0954939 100644
223--- a/templates/log.html
224+++ b/templates/log.html
225@@ -2,49 +2,12 @@
226 <html lang="en">
227 
228 <head>
229-  <meta charset="utf-8">
230-  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
231-  <meta name="viewport" content="width=device-width, initial-scale=1">
232-  <meta http-equiv="X-UA-Compatible" content="IE=edge">
233-  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
234-  <title>gshr</title>
235-  <link rel="stylesheet" href="{{ .BaseURL }}gshr.css" type="text/css">
236-  <meta name="description"
237-        content="git static host repo">
238-  <meta property="og:site_name" content="gshr">
239-  <meta property="og:type" content="article">
240-  <meta property="article:author" content="gshr">
241+  {{ template "head" . }}
242 </head>
243 
244 <body>
245   <div class="content">
246-    <div class="metadata">
247-      <table>
248-        <tbody>
249-          <tr>
250-            <td>
251-              <h1>www</h1>
252-              <span class="desc">
253-                personal website hosted at https:://www.vogt.world/
254-              </span>
255-            </td>
256-          </tr>
257-          <tr>
258-            <td>
259-              git clone
260-              <a href="[email protected]:./www.gitc">[email protected]:./www.git</a>
261-            </td>
262-          </tr>
263-          <tr>
264-            <td>
265-              <a href="{{ .BaseURL }}log.html">Log</a>
266-              |
267-              <a href="{{ .BaseURL }}files.html">Files</a>
268-            </td>
269-          </tr>
270-        </tbody>
271-      </table>
272-    </div>
273+    {{ template "metadata" . }}
274     <div class="log">
275       <table>
276         <thead>
277diff --git a/templates/partials.html b/templates/partials.html
278new file mode 100644
279index 0000000..5a2191a
280--- /dev/null
281+++ b/templates/partials.html
282@@ -0,0 +1,44 @@
283+{{ define "head" }}
284+<meta charset="utf-8">
285+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
286+<meta name="viewport" content="width=device-width, initial-scale=1">
287+<meta http-equiv="X-UA-Compatible" content="IE=edge">
288+<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
289+<title>gshr</title>
290+<link rel="stylesheet" href="{{ .BaseURL }}gshr.css" type="text/css">
291+<meta name="description"
292+      content="git static host repo">
293+<meta property="og:site_name" content="gshr">
294+<meta property="og:type" content="article">
295+<meta property="article:author" content="gshr">
296+{{ end }}
297+
298+{{ define "metadata" }}
299+<div class="metadata">
300+  <table>
301+    <tbody>
302+      <tr>
303+        <td>
304+          <h1>www</h1>
305+          <span class="desc">
306+            personal website hosted at https:://www.vogt.world/
307+          </span>
308+        </td>
309+      </tr>
310+      <tr>
311+        <td>
312+          git clone
313+          <a href="[email protected]:./www.gitc">[email protected]:./www.git</a>
314+        </td>
315+      </tr>
316+      <tr>
317+        <td>
318+          <a href="{{ .BaseURL }}log.html">Log</a>
319+          |
320+          <a href="{{ .BaseURL }}files.html">Files</a>
321+        </td>
322+      </tr>
323+    </tbody>
324+  </table>
325+</div>
326+{{ end }}
327\ No newline at end of file