change directory logic
if dir has an index.html file, it gets <a> tag
This commit is contained in:
parent
d54a7d3a3c
commit
8bb441d9f9
1 changed files with 21 additions and 2 deletions
23
kew.go
23
kew.go
|
|
@ -46,6 +46,11 @@ func build_nav(dir string, root string) (NavNode, bool) {
|
||||||
if e.IsDir() {
|
if e.IsDir() {
|
||||||
child, ok := build_nav(full, root)
|
child, ok := build_nav(full, root)
|
||||||
if ok {
|
if ok {
|
||||||
|
_, err := os.Stat(filepath.Join(full, "index.md"))
|
||||||
|
if err == nil {
|
||||||
|
rel_dir, _ := filepath.Rel(root, full)
|
||||||
|
child.Path = rel_dir + "/index.html"
|
||||||
|
}
|
||||||
node.Children = append(node.Children, child)
|
node.Children = append(node.Children, child)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
|
|
@ -77,6 +82,7 @@ func render_nav(n NavNode, b *strings.Builder, cur string) {
|
||||||
if !strings.HasPrefix(p, "/") {
|
if !strings.HasPrefix(p, "/") {
|
||||||
p = "/" + p
|
p = "/" + p
|
||||||
}
|
}
|
||||||
|
|
||||||
sym := NavFileSymbol
|
sym := NavFileSymbol
|
||||||
if p == cur {
|
if p == cur {
|
||||||
sym = NavCurrentSymbol
|
sym = NavCurrentSymbol
|
||||||
|
|
@ -85,8 +91,21 @@ func render_nav(n NavNode, b *strings.Builder, cur string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range n.Children {
|
for _, c := range n.Children {
|
||||||
/* directory label with symbol */
|
sym := NavDirSymbol
|
||||||
b.WriteString("<li>" + c.Name + NavDirSymbol)
|
if c.Path == cur {
|
||||||
|
sym = NavCurrentSymbol
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Path != "" {
|
||||||
|
p := c.Path
|
||||||
|
if !strings.HasPrefix(p, "/") {
|
||||||
|
p = "/" + p
|
||||||
|
}
|
||||||
|
b.WriteString(`<li><a href="` + p + `">` + c.Name + sym + `</a>`)
|
||||||
|
} else {
|
||||||
|
b.WriteString("<li>" + c.Name + sym)
|
||||||
|
}
|
||||||
|
|
||||||
render_nav(c, b, cur)
|
render_nav(c, b, cur)
|
||||||
b.WriteString("</li>\n")
|
b.WriteString("</li>\n")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue