tangled
alpha
login
or
join now
julien.rbrt.fr
/
tangled-core
forked from
tangled.org/core
0
fork
atom
Monorepo for Tangled — https://tangled.org
0
fork
atom
overview
issues
pulls
pipelines
add file and folder into to tree/blob views
oppi.li
1 year ago
a2c04f40
c98ebeff
+73
-15
7 changed files
expand all
collapse all
unified
split
appview
pages
pages.go
templates
layouts
base.html
repo
blob.html
index.html
tree.html
knotserver
routes.go
types
repo.go
+22
appview/pages/pages.go
···
71
71
return s
72
72
},
73
73
"timeFmt": humanize.Time,
74
74
+
"byteFmt": humanize.Bytes,
74
75
"length": func(v []string) int {
75
76
return len(v)
76
77
},
···
293
294
BaseTreeLink string
294
295
BaseBlobLink string
295
296
types.RepoTreeResponse
297
297
+
}
298
298
+
299
299
+
type RepoTreeStats struct {
300
300
+
NumFolders uint64
301
301
+
NumFiles uint64
302
302
+
}
303
303
+
304
304
+
func (r RepoTreeParams) TreeStats() RepoTreeStats {
305
305
+
numFolders, numFiles := 0, 0
306
306
+
for _, f := range r.Files {
307
307
+
if !f.IsFile {
308
308
+
numFolders += 1
309
309
+
} else if f.IsFile {
310
310
+
numFiles += 1
311
311
+
}
312
312
+
}
313
313
+
314
314
+
return RepoTreeStats{
315
315
+
NumFolders: uint64(numFolders),
316
316
+
NumFiles: uint64(numFiles),
317
317
+
}
296
318
}
297
319
298
320
func (p *Pages) RepoTree(w io.Writer, params RepoTreeParams) error {
+1
-1
appview/pages/templates/layouts/base.html
···
17
17
{{ template "layouts/topbar" . }}
18
18
{{ end }}
19
19
</header>
20
20
-
<div class="container mx-auto px-10">
20
20
+
<div class="container mx-auto px-1">
21
21
<main class="content">{{ block "content" . }}{{ end }}</main>
22
22
<script src="/static/lucide.min.js"></script>
23
23
<script>
+16
-5
appview/pages/templates/repo/blob.html
···
5
5
{{ $code_number_style := "text-gray-400 left-0 bg-white text-right mr-2 select-none" }}
6
6
{{ $linkstyle := "no-underline hover:underline" }}
7
7
<div class="pb-2 text-base">
8
8
-
{{ range $idx, $value := .BreadCrumbs }}
9
9
-
{{ if ne $idx (sub (len $.BreadCrumbs) 1) }}
8
8
+
<div class="flex justify-between">
9
9
+
<div id="breadcrumbs">
10
10
+
{{ range $idx, $value := .BreadCrumbs }}
11
11
+
{{ if ne $idx (sub (len $.BreadCrumbs) 1) }}
10
12
<a href="{{ index . 1}}" class="text-bold text-gray-500 {{ $linkstyle }}">{{ index . 0 }}</a> /
11
11
-
{{ else }}
13
13
+
{{ else }}
12
14
<span class="text-bold text-gray-500">{{ index . 0 }}</span>
13
13
-
{{ end }}
14
14
-
{{ end }}
15
15
+
{{ end }}
16
16
+
{{ end }}
17
17
+
</div>
18
18
+
<div id="file-info">
19
19
+
<span class="text-gray-500 text-xs">
20
20
+
{{ .Lines }} lines
21
21
+
·
22
22
+
{{ byteFmt .SizeHint }}
23
23
+
</span>
24
24
+
</div>
25
25
+
</div>
15
26
</div>
16
27
17
28
+1
-1
appview/pages/templates/repo/index.html
···
4
4
this repo is empty
5
5
{{ else }}
6
6
<div class="flex gap-4">
7
7
-
<div id="file-tree" class="w-1/2">
7
7
+
<div id="file-tree" class="w-3/5">
8
8
{{ $containerstyle := "py-1" }}
9
9
{{ $linkstyle := "no-underline hover:underline" }}
10
10
+27
-6
appview/pages/templates/repo/tree.html
···
5
5
{{ $linkstyle := "no-underline hover:underline" }}
6
6
7
7
<div class="pb-2 text-base">
8
8
-
{{ range .BreadCrumbs }}
9
9
-
<a href="{{ index . 1}}" class="text-bold text-gray-500 {{ $linkstyle }}">{{ index . 0 }}</a> /
10
10
-
{{ end }}
8
8
+
<div class="flex justify-between">
9
9
+
<div id="breadcrumbs">
10
10
+
{{ range .BreadCrumbs }}
11
11
+
<a href="{{ index . 1}}" class="text-bold text-gray-500 {{ $linkstyle }}">{{ index . 0 }}</a> /
12
12
+
{{ end }}
13
13
+
</div>
14
14
+
<div id="dir-info">
15
15
+
<span class="text-gray-500 text-xs">
16
16
+
{{ $stats := .TreeStats }}
17
17
+
18
18
+
{{ if eq $stats.NumFolders 1 }}
19
19
+
{{ $stats.NumFolders }} folder
20
20
+
·
21
21
+
{{ else if gt $stats.NumFolders 1 }}
22
22
+
{{ $stats.NumFolders }} folders
23
23
+
·
24
24
+
{{ end }}
25
25
+
26
26
+
{{ if eq $stats.NumFiles 1 }}
27
27
+
{{ $stats.NumFiles }} file
28
28
+
{{ else if gt $stats.NumFiles 1 }}
29
29
+
{{ $stats.NumFiles }} files
30
30
+
{{ end }}
31
31
+
</span>
32
32
+
</div>
33
33
+
</div>
11
34
</div>
12
35
13
36
{{ range .Files }}
···
19
42
<i class="w-3 h-3 fill-current" data-lucide="folder"></i>{{ .Name }}
20
43
</div>
21
44
</a>
45
45
+
<time class="text-xs text-gray-500">{{ timeFmt .LastCommit.Author.When }}</time>
22
46
</div>
23
23
-
<time class="text-xs text-gray-500">{{ timeFmt .LastCommit.Author.When }}</time>
24
47
</div>
25
48
{{ end }}
26
49
{{ end }}
···
28
51
{{ range .Files }}
29
52
{{ if .IsFile }}
30
53
<div class="{{ $containerstyle }}">
31
31
-
32
54
<div class="flex justify-between items-center">
33
55
<a href="/{{ $.BaseBlobLink }}/{{ .Name }}" class="{{ $linkstyle }}">
34
56
<div class="flex items-center gap-2">
35
57
<i class="w-3 h-3" data-lucide="file"></i>{{ .Name }}
36
58
</div>
37
59
</a>
38
38
-
39
60
<time class="text-xs text-gray-500">{{ timeFmt .LastCommit.Author.When }}</time>
40
61
</div>
41
62
</div>
+4
-1
knotserver/routes.go
···
215
215
return
216
216
}
217
217
218
218
-
safe := string(sanitize([]byte(contents)))
218
218
+
bytes := []byte(contents)
219
219
+
safe := string(sanitize(bytes))
220
220
+
sizeHint := len(bytes)
219
221
220
222
resp := types.RepoBlobResponse{
221
223
Ref: ref,
222
224
Contents: string(safe),
223
225
Path: treePath,
224
226
IsBinary: isBinaryFile,
227
227
+
SizeHint: uint64(sizeHint),
225
228
}
226
229
227
230
h.showFile(resp, w, l)
+2
-1
types/repo.go
···
69
69
Path string `json:"path,omitempty"`
70
70
IsBinary bool `json:"is_binary,omitempty"`
71
71
72
72
-
Lines int `json:"lines,omitempty"`
72
72
+
Lines int `json:"lines,omitempty"`
73
73
+
SizeHint uint64 `json:"size_hint,omitempty"`
73
74
}