Skip to content

Instantly share code, notes, and snippets.

@nagisa
Last active December 14, 2015 03:09
Show Gist options
  • Save nagisa/5019206 to your computer and use it in GitHub Desktop.
Save nagisa/5019206 to your computer and use it in GitHub Desktop.
For people who want to sort items in hakyll by time in metadata
sortOnM :: (Monad m, Ord k) => (a -> m k) -> [a] -> m [a]
sortOnM f xs = liftM (map fst . sortBy (comparing snd)) $
mapM (\x -> liftM (x,) (f x)) xs
chronologicalMeta :: [Item a] -> Compiler [Item a]
chronologicalMeta = sortOnM $ getItemUTC defaultTimeLocale . itemIdentifier
recentFirstMeta :: [Item a] -> Compiler [Item a]
recentFirstMeta i = return . reverse =<< chronologicalMeta i
-- loadAllSorted :: (Binary a, Typeable a) => Pattern -> Compiler [Item a]
loadAllSorted p = loadAll p >>= recentFirstMeta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment