Commit 41f93ba

Eric Bower  ·  2024-01-14 15:04:01 -0500 EST
parent 132c3f9
working on file icons
5 files changed,  +49, -6
+2, -2
......@@ -28,6 +28,6 @@ static: build clean
2828 .PHONY:
2929
3030 deploy:
31- scp -r ./public/* erock@pgs.sh:/$(PROJECT)
32- ssh erock@pgs.sh git-pgit link $(PROJECT)
31+ rsync -rv ./public/* erock@pgs.sh:/$(PROJECT)
32+ ssh erock@pgs.sh link git-pgit $(PROJECT) --write
3333 .PHONY: deploy
+1, -0
......@@ -10,6 +10,7 @@
1010
1111 {{template "meta" .}}
1212
13+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/devicons/devicon@latest/devicon.min.css">
1314 <link rel="stylesheet" href="https://pico.sh/smol.css" />
1415 <link rel="stylesheet" href="/main.css" />
1516 </head>
+10, -2
......@@ -17,8 +17,16 @@
1717
1818 {{range .Tree.Items}}
1919 <div class="flex justify-between items-center gap p-sm border-b tree-row">
20- <div class="flex-1 tree-path">
21- <a href="{{.URL}}">{{.Name}}{{if .IsDir}}/{{end}}</a>
20+ <div class="flex-1 tree-path flex items-center gap">
21+ {{if .IsDir}}
22+ <svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 512 512">
23+ <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"/>
24+ </svg>
25+ {{else}}
26+ <i class="{{.Icon}}"></i>
27+ {{end}}
28+
29+ <a href="{{.URL}}">{{.Name}}</a>
2230 </div>
2331
2432 <div class="flex items-center gap">
+28, -2
......@@ -7,7 +7,6 @@ import (
77 "flag"
88 "fmt"
99 "html/template"
10- "io/ioutil"
1110 "math"
1211 "os"
1312 "path/filepath"
......@@ -121,6 +120,7 @@ type TreeItem struct {
121120 Size string
122121 NumLines int
123122 Name string
123+ Icon string
124124 Path string
125125 URL template.URL
126126 CommitID string
......@@ -337,7 +337,7 @@ func (c *Config) writeHtml(writeData *WriteData) {
337337
338338 func (c *Config) copyStatic(dst string, data []byte) {
339339 c.Logger.Infof("writing (%s)", dst)
340- err := ioutil.WriteFile(dst, data, 0755)
340+ err := os.WriteFile(dst, data, 0755)
341341 bail(err)
342342 }
343343
......@@ -736,6 +736,30 @@ func (tw *TreeWalker) calcBreadcrumbs(curpath string) []*Breadcrumb {
736736 return crumbs
737737 }
738738
739+func FilenameToDevIcon(filename string) string {
740+ ext := filepath.Ext(filename)
741+ extMappr := map[string]string{
742+ ".html": "html5",
743+ ".go": "go",
744+ ".py": "python",
745+ ".css": "css3",
746+ ".js": "javascript",
747+ ".md": "markdown",
748+ }
749+
750+ nameMappr := map[string]string {
751+ "Makefile": "cmake",
752+ "Dockerfile": "docker",
753+ }
754+
755+ icon := extMappr[ext]
756+ if icon == "" {
757+ icon = nameMappr[filename]
758+ }
759+
760+ return fmt.Sprintf("devicon-%s-original", icon)
761+}
762+
739763 func (tw *TreeWalker) NewTreeItem(entry *git.TreeEntry, curpath string, crumbs []*Breadcrumb) *TreeItem {
740764 typ := entry.Type()
741765 fname := filepath.Join(curpath, entry.Name())
......@@ -782,6 +806,8 @@ func (tw *TreeWalker) NewTreeItem(entry *git.TreeEntry, curpath string, crumbs [
782806 entry.Name(),
783807 "index.html",
784808 )
809+ } else if typ == git.ObjectBlob {
810+ item.Icon = FilenameToDevIcon(item.Name)
785811 }
786812 item.URL = template.URL(fpath)
787813
+8, -0
......@@ -1,3 +1,11 @@
1+body {
2+ max-width: 900px;
3+}
4+
5+.box {
6+ margin: 1rem 0;
7+}
8+
19 .tree-size {
210 width: 60px;
311 text-align: right;