diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-10-05 10:03:31 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-10-05 10:03:31 +0200 |
commit | 16da8a1ea6187f4bd5ef176f2aed64403b111c8c (patch) | |
tree | f304e9983afa5b9170e29f7bf0df7933e2aa1c4c /app/Issue | |
parent | 1890844c731b4c5c648b1871193947144aefa3dd (diff) |
generate internal @id tag from title
Diffstat (limited to 'app/Issue')
-rw-r--r-- | app/Issue/Tag.hs | 17 | ||||
-rw-r--r-- | app/Issue/Text.hs | 4 |
2 files changed, 15 insertions, 6 deletions
diff --git a/app/Issue/Tag.hs b/app/Issue/Tag.hs index 2699342..af12331 100644 --- a/app/Issue/Tag.hs +++ b/app/Issue/Tag.hs @@ -1,7 +1,8 @@ {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ViewPatterns #-} -module Issue.Tag (Tag (..), extract) where +module Issue.Tag (Tag (..), extractTags, internalTags) where import Data.Maybe (catMaybes) import Data.Text (Text) @@ -9,8 +10,8 @@ import Data.Text qualified as T data Tag = Tag Text Text deriving (Show) -extract :: Text -> [Tag] -extract = +extractTags :: Text -> [Tag] +extractTags = catMaybes . map ( ( \case @@ -21,3 +22,13 @@ extract = . 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']])) diff --git a/app/Issue/Text.hs b/app/Issue/Text.hs index 190e1c7..2d3aac4 100644 --- a/app/Issue/Text.hs +++ b/app/Issue/Text.hs @@ -16,9 +16,7 @@ extractText fileType rawText = (title, description) where text = stripComments fileType $ stripLines rawText stripLines = T.unlines . map T.strip . T.lines - (title, description') = - second T.stripStart $ - T.breakOn "\n\n" text + (title, description') = second T.stripStart $ T.breakOn "\n\n" text description | T.null description' = Nothing | otherwise = Just description' |