summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim McStanton <jim@jhmcstanton.com>2021-07-16 14:13:43 -0500
committerGitHub <noreply@github.com>2021-07-16 22:13:43 +0300
commitd739fd1eea40de9ded3b4f682c849d3c31eba92c (patch)
tree4b9a8b0fe1061a65fcf1359410ffc8ecd65f8159
parent0ad582562ba79e082417d5aaa3d7733859e55306 (diff)
downloadhakyll-d739fd1eea40de9ded3b4f682c849d3c31eba92c.tar.gz
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 <eual.jp@gmail.com>
-rw-r--r--lib/Hakyll/Web/Tags.hs12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/Hakyll/Web/Tags.hs b/lib/Hakyll/Web/Tags.hs
index aab5d34..ccf34a5 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)
--------------------------------------------------------------------------------