Skip to content

Commit

Permalink
Compute uptree and expose as template variable (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Aug 7, 2021
1 parent 0925930 commit e1a438a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Before tests (tasks impacting the larger architectural context in code base),

- Zettelkasten / Graph considerations
- [ ] Incrementally build a graph of notes using [algebraic-graphs-patch](https://github.com/srid/emanote.obelisk/tree/master/lib/algebraic-graphs-patch)
- Tricky: unresolved wiki links cannot be resolved during graph patching; they must be deferred. This complicates implementation, and may involve using models like propagators. The same challenge applies to folgezettel queries (all querries, right now, are non-folgezettel for this reason).
- [ ] Consider computing uptree on demand (ie. when rendering a note) by traversing the IxSet's. https://github.com/srid/emanote/issues/25
- [ ] Using the graph, produce a folgezettel index (z-index) at `/-/folgezettel.html`
- [ ] Using the graph, reinstate neuron UpTree on top of each note
- [x] Reinstate Neuron look & feel (or just improve on it; make Emanote's note template distinct-looking, and an improved version of neuron's)
Expand Down
Empty file.
1 change: 1 addition & 0 deletions default/templates/layouts/note.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<apply template="components/breadcrumbs" />
<div class="flex-1 w-full overflow-x-auto bg-white">
<main class="px-4 py-4">
<apply template="components/note-uptree" />
<apply template="components/note-title" />
<apply template="components/note-body" />
<apply template="components/backlinks" />
Expand Down
2 changes: 1 addition & 1 deletion emanote.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.4
name: emanote
version: 0.1.43.2
version: 0.1.43.3
license: AGPL-3.0-only
copyright: 2021 Sridhar Ratnakumar
maintainer: srid@srid.ca
Expand Down
39 changes: 32 additions & 7 deletions src/Emanote/Model/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import Control.Lens.Operators as Lens ((%~), (^.))
import Control.Lens.TH (makeLenses)
import Data.IxSet.Typed ((@+), (@=))
import qualified Data.IxSet.Typed as Ix
import qualified Data.Set as Set
import Data.Time (UTCTime)
import Data.Tree (Tree)
import Data.Tree (Forest, Tree (Node))
import Ema (Slug)
import qualified Ema.Helper.PathTree as PathTree
import qualified Emanote.Model.Graph as G
Expand Down Expand Up @@ -41,6 +42,7 @@ data Model = Model
_modelRels :: IxRel,
_modelSData :: IxSData,
_modelStaticFiles :: IxStaticFile,
-- NOTE: This is unused.
_modelGraph :: G.Graph,
-- TODO: Avoid incremental building (which is complex), and compute this on
-- demand like `modelTags`? Use memoization to avoid repeat computation if
Expand Down Expand Up @@ -149,12 +151,35 @@ modelWikiLinkTargets wl model =

modelLookupBacklinks :: ModelRoute -> Model -> [(LMLRoute, [B.Block])]
modelLookupBacklinks r model =
let backlinks = Ix.toList $ (model ^. modelRels) @+ Rel.unresolvedRelsTo r
in -- HACK: See also sortByDateOrTitle in Query.hs
-- This is so that calendar backlinks are sorted properly.
sortOn (Down . flip modelLookupTitle model . fst) $
backlinks <&> \rel ->
(rel ^. Rel.relFrom, rel ^. Rel.relCtx)
-- HACK: See also sortByDateOrTitle in Query.hs
-- This is so that calendar backlinks are sorted properly.
sortOn (Down . flip modelLookupTitle model . fst) $
backlinkRels r model <&> \rel ->
(rel ^. Rel.relFrom, rel ^. Rel.relCtx)

backlinkRels :: ModelRoute -> Model -> [Rel.Rel]
backlinkRels r model =
let allPossibleLinks = Rel.unresolvedRelsTo r
in Ix.toList $ (model ^. modelRels) @+ allPossibleLinks

-- WIP https://github.com/srid/emanote/issues/25
modelFolgezettelAncestorTree :: ModelRoute -> Model -> Forest LMLRoute
modelFolgezettelAncestorTree r0 model =
go mempty r0
where
go :: Set ModelRoute -> ModelRoute -> Forest LMLRoute
go visited = \case
r | r `Set.member` visited -> mempty
r ->
backlinkRels r model & filter (selectFolgezttel . (^. Rel.relTo)) <&> \rel ->
let parentR = rel ^. Rel.relFrom
parentModelR = R.liftModelRoute . R.lmlRouteCase $ parentR
in Node parentR $ go (Set.insert r visited) parentModelR
selectFolgezttel = \case
Rel.URTWikiLink (WL.WikiLinkBranch, _wl) ->
True
_ ->
False

modelLookupStaticFileByRoute :: R 'AnyExt -> Model -> Maybe StaticFile
modelLookupStaticFileByRoute r =
Expand Down
2 changes: 1 addition & 1 deletion src/Emanote/Pandoc/Markdown/Syntax/WikiLink.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ inlineToWikiLink inl = do
Left (_, wl) <- delineateLink (otherAttrs <> one ("title", tit)) url
pure wl

-- | Return the various ways to link to this markdown route
-- | Return the various ways to link to this model route
--
-- Foo/Bar/Qux.md -> [[Qux]], [[Bar/Qux]], [[Foo/Bar/Qux]]
--
Expand Down
5 changes: 4 additions & 1 deletion src/Emanote/View/Template.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import qualified Heist.Extra.Splices.Tree as Splices
import qualified Heist.Extra.TemplateState as Tmpl
import qualified Heist.Interpreted as HI
import qualified Heist.Splices as Heist
import qualified Shower
import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Definition (Pandoc (..))

Expand Down Expand Up @@ -113,8 +114,9 @@ renderLmlHtml emaAction model note = do
-- Note stuff
"ema:note:title"
## titleSplice pageTitle
let modelRoute = R.liftModelRoute . R.lmlRouteCase $ r
"ema:note:backlinks"
## Splices.listSplice (M.modelLookupBacklinks (R.liftModelRoute . R.lmlRouteCase $ r) model) "backlink"
## Splices.listSplice (M.modelLookupBacklinks modelRoute model) "backlink"
$ \(source, backlinkCtx) -> do
-- TODO: reuse note splice
"backlink:note:title" ## titleSplice (M.modelLookupTitle source model)
Expand All @@ -124,6 +126,7 @@ renderLmlHtml emaAction model note = do
let ctxDoc :: Pandoc = Pandoc mempty $ one $ B.Div B.nullAttr backlinkCtx
withInlineCtx $ \ctx ->
Splices.pandocSplice ctx ctxDoc
"ema:note:uptree" ## HI.textSplice (toText . Shower.shower $ M.modelFolgezettelAncestorTree modelRoute model)
"ema:note:pandoc"
## withBlockCtx
$ \ctx ->
Expand Down

0 comments on commit e1a438a

Please sign in to comment.