Skip to content

Commit

Permalink
refactor: move function around
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Dec 7, 2023
1 parent fc1bc7a commit 1fdeded
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
18 changes: 1 addition & 17 deletions emanote/src/Emanote/Model/Graph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ((^.))
Expand Down Expand Up @@ -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) $
Expand Down
16 changes: 16 additions & 0 deletions emanote/src/Emanote/Model/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions emanote/src/Emanote/View/Export.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1fdeded

Please sign in to comment.