Commit 41f93ba
Eric Bower
·
2024-01-14 15:04:01 -0500 EST
parent 132c3f9
working on file icons
5 files changed,
+49,
-6
M
Makefile
+2,
-2
| ... | ... | @@ -28,6 +28,6 @@ static: build clean | |
| 28 | 28 | .PHONY: | |
| 29 | 29 | ||
| 30 | 30 | 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 | |
| 33 | 33 | .PHONY: deploy |
+1,
-0
| ... | ... | @@ -10,6 +10,7 @@ | |
| 10 | 10 | ||
| 11 | 11 | {{template "meta" .}} | |
| 12 | 12 | ||
| 13 | + | <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/devicons/devicon@latest/devicon.min.css"> | |
| 13 | 14 | <link rel="stylesheet" href="https://pico.sh/smol.css" /> | |
| 14 | 15 | <link rel="stylesheet" href="/main.css" /> | |
| 15 | 16 | </head> |
+10,
-2
| ... | ... | @@ -17,8 +17,16 @@ | |
| 17 | 17 | ||
| 18 | 18 | {{range .Tree.Items}} | |
| 19 | 19 | <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> | |
| 22 | 30 | </div> | |
| 23 | 31 | ||
| 24 | 32 | <div class="flex items-center gap"> |
M
main.go
+28,
-2
| ... | ... | @@ -7,7 +7,6 @@ import ( | |
| 7 | 7 | "flag" | |
| 8 | 8 | "fmt" | |
| 9 | 9 | "html/template" | |
| 10 | - | "io/ioutil" | |
| 11 | 10 | "math" | |
| 12 | 11 | "os" | |
| 13 | 12 | "path/filepath" |
| ... | ... | @@ -121,6 +120,7 @@ type TreeItem struct { | |
| 121 | 120 | Size string | |
| 122 | 121 | NumLines int | |
| 123 | 122 | Name string | |
| 123 | + | Icon string | |
| 124 | 124 | Path string | |
| 125 | 125 | URL template.URL | |
| 126 | 126 | CommitID string |
| ... | ... | @@ -337,7 +337,7 @@ func (c *Config) writeHtml(writeData *WriteData) { | |
| 337 | 337 | ||
| 338 | 338 | func (c *Config) copyStatic(dst string, data []byte) { | |
| 339 | 339 | c.Logger.Infof("writing (%s)", dst) | |
| 340 | - | err := ioutil.WriteFile(dst, data, 0755) | |
| 340 | + | err := os.WriteFile(dst, data, 0755) | |
| 341 | 341 | bail(err) | |
| 342 | 342 | } | |
| 343 | 343 |
| ... | ... | @@ -736,6 +736,30 @@ func (tw *TreeWalker) calcBreadcrumbs(curpath string) []*Breadcrumb { | |
| 736 | 736 | return crumbs | |
| 737 | 737 | } | |
| 738 | 738 | ||
| 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 | + | ||
| 739 | 763 | func (tw *TreeWalker) NewTreeItem(entry *git.TreeEntry, curpath string, crumbs []*Breadcrumb) *TreeItem { | |
| 740 | 764 | typ := entry.Type() | |
| 741 | 765 | fname := filepath.Join(curpath, entry.Name()) |
| ... | ... | @@ -782,6 +806,8 @@ func (tw *TreeWalker) NewTreeItem(entry *git.TreeEntry, curpath string, crumbs [ | |
| 782 | 806 | entry.Name(), | |
| 783 | 807 | "index.html", | |
| 784 | 808 | ) | |
| 809 | + | } else if typ == git.ObjectBlob { | |
| 810 | + | item.Icon = FilenameToDevIcon(item.Name) | |
| 785 | 811 | } | |
| 786 | 812 | item.URL = template.URL(fpath) | |
| 787 | 813 |
+8,
-0