Skip to content

Commit 553a5c7

Browse files
committed
refactor(hickey): hoist lmlSourcePath from View.Export.JSON to Route.ModelRoute
lmlSourcePath is withLmlRoute encodeRoute — a pure route-layer helper with no View or JSON-export concern. Its home was an accident of being the first consumer's module. Adding MCP.Tools as a non-View consumer made the layering inversion visible (MCP depending on View). Move it to its natural home alongside withLmlRoute / mkLMLRouteFromKnownFilePath. lmlRouteKey stays in View.Export.JSON (single-consumer, JSON-key-specific) but now derives from R.lmlSourcePath instead of redefining the body.
1 parent e62efd8 commit 553a5c7

4 files changed

Lines changed: 12 additions & 15 deletions

File tree

emanote/src/Emanote/MCP/Tools.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import Emanote.Model.Title qualified as Tit
4242
import Emanote.Route qualified as R
4343
import Emanote.Route.Ext (LML (Md, Org))
4444
import Emanote.Route.ModelRoute (mkLMLRouteFromKnownFilePath)
45-
import Emanote.View.Export.JSON (lmlSourcePath)
4645
import MCP.Server (
4746
CallToolResult,
4847
InputSchema (..),
@@ -83,7 +82,7 @@ data NoteMatch = NoteMatch
8382

8483
noteMatchOf :: Model -> R.LMLRoute -> NoteMatch
8584
noteMatchOf model r =
86-
let p = toText $ lmlSourcePath r
85+
let p = toText $ R.lmlSourcePath r
8786
in NoteMatch
8887
{ path = p
8988
, title = Tit.toPlain (M.modelLookupTitle r model)
@@ -106,7 +105,7 @@ findNotes query lim model =
106105
hit note =
107106
let r = note ^. N.noteRoute
108107
t = Tit.toPlain (note ^. N.noteTitle)
109-
p = toText (lmlSourcePath r)
108+
p = toText (R.lmlSourcePath r)
110109
in if q `T.isInfixOf` T.toLower t || q `T.isInfixOf` T.toLower p
111110
then Just (noteMatchOf model r)
112111
else Nothing

emanote/src/Emanote/Route/ModelRoute.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Emanote.Route.ModelRoute (
2020
lmlToHtmlRoute,
2121
mkLMLRouteFromFilePath,
2222
mkLMLRouteFromKnownFilePath,
23+
lmlSourcePath,
2324
isMdRoute,
2425
-- Static file routes
2526
StaticFileRoute,
@@ -158,3 +159,7 @@ mkLMLRouteFromKnownFilePath lmlType fp =
158159
case lmlType of
159160
Md -> fmap LMLRoute_Md (R.mkLmlRouteFromFilePath fp)
160161
Org -> fmap LMLRoute_Org (R.mkLmlRouteFromFilePath fp)
162+
163+
-- | Source-relative path of an LML note (e.g. @guide/mcp.md@).
164+
lmlSourcePath :: LMLRoute -> FilePath
165+
lmlSourcePath = withLmlRoute R.encodeRoute

emanote/src/Emanote/View/Export/Content.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Emanote.Route qualified as R
2020
import Emanote.Route.SiteRoute qualified as SR
2121
import Emanote.Route.SiteRoute.Class (lmlSiteRoute)
2222
import Emanote.Source.Loc (locResolve)
23-
import Emanote.View.Export.JSON (getBaseUrlFromModel, lmlSourcePath)
23+
import Emanote.View.Export.JSON (getBaseUrlFromModel)
2424
import NeatInterpolation (text)
2525
import Optics.Operators ((^.))
2626
import Relude
@@ -51,7 +51,7 @@ renderContentExport :: Model -> IO Text
5151
renderContentExport model = do
5252
let mBaseUrl = getBaseUrlFromModel model
5353
let notes_ = model ^. M.modelNotes
54-
noteList = sortOn (lmlSourcePath . Note._noteRoute) $ toList notes_
54+
noteList = sortOn (R.lmlSourcePath . Note._noteRoute) $ toList notes_
5555
exportedNotes <- catMaybes <$> mapM (exportNote model) noteList
5656
let urlHelpText = case mBaseUrl of
5757
Just _ -> "- URL: The full URL where this note can be accessed"
@@ -66,7 +66,7 @@ renderContentExport model = do
6666
generateNoteHeader :: Model -> Note.Note -> Text
6767
generateNoteHeader model note =
6868
let route = Note._noteRoute note
69-
sourcePath = lmlSourcePath route
69+
sourcePath = R.lmlSourcePath route
7070
noteTitle = Tit.toPlain $ Note._noteTitle note
7171
wikilinks = Note.noteSelfRefs note
7272
wikilinkTexts = toList $ fmap (toText . (show :: WL.WikiLink -> String)) wikilinks

emanote/src/Emanote/View/Export/JSON.hs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module Emanote.View.Export.JSON (
99
modelRels,
1010
currentVersion,
1111
lmlRouteKey,
12-
lmlSourcePath,
1312
getBaseUrlFromModel,
1413
) where
1514

@@ -73,7 +72,7 @@ renderJSONExport model =
7372
in SourceFile
7473
(Tit.toPlain tit)
7574
k
76-
(toText . lmlSourcePath <$> M.parentLmlRoute model r)
75+
(toText . R.lmlSourcePath <$> M.parentLmlRoute model r)
7776
(SR.siteRouteUrl model $ lmlSiteRoute (R.LMLView_Html, r))
7877
meta_
7978
(fromMaybe [] $ Map.lookup k rels)
@@ -98,13 +97,7 @@ modelRels model =
9897
--
9998
-- We use the source path consistently.
10099
lmlRouteKey :: LMLRoute -> Text
101-
lmlRouteKey =
102-
toText . R.withLmlRoute R.encodeRoute
103-
104-
-- Path of the LML note
105-
lmlSourcePath :: LMLRoute -> FilePath
106-
lmlSourcePath =
107-
R.withLmlRoute R.encodeRoute
100+
lmlRouteKey = toText . R.lmlSourcePath
108101

109102
-- | Get base URL from model configuration (returns Nothing if not configured)
110103
getBaseUrlFromModel :: Model -> Maybe Text

0 commit comments

Comments
 (0)