diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-12-28 04:14:43 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-12-28 04:14:43 +0100 |
commit | 490923b96d21c6009d23ec7e78a38a3db1864a87 (patch) | |
tree | d225dc273af38f9d13d801981295217a76df8ab2 | |
parent | 820d20e8f0689c49ce4ac59378182cc80cb48129 (diff) |
chore: add `modifiedAt`
-rw-r--r-- | app/Main.hs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/app/Main.hs b/app/Main.hs index 23c70d1..03a2960 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -27,7 +27,7 @@ import Data.Function ((&)) import Data.List import Data.List.NonEmpty qualified as N import Data.Map qualified as M -import Data.Maybe (catMaybes, fromMaybe, mapMaybe) +import Data.Maybe (catMaybes, fromMaybe, mapMaybe, maybeToList) import Data.Ord (comparing) import Data.Set qualified as S import Data.String (IsString (fromString)) @@ -627,6 +627,13 @@ addTag tag doc = doc {index = doc.index {addedAt = addedAt}} ) (iso8601ParseM . T.unpack =<< (G.tagValue tag)) + | G.tagKey tag == "modifiedAt" -> + maybe + (throw (AddTagException tag)) + ( \modifiedAt -> + doc {index = doc.index {modifiedAt = Just modifiedAt}} + ) + (iso8601ParseM . T.unpack =<< (G.tagValue tag)) | G.tagKey tag == "content" -> maybe (throw (AddTagException tag)) @@ -660,6 +667,8 @@ removeTag tag doc = doc {index = doc.index {todo = False}} | G.tagKey tag == "addedAt" -> throw (RemoveTagException tag) + | G.tagKey tag == "modifiedAt" -> + throw (RemoveTagException tag) | G.tagKey tag == "language" -> throw (RemoveTagException tag) | G.tagKey tag == "content" -> @@ -748,7 +757,14 @@ consume1 language force keep filePath = do else pure content' addedAt <- getCurrentTime withGit do - J.encodeFile iFilePath Index {tags = S.empty, todo = True, ..} + J.encodeFile + iFilePath + Index + { tags = S.empty, + todo = True, + modifiedAt = Nothing, + .. + } if keep then copyFile filePath oFilePath else renameFile filePath oFilePath @@ -813,6 +829,7 @@ data Index = Index { content :: T.Text, tags :: S.Set G.Tag, addedAt :: UTCTime, + modifiedAt :: Maybe UTCTime, todo :: Bool, language :: String } @@ -846,6 +863,7 @@ internalTags index = [ [ G.tag "addedAt" (Just (T.pack (iso8601Show index.addedAt))), G.tag "language" (Just (T.pack index.language)) ], + maybeToList (G.tag "modifiedAt" . Just . T.pack . iso8601Show <$> index.modifiedAt), if index.todo then [G.tag "todo" Nothing] else [] ] ) |