From 0438ee590fd50e8658888d82bd84b91f4748ed2f Mon Sep 17 00:00:00 2001 From: rhiannon morris Date: Sun, 15 Sep 2024 17:39:37 +0200 Subject: [PATCH] slug generation improvements --- blog-meta/lib/Misc.hs | 12 ++++++++---- templates/taglist.html | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/blog-meta/lib/Misc.hs b/blog-meta/lib/Misc.hs index acf970d..b060ee3 100644 --- a/blog-meta/lib/Misc.hs +++ b/blog-meta/lib/Misc.hs @@ -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] diff --git a/templates/taglist.html b/templates/taglist.html index 4882947..c42f9f9 100644 --- a/templates/taglist.html +++ b/templates/taglist.html @@ -2,7 +2,7 @@