aboutsummaryrefslogtreecommitdiffstats
path: root/app/Issue/Tag.hs
blob: af12331d6a4a90409ce2ab9d8690796705fe9134 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

module Issue.Tag (Tag (..), extractTags, internalTags) where

import Data.Maybe (catMaybes)
import Data.Text (Text)
import Data.Text qualified as T

data Tag = Tag Text Text deriving (Show)

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']]))