summaryrefslogtreecommitdiffstats
path: root/app/Settings.hs
diff options
context:
space:
mode:
Diffstat (limited to 'app/Settings.hs')
-rw-r--r--app/Settings.hs25
1 files changed, 23 insertions, 2 deletions
diff --git a/app/Settings.hs b/app/Settings.hs
index 08b40bb..43f721c 100644
--- a/app/Settings.hs
+++ b/app/Settings.hs
@@ -16,6 +16,7 @@ import Data.Aeson qualified as A
import Data.Function (on)
import Data.List (nub)
import Data.Text qualified as T
+import Data.Vector qualified as V
import Data.Yaml (decodeFileThrow, encodeFile)
import GHC.Generics (Generic)
import System.Directory (doesFileExist)
@@ -47,7 +48,9 @@ instance Monoid Settings where
-- - perform minor corrections on OCR, ie. parse `0 1.01.1970`
--
-- @topic suggested-tags
- SuggestTagByRE "createdAt" [R.re|[0-9]{2}\.[0-9]{2}\.[0-9]{4}|],
+ SuggestTagByRE
+ "createdAt"
+ [R.ed|${d}([0-9]{2})\.${m}([0-9]{2})\.${y}([0-9]{4})///${y}-${m}-${d}|],
SuggestTagByTags "correspondent"
],
defaultLanguage = "deu+eng"
@@ -58,7 +61,7 @@ instance A.FromJSON Settings
instance A.ToJSON Settings
data SuggestedTag
- = SuggestTagByRE T.Text R.RE
+ = SuggestTagByRE T.Text (R.SearchReplace R.RE T.Text)
| SuggestTagByTags T.Text
deriving (Show, Generic, Eq)
@@ -68,6 +71,10 @@ instance Show R.RE where
instance Eq R.RE where
(==) = (==) `on` show
+instance (Eq re, Eq s) => Eq (R.SearchReplace re s) where
+ a == b =
+ ((==) `on` R.getSearch) a b && (((==) `on` R.getTemplate) a b)
+
instance A.FromJSON SuggestedTag
instance A.ToJSON SuggestedTag
@@ -78,6 +85,20 @@ instance A.FromJSON R.RE where
instance A.ToJSON R.RE where
toJSON = A.toJSON . R.reSource
+instance (A.FromJSON re, A.FromJSON s) => A.FromJSON (R.SearchReplace re s) where
+ parseJSON =
+ A.withArray
+ "regular search/replace expression (POSIX)"
+ ( \a -> do
+ re <- a `V.indexM` 0
+ s <- a `V.indexM` 1
+ R.SearchReplace <$> A.parseJSON re <*> A.parseJSON s
+ )
+
+instance (A.ToJSON re, A.ToJSON s) => A.ToJSON (R.SearchReplace re s) where
+ toJSON (R.SearchReplace re s) =
+ A.Array (V.fromList [A.toJSON re, A.toJSON s])
+
readSettings :: IO Settings
readSettings =
fmap mconcat