Skip to content

Commit

Permalink
Add option to show folders first in the sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
jfpedroza committed Dec 22, 2022
1 parent 465a22b commit b6ed9a3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
11 changes: 6 additions & 5 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 12 additions & 6 deletions src/Emanote/View/Template.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b6ed9a3

Please sign in to comment.