From 1fdeded7a701782fcf134a6dcb8a3a069666da4a Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Thu, 7 Dec 2023 15:25:51 -0500 Subject: [PATCH] refactor: move function around --- emanote/src/Emanote/Model/Graph.hs | 18 +----------------- emanote/src/Emanote/Model/Type.hs | 16 ++++++++++++++++ emanote/src/Emanote/View/Export.hs | 3 +-- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/emanote/src/Emanote/Model/Graph.hs b/emanote/src/Emanote/Model/Graph.hs index 5c6c5592b..3e6b84c96 100644 --- a/emanote/src/Emanote/Model/Graph.hs +++ b/emanote/src/Emanote/Model/Graph.hs @@ -11,7 +11,7 @@ import Emanote.Model.Link.Rel qualified as Rel import Emanote.Model.Link.Resolve qualified as Resolve import Emanote.Model.Meta (lookupRouteMeta) import Emanote.Model.Note qualified as MN -import Emanote.Model.Type (Model, modelRels, resolveLmlRoute) +import Emanote.Model.Type (Model, modelRels, parentLmlRoute) import Emanote.Route qualified as R import Emanote.Route.ModelRoute (ModelRoute) import Optics.Operators as Lens ((^.)) @@ -76,22 +76,6 @@ folgezettelParentsFor model r = do Rel.RRTFound x -> Just x _ -> Nothing -{- | Return the route to parent folder (unless indexRoute is passed). - - This will return the existing note (.org or .md) if possible. Otherwise - fallback to .md even if missing. --} -parentLmlRoute :: Model -> R.LMLRoute -> Maybe R.LMLRoute -parentLmlRoute model r = do - pr <- do - let lmlR = R.lmlRouteCase r - -- Root index do not have a parent folder. - guard $ lmlR /= Left R.indexRoute && lmlR /= Right R.indexRoute - -- Consider the index route as parent folder for all - -- top-level notes. - pure $ fromMaybe R.indexRoute $ R.withLmlRoute R.routeParent r - pure $ resolveLmlRoute model . coerce $ pr - modelLookupBacklinks :: ModelRoute -> Model -> [(R.LMLRoute, NonEmpty [B.Block])] modelLookupBacklinks r model = sortOn (Calendar.backlinkSortKey model . fst) $ diff --git a/emanote/src/Emanote/Model/Type.hs b/emanote/src/Emanote/Model/Type.hs index 195d64117..5b035ddd5 100644 --- a/emanote/src/Emanote/Model/Type.hs +++ b/emanote/src/Emanote/Model/Type.hs @@ -329,3 +329,19 @@ resolveLmlRouteIfExists notes r = do , N.lookupNotesByRoute (R.LMLRoute_Md $ coerce r) notes ] pure $ note ^. N.noteRoute + +{- | Return the route to parent folder (unless indexRoute is passed). + + This will return the existing note (.org or .md) if possible. Otherwise + fallback to .md even if missing. +-} +parentLmlRoute :: Model -> R.LMLRoute -> Maybe R.LMLRoute +parentLmlRoute model r = do + pr <- do + let lmlR = R.lmlRouteCase r + -- Root index do not have a parent folder. + guard $ lmlR /= Left R.indexRoute && lmlR /= Right R.indexRoute + -- Consider the index route as parent folder for all + -- top-level notes. + pure $ fromMaybe R.indexRoute $ R.withLmlRoute R.routeParent r + pure $ resolveLmlRoute model . coerce $ pr diff --git a/emanote/src/Emanote/View/Export.hs b/emanote/src/Emanote/View/Export.hs index d7c5d8e60..831dfaf31 100644 --- a/emanote/src/Emanote/View/Export.hs +++ b/emanote/src/Emanote/View/Export.hs @@ -11,7 +11,6 @@ import Data.Aeson qualified as Aeson import Data.Map.Strict qualified as Map import Emanote.Model (Model) import Emanote.Model qualified as M -import Emanote.Model.Graph qualified as G import Emanote.Model.Link.Rel qualified as Rel import Emanote.Model.Link.Resolve qualified as Resolve import Emanote.Model.Title qualified as Tit @@ -62,7 +61,7 @@ renderJSONExport model = in SourceFile (Tit.toPlain tit) k - (toText . lmlSourcePath <$> G.parentLmlRoute model r) + (toText . lmlSourcePath <$> M.parentLmlRoute model r) (SR.siteRouteUrl model $ lmlSiteRoute (R.LMLView_Html, r)) meta_ (fromMaybe [] $ Map.lookup k rels)