feat: if just one page called index.md in a folder make no drop down in the menu
All checks were successful
ci/woodpecker/push/commit Pipeline was successful
All checks were successful
ci/woodpecker/push/commit Pipeline was successful
This commit is contained in:
parent
d8d49f22e7
commit
541498bbf3
1 changed files with 21 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func CreateFilePageAndCopyContent(file File, outfolder string) error {
|
||||
|
|
@ -103,10 +104,30 @@ func GenerateMenu(files []File) MenuItem {
|
|||
}
|
||||
}
|
||||
}
|
||||
cleanupMenu(menu.Children)
|
||||
menu.Children = sortMenu(menu.Children)
|
||||
fmt.Printf("%+v\r\n", menu)
|
||||
return menu
|
||||
}
|
||||
|
||||
func cleanupMenu(input []*MenuItem) {
|
||||
log.Info().Msg("Clean Menu Item")
|
||||
// If an page hase just one child called index.md make it a single menu without children
|
||||
for _, i := range input {
|
||||
if len(i.Children) == 1 && strings.HasSuffix(i.Children[0].Link, "index.html") {
|
||||
i.Page = true
|
||||
i.Link = i.Children[0].Link
|
||||
i.Name = i.Children[0].Name
|
||||
i.Text = i.Children[0].Text
|
||||
i.File = i.Children[0].File
|
||||
i.Level = i.Children[0].Level
|
||||
i.Children = nil
|
||||
continue
|
||||
}
|
||||
cleanupMenu(i.Children)
|
||||
}
|
||||
}
|
||||
|
||||
func sortMenu(input []*MenuItem) []*MenuItem {
|
||||
sort.Slice(input, func(i, j int) bool {
|
||||
return strings.ToLower(input[i].Name) < strings.ToLower(input[j].Name)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue