diff --git a/flake.lock b/flake.lock index 6937d2f2b..42dc1f82f 100644 --- a/flake.lock +++ b/flake.lock @@ -68,15 +68,16 @@ "heist-extra": { "flake": false, "locked": { - "lastModified": 1668486579, - "narHash": "sha256-VmyGntVH/tVosftplC4O0JhYA34kXeq1Wu/RbJr132Y=", - "owner": "srid", + "lastModified": 1671699412, + "narHash": "sha256-dYS5GlDeG3DcSf2O3nebKWiwI5Z4NLsNksWbN+cGKPw=", + "owner": "jfpedroza", "repo": "heist-extra", - "rev": "da94abfa68f67933baef9b529fe8d2a4edc572d5", + "rev": "76406ad2fabfa7eb7dbeeb12909379c639df9f5e", "type": "github" }, "original": { - "owner": "srid", + "owner": "jfpedroza", + "ref": "jp/tree-splice-sort-children", "repo": "heist-extra", "type": "github" } diff --git a/flake.nix b/flake.nix index 34585ab2e..218a67638 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ haskell-flake.url = "github:srid/haskell-flake"; # TODO: Dependencies waiting to go from Hackage to nixpkgs. - heist-extra.url = "github:srid/heist-extra"; + heist-extra.url = "github:jfpedroza/heist-extra/jp/tree-splice-sort-children"; heist-extra.flake = false; heist.url = "github:snapframework/heist"; # Waiting for 1.1.1.0 on nixpkgs cabal hashes heist.flake = false; diff --git a/src/Emanote/View/Template.hs b/src/Emanote/View/Template.hs index eb7f61d26..4d360e0d2 100644 --- a/src/Emanote/View/Template.hs +++ b/src/Emanote/View/Template.hs @@ -170,7 +170,7 @@ renderLmlHtml model note = do backlinksSplice backlinksNoDaily let folgeAnc = G.modelFolgezettelAncestorTree modelRoute model "ema:note:uptree" ## - Splices.treeSplice (const ()) folgeAnc $ + Splices.treeSplice (\_ _ -> ()) folgeAnc $ \(last -> nodeRoute) children -> do "node:text" ## C.titleSplice ctx $ M.modelLookupTitle nodeRoute model "node:url" ## HI.textSplice $ SR.siteRouteUrl model $ SR.lmlSiteRoute nodeRoute @@ -191,16 +191,22 @@ routeTreeSplice :: routeTreeSplice tCtx mr model = do "ema:route-tree" ## ( let tree = PathTree.treeDeleteChild "index" $ model ^. M.modelNav - getOrder tr = - ( Meta.lookupRouteMeta @Int 0 (one "order") tr model, - tr - ) + getFoldersFirst tr = + Meta.lookupRouteMeta @Bool False ("template" :| ["sidebar", "folders-first"]) tr model + getOrder path children = + let tr = mkLmlRoute path + isLeaf = null children + priority = if getFoldersFirst tr && isLeaf then 1 else 0 :: Integer + in ( priority, + Meta.lookupRouteMeta @Int 0 (one "order") tr model, + tr + ) getCollapsed tr = Meta.lookupRouteMeta @Bool True ("template" :| ["sidebar", "collapsed"]) tr model mkLmlRoute = M.resolveLmlRoute model . R.mkRouteFromSlugs lmlRouteSlugs = R.withLmlRoute R.unRoute - in Splices.treeSplice (getOrder . mkLmlRoute) tree $ \(mkLmlRoute -> nodeRoute) children -> do + in Splices.treeSplice getOrder tree $ \(mkLmlRoute -> nodeRoute) children -> do "node:text" ## C.titleSplice tCtx $ M.modelLookupTitle nodeRoute model "node:url" ## HI.textSplice $ SR.siteRouteUrl model $ SR.lmlSiteRoute nodeRoute let isActiveNode = Just nodeRoute == mr