repos / pgit

static site generator for git
git clone https://github.com/picosh/pgit.git

commit
41f93ba
parent
132c3f9
author
Eric Bower
date
2024-01-14 20:04:01 +0000 UTC
working on file icons
5 files changed,  +49, -6
M Makefile
+2, -2
1@@ -28,6 +28,6 @@ static: build clean
2 .PHONY:
3 
4 deploy:
5-	scp -r ./public/* erock@pgs.sh:/$(PROJECT)
6-	ssh erock@pgs.sh git-pgit link $(PROJECT)
7+	rsync -rv ./public/* erock@pgs.sh:/$(PROJECT)
8+	ssh erock@pgs.sh link git-pgit $(PROJECT) --write
9 .PHONY: deploy
M html/base.layout.tmpl
+1, -0
1@@ -10,6 +10,7 @@
2 
3     {{template "meta" .}}
4 
5+    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/devicons/devicon@latest/devicon.min.css">
6     <link rel="stylesheet" href="https://pico.sh/smol.css" />
7     <link rel="stylesheet" href="/main.css" />
8   </head>
M html/tree.page.tmpl
+10, -2
 1@@ -17,8 +17,16 @@
 2 
 3     {{range .Tree.Items}}
 4       <div class="flex justify-between items-center gap p-sm border-b tree-row">
 5-        <div class="flex-1 tree-path">
 6-          <a href="{{.URL}}">{{.Name}}{{if .IsDir}}/{{end}}</a>
 7+        <div class="flex-1 tree-path flex items-center gap">
 8+          {{if .IsDir}}
 9+            <svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 512 512">
10+              <path d="M0 96C0 60.7 28.7 32 64 32H196.1c19.1 0 37.4 7.6 50.9 21.1L289.9 96H448c35.3 0 64 28.7 64 64V416c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V96zM64 80c-8.8 0-16 7.2-16 16V416c0 8.8 7.2 16 16 16H448c8.8 0 16-7.2 16-16V160c0-8.8-7.2-16-16-16H286.6c-10.6 0-20.8-4.2-28.3-11.7L213.1 87c-4.5-4.5-10.6-7-17-7H64z"/>
11+            </svg>
12+          {{else}}
13+          <i class="{{.Icon}}"></i>
14+          {{end}}
15+
16+          <a href="{{.URL}}">{{.Name}}</a>
17         </div>
18 
19         <div class="flex items-center gap">
M main.go
+28, -2
 1@@ -7,7 +7,6 @@ import (
 2 	"flag"
 3 	"fmt"
 4 	"html/template"
 5-	"io/ioutil"
 6 	"math"
 7 	"os"
 8 	"path/filepath"
 9@@ -121,6 +120,7 @@ type TreeItem struct {
10 	Size       string
11 	NumLines   int
12 	Name       string
13+	Icon string
14 	Path       string
15 	URL        template.URL
16 	CommitID   string
17@@ -337,7 +337,7 @@ func (c *Config) writeHtml(writeData *WriteData) {
18 
19 func (c *Config) copyStatic(dst string, data []byte) {
20 	c.Logger.Infof("writing (%s)", dst)
21-	err := ioutil.WriteFile(dst, data, 0755)
22+	err := os.WriteFile(dst, data, 0755)
23 	bail(err)
24 }
25 
26@@ -736,6 +736,30 @@ func (tw *TreeWalker) calcBreadcrumbs(curpath string) []*Breadcrumb {
27 	return crumbs
28 }
29 
30+func FilenameToDevIcon(filename string) string {
31+	ext := filepath.Ext(filename)
32+	extMappr := map[string]string{
33+		".html": "html5",
34+		".go": "go",
35+		".py": "python",
36+		".css": "css3",
37+		".js": "javascript",
38+		".md": "markdown",
39+	}
40+
41+	nameMappr := map[string]string {
42+		"Makefile": "cmake",
43+		"Dockerfile": "docker",
44+	}
45+
46+	icon := extMappr[ext]
47+	if icon == "" {
48+		icon = nameMappr[filename]
49+	}
50+
51+	return fmt.Sprintf("devicon-%s-original", icon)
52+}
53+
54 func (tw *TreeWalker) NewTreeItem(entry *git.TreeEntry, curpath string, crumbs []*Breadcrumb) *TreeItem {
55 	typ := entry.Type()
56 	fname := filepath.Join(curpath, entry.Name())
57@@ -782,6 +806,8 @@ func (tw *TreeWalker) NewTreeItem(entry *git.TreeEntry, curpath string, crumbs [
58 			entry.Name(),
59 			"index.html",
60 		)
61+	} else if typ == git.ObjectBlob {
62+		item.Icon = FilenameToDevIcon(item.Name)
63 	}
64 	item.URL = template.URL(fpath)
65 
M static/main.css
+8, -0
 1@@ -1,3 +1,11 @@
 2+body {
 3+  max-width: 900px;
 4+}
 5+
 6+.box {
 7+  margin: 1rem 0;
 8+}
 9+
10 .tree-size {
11   width: 60px;
12   text-align: right;