blob: c227491e60f96eaacce971029c87b1c220e188df (
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
35
36
37
38
39
40
41
42
43
|
module Issue.Tag (Tag (..), extractTags, internalTags) where
import Data.Binary (Binary)
import Data.Maybe (catMaybes)
import Data.Text (Text, pack)
import Data.Text qualified as T
import Data.Time.Clock (UTCTime (utctDay))
import GHC.Generics (Generic)
import Issue.Provenance (Provenance (..))
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 -> Maybe Provenance -> [Tag]
internalTags title provenance' =
concat
[ [ Tag "id" (toSpinalCase title)
],
maybe
[]
( \provenance ->
[ Tag "createdAt" (pack (show (utctDay provenance.date)))
]
)
provenance'
]
toSpinalCase :: Text -> Text
toSpinalCase = T.replace " " "-" . T.filter keep . T.toLower
where
keep = (`elem` (concat [[' ', '-'], ['a' .. 'z'], ['0' .. '9']]))
|