diff --git a/application/source/document/files.go b/application/source/document/files.go index e2a9edd2e53a80af5a6a93f90a25f5997a5c387d..f773d14a471e69bddfc918f59690ba829a13ab02 100644 --- a/application/source/document/files.go +++ b/application/source/document/files.go @@ -5,6 +5,7 @@ package document import ( "errors" + "fmt" "os" "path" "path/filepath" @@ -40,13 +41,21 @@ func (m SourceFileMap) findByHash(hash string) *SourceFile { func buildFileMap(files []*SourceFile) (SourceFileMap, []string) { sort.Slice(files, func(i, j int) bool { - if files[i].level == files[j].level { - return files[i].relSourcePath < files[j].relSourcePath + if files[i].relSourcePath == files[j].relSourcePath { + if files[i].level < files[j].level { + return true + } + + return files[i].level < files[j].level } - return files[i].level < files[j].level + return files[i].relSourcePath < files[j].relSourcePath }) + for _, f := range files { + fmt.Println(f.relSourcePath, f.level) + } + keys := make([]string, 0, len(files)) mapFiles := make(map[string]*SourceFile) for _, file := range files { diff --git a/application/source/document/html.go b/application/source/document/html.go index 0eea67d0c82b01f4800e1008092eebddcd871df8..a85104db6a4231ce164464aba8ffe03eea1ba97d 100644 --- a/application/source/document/html.go +++ b/application/source/document/html.go @@ -239,12 +239,11 @@ func buildTree(body string) *Tree[DocumentNode] { if title, err := s.Html(); err == nil { aID = slug.Make(title) - } else { - aID = "" + e.DataAtom.String() + "-" + randomID() } - s.SetAttr("id", aID) - + if aID == "" { + aID = "" + e.DataAtom.String() + "-" + randomID() + } } payload := DocumentNode{