commit
message
Adding template for main index
author
Ben Vogt <[email protected]>
date
2023-04-03 15:35:36
stats
4 file(s) changed,
108 insertions(+),
51 deletions(-)
files
index.template.html
main.go
styles.css
template.html
file.template.html
1diff --git a/template.html b/file.template.html
2similarity index 100%
3rename from template.html
4rename to file.template.html
5diff --git a/index.template.html b/index.template.html
6new file mode 100644
7index 0000000..723ab9f
8--- /dev/null
9+++ b/index.template.html
10@@ -0,0 +1,64 @@
11+<!DOCTYPE html>
12+<html lang="en">
13+
14+<head>
15+ <meta charset="utf-8">
16+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
17+ <meta name="viewport" content="width=device-width, initial-scale=1">
18+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
19+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
20+ <title>gshr</title>
21+ <link rel="stylesheet" href="/styles.css" type="text/css">
22+ <meta name="description"
23+ content="git static host repo">
24+ <meta property="og:site_name" content="gshr">
25+ <meta property="og:type" content="article">
26+ <meta property="article:author" content="gshr">
27+</head>
28+
29+<body>
30+ <div class="content">
31+ <div class="commits">
32+ <table id="log">
33+ <thead>
34+ <tr>
35+ <td><b>Date</b></td>
36+ <td><b>Commit message</b></td>
37+ <td><b>Author</b></td>
38+ <td align="right"><b>Files</b></td>
39+ <td align="right"><b>+</b></td>
40+ <td align="right"><b>-</b></td>
41+ </tr>
42+ </thead>
43+ <tbody>
44+ <tr>
45+ <td>2020-03-04 11:03</td>
46+ <td><a href="commit/commit_hash.html">update TODO</a></td>
47+ <td>benjvogt</td>
48+ <td align="right">1</td>
49+ <td align="right">+2</td>
50+ <td align="right">-0</td>
51+ </tr>
52+ <tr>
53+ <td>2020-03-04 10:59</td>
54+ <td><a href="commit/commit_hash.html">README.md update for clarity.</a></td>
55+ <td>benjvogt</td>
56+ <td align="right">3</td>
57+ <td align="right">+83</td>
58+ <td align="right">-3</td>
59+ </tr>
60+ <tr>
61+ <td>2020-01-22 10:04</td>
62+ <td><a href="commit/commit_hash.html">Working through the bugs.</a></td>
63+ <td>benjvogt</td>
64+ <td align="right">1</td>
65+ <td align="right">+2</td>
66+ <td align="right">-3</td>
67+ </tr>
68+ </tbody>
69+ </table>
70+ </div>
71+ </div>
72+</body>
73+
74+</html>
75\ No newline at end of file
76diff --git a/main.go b/main.go
77index 16018fb..98e4399 100644
78--- a/main.go
79+++ b/main.go
80@@ -5,6 +5,7 @@ import (
81 "html/template"
82 "io/fs"
83 "os"
84+ "path"
85 "path/filepath"
86 "strings"
87
88@@ -28,29 +29,34 @@ var (
89 cloningDir = ""
90 )
91
92-func main() {
93- outputDir = os.Getenv("OUTPUT_DIR")
94- cloningDir = os.Getenv("CLONING_DIR")
95- line("OUTPUT_DIR = %v", outputDir)
96- line("CLONING_DIR = %v", cloningDir)
97- cloneAndCheck()
98- primaryScan()
99+type TrackedFile struct {
100+ origin string
101+ destination string
102 }
103
104-func writeFile(filename string, outputFile string, t *template.Template) {
105- fileBytes, err := os.ReadFile(filename)
106+func (tf *TrackedFile) SaveTemplate(t *template.Template) {
107+ fileBytes, err := os.ReadFile(tf.origin)
108 checkErr(err)
109 fileStr := string(fileBytes)
110- filepath.Dir(outputFile)
111- err = os.MkdirAll(filepath.Dir(outputFile), 0775)
112+ err = os.MkdirAll(filepath.Dir(tf.destination), 0775)
113 checkErr(err)
114- output, err := os.Create(outputFile)
115+ output, err := os.Create(tf.destination)
116 checkErr(err)
117 err = t.Execute(output, fileStr)
118 checkErr(err)
119 }
120
121-func cloneAndCheck() {
122+func main() {
123+ outputDir = os.Getenv("OUTPUT_DIR")
124+ cloningDir = os.Getenv("CLONING_DIR")
125+ line("OUTPUT_DIR = %v", outputDir)
126+ line("CLONING_DIR = %v", cloningDir)
127+ CloneAndInfo()
128+ BuildTrackedFiles()
129+ BuildMainIndex()
130+}
131+
132+func CloneAndInfo() {
133 r, err := git.PlainClone(cloningDir, false, &git.CloneOptions{
134 URL: "/Users/bvogt/dev/src/ben/www",
135 })
136@@ -70,8 +76,16 @@ func cloneAndCheck() {
137
138 }
139
140-func primaryScan() {
141- t, err := template.ParseFiles("template.html")
142+func BuildMainIndex() {
143+ t, err := template.ParseFiles("index.template.html")
144+ checkErr(err)
145+ output, err := os.Create(path.Join(outputDir, "index.html"))
146+ err = t.Execute(output, "")
147+ checkErr(err)
148+}
149+
150+func BuildTrackedFiles() {
151+ t, err := template.ParseFiles("file.template.html")
152 checkErr(err)
153
154 err = filepath.Walk(cloningDir, func(filename string, info fs.FileInfo, err error) error {
155@@ -81,12 +95,16 @@ func primaryScan() {
156
157 if !info.IsDir() {
158 ext := filepath.Ext(filename)
159- line("READING: %v", filename)
160 if _, ok := allowedExtensions[ext]; ok {
161 partialPath, _ := strings.CutPrefix(filename, cloningDir)
162 outputName := fmt.Sprintf("%v%v.html", outputDir, partialPath)
163+ line("READING: %v", filename)
164 line("WRITING: %v", outputName)
165- writeFile(filename, outputName, t)
166+ tf := TrackedFile{
167+ origin: filename,
168+ destination: outputName,
169+ }
170+ tf.SaveTemplate(t)
171 }
172 }
173 return nil
174diff --git a/styles.css b/styles.css
175index 72bb047..872e062 100644
176--- a/styles.css
177+++ b/styles.css
178@@ -402,38 +402,17 @@ div.content img.img-responsive {
179 height: auto
180 }
181
182-.workspace {
183- border-radius: 3px;
184- background: #4ae1f5;
185- padding: 1em;
186- margin-top: 1em;
187- margin-bottom: 1em;
188- color: black
189-}
190-
191-.ideas {
192- border-radius: 3px;
193- background: #efc51c;
194- padding: 1em;
195- margin-top: 1em;
196- margin-bottom: 1em;
197- color: black
198-}
199-
200-.reading-container {
201- display: flex;
202- flex-wrap: wrap;
203- justify-content: space-between
204+div.content div.commits {
205+ display: block;
206+ font-family: var(--mono-font);
207 }
208
209-.reading-container .book {
210- flex: 0 48%
211+div.content div.commits table {
212+ width: 100%;
213 }
214
215-@media (max-width: 480px) {
216- .reading-container .book {
217- flex: 0 100%;
218- }
219+div.content div.commits table tr:hover {
220+ background: #efefef;
221 }
222
223 .chroma {