generated from srid/ema-template
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Resolve.hs
45 lines (40 loc) · 1.46 KB
/
Resolve.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Emanote.Model.Link.Resolve where
import Commonmark.Extensions.WikiLink qualified as WL
import Emanote.Model.Link.Rel qualified as Rel
import Emanote.Model.Note qualified as MN
import Emanote.Model.StaticFile qualified as SF
import Emanote.Model.Type (Model)
import Emanote.Model.Type qualified as M
import Emanote.Route qualified as R
import Emanote.Route.SiteRoute qualified as SR
import Relude
resolveUnresolvedRelTarget ::
Model ->
Rel.UnresolvedRelTarget ->
Rel.ResolvedRelTarget SR.SiteRoute
resolveUnresolvedRelTarget model = \case
Rel.URTWikiLink (_wlType, wl) -> do
resolveWikiLinkMustExist model wl
<&> resourceSiteRoute
Rel.URTResource r ->
resolveModelRoute model r
<&> resourceSiteRoute
Rel.URTVirtual virtualRoute -> do
Rel.RRTFound $
SR.SiteRoute_VirtualRoute
virtualRoute
resolveWikiLinkMustExist ::
Model -> WL.WikiLink -> Rel.ResolvedRelTarget (Either MN.Note SF.StaticFile)
resolveWikiLinkMustExist model wl =
Rel.resolvedRelTargetFromCandidates $ M.modelWikiLinkTargets wl model
resolveModelRoute ::
Model -> R.ModelRoute -> Rel.ResolvedRelTarget (Either MN.Note SF.StaticFile)
resolveModelRoute model lr =
bitraverse
(`M.modelLookupNoteByRoute` model)
(`M.modelLookupStaticFileByRoute` model)
(R.modelRouteCase lr)
& maybe Rel.RRTMissing Rel.RRTFound
resourceSiteRoute :: Either MN.Note SF.StaticFile -> SR.SiteRoute
resourceSiteRoute =
either SR.noteFileSiteRoute SR.staticFileSiteRoute