Skip to content

Commit

Permalink
WIP: Implement a backlinks query for a given Zettel ID
Browse files Browse the repository at this point in the history
Will be useful for editors to show a "nearby zettels" view.  See
felko/neuron-mode#30 for more details.
  • Loading branch information
pjones committed Jun 4, 2020
1 parent ac46252 commit 36773ff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions neuron/src/app/Neuron/CLI/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ commandParser defaultNotesDir today = do
<|> fmap
Right
(fmap (const $ Some $ Q.GraphQuery_Id) $ switch (long "graph" <> help "Get the entire zettelkasten graph as JSON"))
<|> fmap
Right
( fmap (Some . Q.GraphQuery_BacklinksOf) $
option
zettelIDReader
( long "backlinks-of"
<> help "Get a backlink graph of ID"
<> metavar "ID"
)
)
)
searchCommand = do
searchBy <-
Expand Down
3 changes: 3 additions & 0 deletions neuron/src/lib/Neuron/Zettelkasten/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ runZettelQuery zs = \case
runGraphQuery :: ZettelGraph -> GraphQuery r -> r
runGraphQuery g = \case
GraphQuery_Id -> g
GraphQuery_BacklinksOf _ -> g -- FIXME: implement this

zettelQueryResultJson ::
forall r.
Expand Down Expand Up @@ -104,3 +105,5 @@ graphQueryResultJson q r errors =
resultJson = case q of
GraphQuery_Id ->
toJSON r
GraphQuery_BacklinksOf _ ->
toJSON r
3 changes: 3 additions & 0 deletions neuron/src/lib/Neuron/Zettelkasten/Query/Graph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ import Data.Dependent.Sum.Orphans ()
import Data.GADT.Compare.TH
import Data.GADT.Show.TH
import Neuron.Zettelkasten.Graph.Type
import Neuron.Zettelkasten.ID
import Relude

-- | Like `GraphQuery` but focused on the relationship between zettels.
data GraphQuery r where
-- | Query the entire graph.
GraphQuery_Id :: GraphQuery ZettelGraph
-- | Query backlinks.
GraphQuery_BacklinksOf :: ZettelID -> GraphQuery ZettelGraph

deriveJSONGADT ''GraphQuery

Expand Down

0 comments on commit 36773ff

Please sign in to comment.