slug generation improvements

This commit is contained in:
rhiannon morris 2024-09-15 17:39:37 +02:00
parent 32edbb1816
commit 0438ee590f
2 changed files with 9 additions and 5 deletions

View file

@ -25,10 +25,14 @@ getOptionsWith hdr mkDef descrs = do
exitFailure
makeSlug :: Text -> Text
makeSlug name = Text.map toSlugChar name where
toSlugChar c
| isAlphaNum c && isAscii c || c == '-' = toLower c
| otherwise = '_'
makeSlug = Text.intercalate "-" . filter (not . Text.null) . chunks where
chunks txt =
if Text.null txt then [] else
let (this', that') = Text.span isOK txt
this = Text.map toLower this'
that = Text.dropWhile (not . isOK) that' in
this : chunks that
isOK c = (isAlphaNum c && isAscii c) || c == '-'
toTextList :: MetaValue -> Maybe [Text]