Skip to content

Commit

Permalink
Supporting different field names for tags. (#862)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
jhmcstanton and Minoru authored Jul 16, 2021
1 parent 0ad5825 commit d739fd1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/Hakyll/Web/Tags.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
module Hakyll.Web.Tags
( Tags (..)
, getTags
, getTagsByField
, getCategory
, buildTagsWith
, buildTags
Expand Down Expand Up @@ -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)


--------------------------------------------------------------------------------
Expand Down

0 comments on commit d739fd1

Please sign in to comment.