diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-12-25 13:25:42 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-12-25 13:25:42 +0100 |
commit | 0ec8e1686013bbb3613d69b9271d7c5f2afdaaf9 (patch) | |
tree | d3cc7ad96b5058ff771acb7d2718367790e79b06 /app | |
parent | 47e17eec1e191e24a718a045c1550d5b5511428f (diff) |
chore: add library 'tags'
Diffstat (limited to 'app')
-rw-r--r-- | app/Main.hs | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/app/Main.hs b/app/Main.hs index 1c108fe..051752b 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -39,6 +39,7 @@ import System.IO import System.IO.LockFile (withLockFile) import System.IO.Temp (withSystemTempDirectory) import System.Process.Typed +import Tag import Text.Printf (printf) import Text.Read (readMaybe) @@ -201,7 +202,7 @@ main = do doRedoIf filters redo mapM_ ( \(Document {iFileName, index}) -> do - if hasTag (Tag "todo" Nothing) index + if hasTag (Tag "todo" Nothing) index.tags then printf "TODO %s\n" (takeBaseName iFileName) else printf " %s\n" (takeBaseName iFileName) ) @@ -275,7 +276,7 @@ readDocument iFileName = <$> decodeFile @Index ("index" </> iFileName) applyFilters :: [Filter] -> [Document] -> [Document] -applyFilters filters = filter (pred filters) `at` (.index) +applyFilters filters = filter (pred filters) `at` (.index.tags) where pred1 (FilterByTag tagKey) = hasTag (Tag tagKey Nothing) pred filters = \index -> all ($ index) (map pred1 filters) @@ -560,23 +561,6 @@ instance HasField "shortText" Index T.Text where (T.unlines . take 10 . T.lines) . (.originalText) -data Tag = Tag T.Text (Maybe T.Text) - deriving (Show, Generic, Eq, Ord) - -tagKey :: Tag -> T.Text -tagKey (Tag x _) = x - -tagValue :: Tag -> Maybe T.Text -tagValue (Tag _ x) = x - -hasTag :: Tag -> Index -> Bool -hasTag tag = - (tagKey tag `S.member`) . S.map tagKey . (.tags) - -instance J.ToJSON Tag - -instance J.FromJSON Tag - data PdfInfo = PdfInfo { numPages :: Int, pageSize :: (Double, Double) |