Files
nani.wtf/generator/src/Slug.hs
2020-09-21 22:03:52 -04:00

23 lines
417 B
Haskell

{-# LANGUAGE OverloadedStrings #-}
module Slug
( toSlug,
)
where
import Data.Char (isAlphaNum)
import qualified Data.Text as T
keepAlphaNum :: Char -> Char
keepAlphaNum x
| isAlphaNum x = x
| otherwise = ' '
clean :: T.Text -> T.Text
clean =
T.map keepAlphaNum . T.replace "'" "" . T.replace "&" "and"
toSlug :: T.Text -> T.Text
toSlug =
T.intercalate (T.singleton '-') . T.words . T.toLower . clean