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 base-url for assets
author
Ben Vogt <[email protected]>
date
2023-04-03 22:53:51
stats
6 file(s) changed, 25 insertions(+), 131 deletions(-)
files
Makefile
file.template.html
files.template.html
log.template.html
main.go
styles.css
gshr.css
  1diff --git a/Makefile b/Makefile
  2index 01f7a8b..1129aa9 100644
  3--- a/Makefile
  4+++ b/Makefile
  5@@ -28,6 +28,6 @@ dev: target output cloning target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin
  6     --output=$(PWD)/target/output \
  7     --clone=$(PWD)/target/cloning \
  8 		&& \
  9-    cp styles.css $(PWD)/target/output/ && \
 10+    cp gshr.css $(PWD)/target/output/ && \
 11     cd $(PWD)/target/output && \
 12     python3 -m http.server 8000
 13\ No newline at end of file
 14diff --git a/file.template.html b/file.template.html
 15index 9c330ce..5cc1d66 100644
 16--- a/file.template.html
 17+++ b/file.template.html
 18@@ -8,7 +8,7 @@
 19   <meta http-equiv="X-UA-Compatible" content="IE=edge">
 20   <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
 21   <title>gshr</title>
 22-  <link rel="stylesheet" href="/styles.css" type="text/css">
 23+  <link rel="stylesheet" href="{{ .BaseURL }}gshr.css" type="text/css">
 24   <meta name="description"
 25         content="git static host repo">
 26   <meta property="og:site_name" content="gshr">
 27diff --git a/files.template.html b/files.template.html
 28index 892dfcd..14183cc 100644
 29--- a/files.template.html
 30+++ b/files.template.html
 31@@ -8,7 +8,7 @@
 32   <meta http-equiv="X-UA-Compatible" content="IE=edge">
 33   <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
 34   <title>gshr</title>
 35-  <link rel="stylesheet" href="/styles.css" type="text/css">
 36+  <link rel="stylesheet" href="{{ .BaseURL }}gshr.css" type="text/css">
 37   <meta name="description"
 38         content="git static host repo">
 39   <meta property="og:site_name" content="gshr">
 40diff --git a/styles.css b/gshr.css
 41similarity index 79%
 42rename from styles.css
 43rename to gshr.css
 44index e816014..d6629c5 100644
 45--- a/styles.css
 46+++ b/gshr.css
 47@@ -157,130 +157,7 @@ h6>a:hover {
 48   text-decoration-thickness: 2px
 49 }
 50 
 51-nav * {
 52-  cursor: default
 53-}
 54-
 55-nav h1 {
 56-  margin: 0;
 57-  display: block
 58-}
 59-
 60-nav a[href] {
 61-  color: inherit;
 62-  background: none;
 63-  text-shadow: none
 64-}
 65-
 66-nav a[href]:not(.active) {
 67-  text-decoration: none
 68-}
 69-
 70-nav a[href]:hover {
 71-  color: black;
 72-  background: none;
 73-  text-decoration-style: solid;
 74-  text-decoration-line: underline;
 75-  text-decoration-color: var(--link-color);
 76-  text-decoration-thickness: 2px
 77-}
 78-
 79-nav h1 a[href] {
 80-  display: block
 81-}
 82-
 83-nav h1 a[href]:hover {
 84-  cursor: pointer
 85-}
 86-
 87-nav h1 img {
 88-  display: block
 89-}
 90-
 91-nav ul {
 92-  flex: 0 0 auto;
 93-  margin: 0;
 94-  text-align: left;
 95-  display: list-item;
 96-  list-style: none
 97-}
 98-
 99-nav ul li {
100-  display: list-item;
101-  text-align: -webkit-match-parent
102-}
103-
104-nav.main ul,
105-nav:hover ul {
106-  opacity: 1;
107-  list-style: none;
108-  padding: 0;
109-  margin: 0
110-}
111-
112-.main-header {
113-  max-width: 860px;
114-  min-width: 100px;
115-  padding-left: 20px;
116-  padding-right: 20px;
117-  margin-left: auto;
118-  position: absolute;
119-  top: 40px;
120-  right: 50%;
121-  margin-right: 340px;
122-  letter-spacing: -.009em
123-}
124-
125-
126-nav ul li {
127-  list-style: none;
128-  margin: 0;
129-  padding: 0;
130-  display: block
131-}
132-
133-nav ul li:first-child {
134-  margin-left: 0
135-}
136-
137-nav ul li a[href] {
138-  cursor: pointer;
139-  padding-right: 0.6em
140-}
141-
142-nav a[href].active,
143-nav a[href].active:hover {
144-  text-decoration-style: solid;
145-  text-decoration-line: underline;
146-  text-decoration-color: var(--link-color);
147-  text-decoration-thickness: 2px
148-}
149-
150-nav ul li:last-child a[href] {
151-  padding-right: 0
152-}
153-
154-nav ul li a[href]:hover {
155-  color: var(--text-color);
156-  text-decoration-style: solid;
157-  text-decoration-line: underline;
158-  text-decoration-color: var(--link-color);
159-  text-decoration-thickness: 2px
160-}
161-
162 @media screen and (max-width: 920px) {
163-  .main-header {
164-    margin: 0 auto;
165-    max-width: 860px;
166-    padding-left: 20px;
167-    padding-right: 20px;
168-    position: relative;
169-    padding-top: 10px;
170-    top: unset;
171-    right: unset;
172-    min-width: 120px;
173-  }
174-
175   div.content {
176     margin: 0 auto;
177     padding: 40px 20px;
178diff --git a/log.template.html b/log.template.html
179index 6e75cfb..9bbe959 100644
180--- a/log.template.html
181+++ b/log.template.html
182@@ -8,7 +8,7 @@
183   <meta http-equiv="X-UA-Compatible" content="IE=edge">
184   <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
185   <title>gshr</title>
186-  <link rel="stylesheet" href="/styles.css" type="text/css">
187+  <link rel="stylesheet" href="{{ .BaseURL }}gshr.css" type="text/css">
188   <meta name="description"
189         content="git static host repo">
190   <meta property="og:site_name" content="gshr">
191diff --git a/main.go b/main.go
192index b2dfe6d..f4b615e 100644
193--- a/main.go
194+++ b/main.go
195@@ -29,6 +29,7 @@ type Config struct {
196 	Repo           string
197 	OutputDir      string
198 	CloneDir       string
199+	BaseURL        string
200 	TextExtensions map[string]bool
201 }
202 
203@@ -37,7 +38,8 @@ func DefaultConfig() Config {
204 		DebugOn:   true,
205 		Repo:      "",
206 		OutputDir: "",
207-		CloneDir:  fmt.Sprintf("/tmp/gshr-temp-clone-%v", rand.Uint32()),
208+		BaseURL:   "/",
209+		CloneDir:  "",
210 		TextExtensions: map[string]bool{
211 			".c":          true,
212 			".cc":         true,
213@@ -86,14 +88,23 @@ func main() {
214 	flag.BoolVar(&config.DebugOn, "debug", true, "Run in debug mode.")
215 	flag.StringVar(&config.OutputDir, "output", "", "Directory of output.")
216 	flag.StringVar(&config.CloneDir, "clone", "", "Directory to clone into. Random directory in /tmp if omitted.")
217+	flag.StringVar(&config.BaseURL, "base-url", "/", "Base URL for loading styles.")
218 	flag.Parse()
219 
220 	if config.Repo == "" {
221 		checkErr(errors.New("--repo flag is required"))
222 	}
223 
224+	if config.CloneDir == "" {
225+		config.CloneDir = fmt.Sprintf("/tmp/gshr-temp-clone-%v", rand.Uint32())
226+	}
227+
228+	config.BaseURL = path.Join(config.BaseURL, "/")
229+
230+	debug("repo = %v", config.Repo)
231 	debug("output = %v", config.OutputDir)
232 	debug("clone = %v", config.CloneDir)
233+	debug("base-url = %v", config.BaseURL)
234 	r := CloneAndInfo()
235 	BuildLogPage(r)
236 	BuildFilesPages()
237@@ -108,6 +119,7 @@ type TrackedFileMetaData struct {
238 }
239 
240 type TrackedFile struct {
241+	BaseURL        string
242 	Mode           string
243 	Name           string
244 	Size           string
245@@ -163,6 +175,7 @@ type GshrCommit struct {
246 }
247 
248 type LogPage struct {
249+	BaseURL string
250 	Commits []GshrCommit
251 }
252 
253@@ -174,7 +187,8 @@ func (mi *LogPage) SaveTemplate(t *template.Template) {
254 }
255 
256 type FilesIndex struct {
257-	Files []TrackedFileMetaData
258+	BaseURL string
259+	Files   []TrackedFileMetaData
260 }
261 
262 func (fi *FilesIndex) SaveTemplate(t *template.Template) {
263@@ -212,6 +226,7 @@ func BuildLogPage(r *git.Repository) {
264 
265 	checkErr(err)
266 	m := LogPage{
267+		BaseURL: config.BaseURL,
268 		Commits: commits,
269 	}
270 	m.SaveTemplate(t)
271@@ -242,7 +257,8 @@ func BuildFilesPages() {
272 	})
273 	checkErr(err)
274 	index := FilesIndex{
275-		Files: trackedFiles,
276+		BaseURL: config.BaseURL,
277+		Files:   trackedFiles,
278 	}
279 	index.SaveTemplate(t)
280 }
281@@ -263,6 +279,7 @@ func BuildSingleFilePages() {
282 			outputName := path.Join(config.OutputDir, "files", partialPath, "index.html")
283 			debug("reading = %v", partialPath)
284 			tf := TrackedFile{
285+				BaseURL:        config.BaseURL,
286 				Extension:      ext,
287 				CanRender:      canRender,
288 				Origin:         filename,