module Issue.Tag (Tag (..), extractTags, internalTags) where import Data.Binary (Binary) import Data.Maybe (catMaybes) import Data.Text (Text) import Data.Text qualified as T import GHC.Generics (Generic) data Tag = Tag Text Text deriving (Show, Generic, Binary) extractTags :: Text -> [Tag] extractTags = catMaybes . map ( ( \case ((T.uncons -> Just ('@', k)) : v) -> Just (Tag k (T.unwords v)) _ -> Nothing ) . T.words ) . T.lines internalTags :: Text -> [Tag] internalTags title = [ Tag "id" (toSpinalCase title) ] toSpinalCase :: Text -> Text toSpinalCase = T.replace " " "-" . T.filter keep . T.toLower where keep = (`elem` (concat [[' ', '-'], ['a' .. 'z'], ['0' .. '9']]))