mirror of https://gerrit.hackerspace.pl/hscloud
Merge "hackdoc: do not render links to pages that wouldn't serve anything"
commit
77a5a4b388
|
@ -50,6 +50,29 @@ type pathPart struct {
|
||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *request) renderable(dirpath string) bool {
|
||||||
|
cfg, err := config.ForPath(r.ctx, r.source, dirpath)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("could not get config for path %q: %v", dirpath, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range cfg.DefaultIndex {
|
||||||
|
fpath := dirpath + "/" + f
|
||||||
|
file, err := r.source.IsFile(r.ctx, fpath)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("IsFile(%q): %v", fpath, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if file {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (r *request) handleFile(path string, cfg *config.Config) {
|
func (r *request) handleFile(path string, cfg *config.Config) {
|
||||||
data, err := r.source.ReadFile(r.ctx, path)
|
data, err := r.source.ReadFile(r.ctx, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -85,7 +108,11 @@ func (r *request) handleFile(path string, cfg *config.Config) {
|
||||||
label = label + "/"
|
label = label + "/"
|
||||||
}
|
}
|
||||||
fullPath += "/" + p
|
fullPath += "/" + p
|
||||||
pathParts = append(pathParts, pathPart{Label: label, Path: fullPath})
|
target := fullPath
|
||||||
|
if i != len(parts)-1 && !r.renderable("/"+fullPath) {
|
||||||
|
target = ""
|
||||||
|
}
|
||||||
|
pathParts = append(pathParts, pathPart{Label: label, Path: target})
|
||||||
}
|
}
|
||||||
|
|
||||||
vars := map[string]interface{}{
|
vars := map[string]interface{}{
|
||||||
|
|
|
@ -72,6 +72,7 @@ body {
|
||||||
font-family: Consolas, monospace;
|
font-family: Consolas, monospace;
|
||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
padding: 0.5em 0 0.5em 0;
|
padding: 0.5em 0 0.5em 0;
|
||||||
|
display: inline-flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header a {
|
.header a {
|
||||||
|
@ -231,7 +232,13 @@ h1,h2,h3,h4 {
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<span class="red">hackdoc:</span>
|
<span class="red">hackdoc:</span>
|
||||||
{{ range .PathParts }}<span class="part"><a href="{{ .Path }}">{{ .Label }}</a></span>{{ end }}
|
{{ range .PathParts }}
|
||||||
|
{{ if ne .Path "" }}
|
||||||
|
<span class="part"><a href="{{ .Path }}">{{ .Label }}</a></span>
|
||||||
|
{{ else }}
|
||||||
|
<span class="part">{{ .Label }}</span>
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
<span class="red" style="margin-left: 1em;">shortcuts:</span> <a href="/">root</a>, <a href="/cluster/doc">cluster docs</a>, <a href="/doc/codelabs">codelabs</a>
|
<span class="red" style="margin-left: 1em;">shortcuts:</span> <a href="/">root</a>, <a href="/cluster/doc">cluster docs</a>, <a href="/doc/codelabs">codelabs</a>
|
||||||
</div>
|
</div>
|
||||||
{{ .Rendered }}
|
{{ .Rendered }}
|
||||||
|
|
Loading…
Reference in New Issue