From d739fd1eea40de9ded3b4f682c849d3c31eba92c Mon Sep 17 00:00:00 2001 From: Jim McStanton Date: Fri, 16 Jul 2021 14:13:43 -0500 Subject: [PATCH] Supporting different field names for tags. (#862) * Supporting different field names for tags. * Removed buildTagsByField Removed to avoid exponential growth of helper functions. Renamed field parameter in getTagsByField to fieldName to avoid shadowing. * Drop obsolete export Co-authored-by: Alexander Batischev --- lib/Hakyll/Web/Tags.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Hakyll/Web/Tags.hs b/lib/Hakyll/Web/Tags.hs index aab5d3438..ccf34a5f3 100644 --- a/lib/Hakyll/Web/Tags.hs +++ b/lib/Hakyll/Web/Tags.hs @@ -43,6 +43,7 @@ module Hakyll.Web.Tags ( Tags (..) , getTags + , getTagsByField , getCategory , buildTagsWith , buildTags @@ -105,11 +106,16 @@ data Tags = Tags -- | Obtain tags from a page in the default way: parse them from the @tags@ -- metadata field. This can either be a list or a comma-separated string. getTags :: MonadMetadata m => Identifier -> m [String] -getTags identifier = do +getTags = getTagsByField "tags" + +-- | Obtain tags from a page by name of the metadata field. These can be a list +-- or a comma-separated string +getTagsByField :: MonadMetadata m => String -> Identifier -> m [String] +getTagsByField fieldName identifier = do metadata <- getMetadata identifier return $ fromMaybe [] $ - (lookupStringList "tags" metadata) `mplus` - (map trim . splitAll "," <$> lookupString "tags" metadata) + (lookupStringList fieldName metadata) `mplus` + (map trim . splitAll "," <$> lookupString fieldName metadata) --------------------------------------------------------------------------------