use sets for tags

This commit is contained in:
rhiannon morris 2024-11-04 00:55:07 +01:00
parent b9b0edc173
commit 34bd2214f5
4 changed files with 19 additions and 17 deletions

View file

@ -13,7 +13,8 @@ import Data.Maybe (fromMaybe, isJust)
import qualified Data.Text as Strict
import qualified Data.Text.Lazy as Lazy
import System.FilePath (joinPath, splitPath)
import qualified Data.HashSet as Set
import Data.HashSet (HashSet)
import qualified Data.HashSet as HashSet
import Data.Traversable
import Data.Semigroup
import Data.List.NonEmpty (toList)
@ -242,9 +243,9 @@ filterI :: (a -> Bool) -> Inf a -> Inf a
filterI p (x :> xs) = if p x then x :> filterI p xs else filterI p xs
addIds :: Traversable t => t Image -> t (Image, Text)
addIds = snd . mapAccumL makeId Set.empty where
makeId used img = (Set.insert newId used, (img, newId)) where
newId = headI $ filterI (\i -> not $ i `Set.member` used) ids
addIds = snd . mapAccumL makeId HashSet.empty where
makeId used img = (HashSet.insert newId used, (img, newId)) where
newId = headI $ filterI (\i -> not $ i `HashSet.member` used) ids
ids = fmap (\i -> toStrictText [b|$label$i|]) suffixes
label = escId $ img.label
@ -314,7 +315,7 @@ altButton img i = [b|
warning' = ifJust warning \(escAttr -> w) -> [b|$& data-warning="$w"|]
alt = img.desc
makeTags :: FilePath -> [Strict.Text] -> Builder
makeTags :: FilePath -> HashSet Strict.Text -> Builder
makeTags undir tags =
if null tags then "" else [b|
<nav id=tags class=info-section>
@ -325,7 +326,7 @@ makeTags undir tags =
</nav>
|]
where
tagList = map makeTag tags
tagList = map makeTag $ sort $ HashSet.toList tags
makeTag tag = [b|<li><a href="$undir#require_$tag'">$tag</a>|]
where tag' = escId tag