Skip to content

Commit

Permalink
Rename for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Apr 18, 2020
1 parent aa784c5 commit a7c63ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Neuron/CLI/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ commandParser defaultNotesDir = do
pure Open
queryCommand =
fmap Query $
many (Z.ByTag . Z.TagPattern <$> option str (long "tag" <> short 't'))
many (Z.Query_ZettelsByTag . Z.TagPattern <$> option str (long "tag" <> short 't'))
<|> option uriReader (long "uri" <> short 'u')
searchCommand = do
searchBy <-
Expand Down
10 changes: 6 additions & 4 deletions src/Neuron/Zettelkasten/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ import Neuron.Zettelkasten.Zettel
import Relude
import qualified Text.URI as URI

-- | Query represents a way to query the Zettelkasten.
--
-- TODO: Support querying connections, a la:
-- LinksTo ZettelID
-- LinksFrom ZettelID
data Query
= ByTag TagPattern
= Query_ZettelsByTag TagPattern
deriving (Eq, Show)

instance ToHtml Query where
toHtmlRaw = toHtml
toHtml (ByTag (TagPattern pat)) =
toHtml (Query_ZettelsByTag (TagPattern pat)) =
let desc = "Zettels matching tag '" <> toText pat <> "'"
in span_ [class_ "ui basic pointing below black label", title_ desc] $ toHtml pat

Expand All @@ -46,13 +48,13 @@ queryFromURI uri =
flip mapMaybe (URI.uriQuery uri) $ \case
URI.QueryParam (URI.unRText -> key) (URI.unRText -> val) ->
case key of
"tag" -> Just $ ByTag (TagPattern $ toString val)
"tag" -> Just $ Query_ZettelsByTag (TagPattern $ toString val)
_ -> Nothing
_ -> Nothing

matchQuery :: Zettel -> Query -> Bool
matchQuery Zettel {..} = \case
ByTag pat -> any (tagMatch pat) zettelTags
Query_ZettelsByTag pat -> any (tagMatch pat) zettelTags

matchQueries :: Zettel -> [Query] -> Bool
matchQueries zettel queries = and $ matchQuery zettel <$> queries
Expand Down

0 comments on commit a7c63ab

Please sign in to comment.