Files
pages/internal/server/macro_expand.go
T
2026-05-19 21:30:42 +09:00

69 lines
844 B
Go

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
}