diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-10-17 09:29:31 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-10-17 09:29:31 +0200 |
commit | 0d7cb474e6eb9a8bb5b6c9b1adf09b3b29760ff1 (patch) | |
tree | be5608ddfac7cbe3fa00f9afa3b663aae19833df | |
parent | 236316221dc1fe4152028d7720b68a437bb3ea52 (diff) |
allow empty-valued (bool) tags
-rw-r--r-- | app/Issue.hs | 6 | ||||
-rw-r--r-- | app/Issue/Filter.hs | 3 | ||||
-rw-r--r-- | app/Issue/Sort.hs | 2 | ||||
-rw-r--r-- | app/Issue/Tag.hs | 10 |
4 files changed, 11 insertions, 10 deletions
diff --git a/app/Issue.hs b/app/Issue.hs index 8804929..efb61b7 100644 --- a/app/Issue.hs +++ b/app/Issue.hs @@ -29,10 +29,8 @@ data Issue = Issue id :: Issue -> Maybe String id issue = - (\(Tag _ v) -> T.unpack v) - <$> ( find (\(Tag k _) -> k == "id") $ - issue.tags ++ issue.internalTags - ) + (\(Tag _ v) -> T.unpack <$> v) + =<< find (\(Tag k _) -> k == "id") (issue.tags ++ issue.internalTags) fromMatch :: FilePath -> G.Result -> G.Match -> IO (Maybe Issue) fromMatch cwd result match = do diff --git a/app/Issue/Filter.hs b/app/Issue/Filter.hs index c330407..fb6d205 100644 --- a/app/Issue/Filter.hs +++ b/app/Issue/Filter.hs @@ -7,6 +7,7 @@ where import Control.Applicative (liftA2) import Control.Arrow (second) +import Data.Maybe (fromMaybe) import Data.Text (Text) import Data.Text qualified as T import Issue (Issue (..)) @@ -63,4 +64,4 @@ simpleFilterPredicate :: SimpleFilter -> (Issue -> Bool) simpleFilterPredicate (ByTag k v) i = any ((&&) <$> matchKey <*> matchValue) i.tags where matchKey (Tag k' _) = k' == k - matchValue (Tag _ v') = maybe True ((==) v') v + matchValue (Tag _ v') = fromMaybe True ((==) <$> v' <*> v) diff --git a/app/Issue/Sort.hs b/app/Issue/Sort.hs index 1a0b3ff..2195244 100644 --- a/app/Issue/Sort.hs +++ b/app/Issue/Sort.hs @@ -63,6 +63,6 @@ applySortBy :: SortBy -> Issue -> [Text] applySortBy (SortByTag k) i = sort ( mapMaybe - (\(Tag k' v) -> if k' == k then Just v else Nothing) + (\(Tag k' v) -> if k' == k then v else Nothing) (i.tags ++ i.internalTags) ) diff --git a/app/Issue/Tag.hs b/app/Issue/Tag.hs index c227491..8b6d6d4 100644 --- a/app/Issue/Tag.hs +++ b/app/Issue/Tag.hs @@ -8,7 +8,7 @@ import Data.Time.Clock (UTCTime (utctDay)) import GHC.Generics (Generic) import Issue.Provenance (Provenance (..)) -data Tag = Tag Text Text deriving (Show, Generic, Binary) +data Tag = Tag Text (Maybe Text) deriving (Show, Generic, Binary) extractTags :: Text -> [Tag] extractTags = @@ -16,7 +16,9 @@ extractTags = . map ( ( \case ((T.uncons -> Just ('@', k)) : v) -> - Just (Tag k (T.unwords v)) + case T.strip (T.unwords v) of + "" -> Just (Tag k Nothing) + v' -> Just (Tag k (Just v')) _ -> Nothing ) . T.words @@ -26,12 +28,12 @@ extractTags = internalTags :: Text -> Maybe Provenance -> [Tag] internalTags title provenance' = concat - [ [ Tag "id" (toSpinalCase title) + [ [ Tag "id" $ Just $ toSpinalCase title ], maybe [] ( \provenance -> - [ Tag "createdAt" (pack (show (utctDay provenance.date))) + [ Tag "createdAt" $ Just $ pack $ show $ utctDay provenance.date ] ) provenance' |