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
Styling clean up
author
Ben Vogt <[email protected]>
date
2023-04-06 18:44:12
stats
3 file(s) changed, 47 insertions(+), 29 deletions(-)
files
file.go
gshr.css
template.file.html
  1diff --git a/file.go b/file.go
  2index 2c91f60..ebf3f3c 100644
  3--- a/file.go
  4+++ b/file.go
  5@@ -1,6 +1,7 @@
  6 package main
  7 
  8 import (
  9+	"fmt"
 10 	"html/template"
 11 	"io/fs"
 12 	"os"
 13@@ -26,14 +27,6 @@ func (f *FilePage) RenderPage(t *template.Template) {
 14 	debug("file %v%v", f.RepoData.Name, f.Name)
 15 	err := os.MkdirAll(f.DestinationDir, 0775)
 16 	checkErr(err)
 17-	if f.CanRender {
 18-		fileBytes, err := os.ReadFile(f.Origin)
 19-		checkErr(err)
 20-		fileStr := string(fileBytes)
 21-		highlighted := highlight(f.DestinationDir, &fileStr)
 22-		checkErr(err)
 23-		f.Content = template.HTML(highlighted)
 24-	}
 25 	err = os.MkdirAll(filepath.Dir(f.Destination), 0775)
 26 	checkErr(err)
 27 	output, err := os.Create(f.Destination)
 28@@ -54,16 +47,32 @@ func RenderSingleFilePages(data RepoData) {
 29 			ext := filepath.Ext(filename)
 30 			_, canRenderExtension := settings.TextExtensions[ext]
 31 			_, canRenderByFullName := settings.PlainFiles[filepath.Base(filename)]
 32+			canRender := canRenderExtension || canRenderByFullName
 33 			partialPath, _ := strings.CutPrefix(filename, data.CloneDir())
 34+			destDir := path.Join(args.OutputDir, data.Name, "files", partialPath)
 35 			outputName := path.Join(args.OutputDir, data.Name, "files", partialPath, "index.html")
 36+			var content template.HTML
 37+			info, err := os.Stat(filename)
 38+			checkErr(err)
 39+			if canRender {
 40+				fileBytes, err := os.ReadFile(filename)
 41+				checkErr(err)
 42+				fileStr := string(fileBytes)
 43+				highlighted := highlight(destDir, &fileStr)
 44+				checkErr(err)
 45+				content = template.HTML(highlighted)
 46+			}
 47 			(&FilePage{
 48 				RepoData:       data,
 49-				Name:           partialPath,
 50+				Mode:           info.Mode().String(),
 51+				Size:           fmt.Sprintf("%v", info.Size()),
 52+				Name:           strings.TrimPrefix(partialPath, "/"),
 53 				Extension:      ext,
 54-				CanRender:      canRenderExtension || canRenderByFullName,
 55+				CanRender:      canRender,
 56 				Origin:         filename,
 57 				Destination:    outputName,
 58-				DestinationDir: path.Join(args.OutputDir, data.Name, "files", partialPath),
 59+				DestinationDir: destDir,
 60+				Content:        content,
 61 			}).RenderPage(t)
 62 		}
 63 		return nil
 64diff --git a/gshr.css b/gshr.css
 65index 6c21d98..fdbe758 100644
 66--- a/gshr.css
 67+++ b/gshr.css
 68@@ -50,10 +50,6 @@ body {
 69   font-feature-settings: "calt" 1, "kern" 1, "liga" 1, "frac" 0;
 70 }
 71 
 72-pre {
 73-  margin: 0.31rem 0
 74-}
 75-
 76 pre,
 77 code,
 78 tt {
 79@@ -101,8 +97,9 @@ div.content {
 80 }
 81 
 82 pre {
 83+  margin: 4px 0;
 84   overflow-x: auto;
 85-  padding: 0.4em;
 86+  padding: 4px;
 87   border: solid 1px gainsboro;
 88   border-radius: 4px;
 89 }
 90diff --git a/template.file.html b/template.file.html
 91index ec3d46f..b8288a7 100644
 92--- a/template.file.html
 93+++ b/template.file.html
 94@@ -8,17 +8,29 @@
 95 <body>
 96   <div class="content">
 97     {{ template "metadata" .RepoData }}
 98-    <r-cell span="16">
 99-      <div style="padding-bottom: 4px;">
100-        <a href="{{ .RepoData.HeadData.BaseURL }}{{ .RepoData.Name }}/files.html">
101-          <span>
102-            ←
103-            All files
104-          </span>
105-        </a>
106-      </div>
107-    </r-cell>
108-    <div class="file">
109+    <div style="padding-bottom: 10px;">
110+      <a href="{{ .RepoData.HeadData.BaseURL }}{{ .RepoData.Name }}/files.html">
111+        <span>
112+          ←
113+          All files
114+        </span>
115+      </a>
116+    </div>
117+    <r-grid columns="12" style="gap: 2px; padding-bottom: 4px;">
118+      <r-cell span="9">
119+        <div class="ellipsis">
120+          <b>name: </b>
121+          <span class="mono">{{ .Name }}</span>
122+        </div>
123+      </r-cell>
124+      <r-cell span="2">
125+        <div align="right" class="mono ellipsis">{{ .Mode }}</div>
126+      </r-cell>
127+      <r-cell span="1">
128+        <div align="right" class="mono ellipsis">{{ .Size }}</div>
129+      </r-cell>
130+    </r-grid>
131+    <div>
132       {{ if .CanRender }}
133       {{ .Content }}
134       {{ else }}