refactor metadata; always apply all metadata parsers; hide index and clients

This commit is contained in:
Sarah Vaupel 2023-11-29 13:32:13 +01:00
parent 203a3722b4
commit b58dca1c9a

View File

@ -58,17 +58,17 @@ stripPathPrefix (splitDirectories -> prefix) =
handleIf :: Exception e => (e -> Bool) -> (e -> IO a) -> IO a -> IO a
handleIf predicate handler = handle $ \exc -> bool throwIO handler (predicate exc) exc
metadataSort :: [Item w] -> Compiler [Item w]
metadataSort = sortOnM $ \Item{itemIdentifier} -> maybe (0 :: Integer) read <$> getMetadataField itemIdentifier "sort"
where
sortOnM :: forall m a b. (Monad m, Ord b) => (a -> m b) -> [a] -> m [a]
sortOnM f = fmap (map snd . List.sortOn fst) . mapM (\x -> (,x) <$> f x)
metadataShow :: [Item w] -> Compiler [Item w]
metadataShow = filterM $ \Item{itemIdentifier} -> maybe (True :: Bool) read <$> getMetadataField itemIdentifier "show"
metadata :: [Item w] -> Compiler [Item w]
metadata = metadataShow >=> metadataSort
where
metadataShow :: [Item w] -> Compiler [Item w]
metadataShow = filterM $ \Item{itemIdentifier} -> maybe (True :: Bool) read <$> getMetadataField itemIdentifier "show"
metadataSort :: [Item w] -> Compiler [Item w]
metadataSort = sortOnM $ \Item{itemIdentifier} -> maybe (0 :: Integer) read <$> getMetadataField itemIdentifier "sort"
where
sortOnM :: forall m a b. (Monad m, Ord b) => (a -> m b) -> [a] -> m [a]
sortOnM f = fmap (map snd . List.sortOn fst) . mapM (\x -> (,x) <$> f x)
unwrapped :: Snapshot
unwrapped = "unwrapped"
@ -244,7 +244,7 @@ main =
let
ctx =
mconcat
[ listField "posts" postContext (metadataSort =<< loadAll posts)
[ listField "posts" postContext (metadata =<< loadAll posts)
, defaultContext
]