slug generation improvements
This commit is contained in:
parent
32edbb1816
commit
0438ee590f
2 changed files with 9 additions and 5 deletions
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue