diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Main.hs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/app/Main.hs b/app/Main.hs index b21030d..cb6e563 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -27,6 +27,8 @@ import Data.String (IsString (fromString)) import Data.Text qualified as T import Data.Text.Encoding qualified as T import Data.Text.IO qualified as T +import Data.Time.Clock (UTCTime, getCurrentTime) +import Data.Time.Format.ISO8601 (iso8601Show) import Debug.Trace import GHC.Conc (getNumProcessors) import GHC.Generics (Generic) @@ -276,7 +278,7 @@ readDocument iFileName = <$> decodeFile @Index ("index" </> iFileName) applyFilters :: [Filter] -> [Document] -> [Document] -applyFilters filters = filter (pred filters) `at` (.index.tags) +applyFilters filters = filter (pred filters) `at` (.index.internalTags) where pred1 (FilterByTag tagKey) = hasTag (Tag tagKey Nothing) pred filters = \index -> all ($ index) (map pred1 filters) @@ -484,6 +486,7 @@ consume1 keep filePath = do if not hasText then ocr filePath else pure originalText' + addedAt <- getCurrentTime withGit do J.encodeFile iFilePath Index {tags = S.singleton (Tag "todo" Nothing), ..} if keep @@ -548,7 +551,8 @@ ocr1 tmp input = data Index = Index { originalText :: T.Text, - tags :: S.Set Tag + tags :: S.Set Tag, + addedAt :: UTCTime } deriving (Show, Generic, Eq) @@ -561,6 +565,17 @@ instance HasField "shortText" Index T.Text where (T.unlines . take 10 . T.lines) . (.originalText) +instance HasField "internalTags" Index (S.Set Tag) where + getField index = + index.tags + `S.union` internalTags index + +internalTags :: Index -> S.Set Tag +internalTags index = + S.fromList + [ Tag "addedAt" (Just (T.pack (iso8601Show index.addedAt))) + ] + data PdfInfo = PdfInfo { numPages :: Int, pageSize :: (Double, Double) |