From 3c774922945cca0b21560373bf7cbeb15aa4b8c6 Mon Sep 17 00:00:00 2001 From: Rhiannon Morris Date: Mon, 3 Aug 2020 23:07:59 +0200 Subject: [PATCH] add tags to gallery items --- make-pages/GalleryPage.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/make-pages/GalleryPage.hs b/make-pages/GalleryPage.hs index ac2a9de..04f75fc 100644 --- a/make-pages/GalleryPage.hs +++ b/make-pages/GalleryPage.hs @@ -2,8 +2,10 @@ module GalleryPage (make) where import Control.Exception +import Data.Foldable import Data.Function (on, (&)) -import Data.List (sortOn, groupBy) +import qualified Data.HashMap.Strict as HashMap +import Data.List (intersperse, groupBy, sortOn) import qualified Data.Text.Lazy as Lazy import System.FilePath ((), takeDirectory, joinPath, splitPath) import GHC.Exts (Down (..), the) @@ -61,6 +63,12 @@ make' title prefix nsfw infos = [b|@0 then group by Down year using groupBy'] groupBy' f = groupBy ((==) `on` f) undir = joinPath (replicate (length (splitPath prefix)) "..") + allTags = infos + & concatMap (map (,1) . tagsFor nsfw . #second) + & HashMap.fromListWith (+) & HashMap.toList + & sortOn (\(tag, count) -> (Down count, tag)) + requireFilters = map (uncurry $ makeFilter "require") allTags + excludeFilters = map (uncurry $ makeFilter "exclude") allTags makeYearItems :: Bool -- ^ nsfw -> Integer -- ^ year @@ -77,7 +85,7 @@ makeYearItems nsfw year infos = [b|@4 makeItem :: Bool -> FilePath -> Info -> Builder makeItem nsfw file info@(Info {title}) = [b|@4 -
  • +
  • @@ -89,3 +97,4 @@ makeItem nsfw file info@(Info {title}) = [b|@4 dir = takeDirectory file thumb = maybe (throw $ NoThumb dir) (\t -> dir thumbFile t) $ #thumb info nsfw' = if nsfw && #anyNsfw info then " nsfw" else "" + tags' = fold $ intersperse ";" $ map fromText $ tagsFor nsfw info