init
This commit is contained in:
commit
fa6a4c650f
93 files changed
+6555
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (s *Server) expandMacros(
|
||||
body string,
|
||||
currentPath string,
|
||||
) string {
|
||||
|
||||
if strings.Contains(
|
||||
body,
|
||||
"{{children}}",
|
||||
) {
|
||||
|
||||
children, err :=
|
||||
s.store.ListChildPaths(
|
||||
currentPath,
|
||||
)
|
||||
|
||||
if err == nil {
|
||||
|
||||
var b strings.Builder
|
||||
|
||||
b.WriteString(
|
||||
`<section class="children-list">`,
|
||||
)
|
||||
|
||||
b.WriteString("<ul>")
|
||||
|
||||
for _, child := range children {
|
||||
|
||||
name :=
|
||||
strings.TrimPrefix(
|
||||
child,
|
||||
currentPath,
|
||||
)
|
||||
|
||||
name =
|
||||
strings.TrimPrefix(
|
||||
name,
|
||||
"/",
|
||||
)
|
||||
|
||||
b.WriteString(
|
||||
fmt.Sprintf(
|
||||
`<li><a href="%s">%s</a></li>`,
|
||||
child,
|
||||
name,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
b.WriteString("</ul>")
|
||||
b.WriteString("</section>")
|
||||
|
||||
body = strings.ReplaceAll(
|
||||
body,
|
||||
"{{children}}",
|
||||
b.String(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return body
|
||||
}
|
||||
Reference in new issue
Block a user