Last active
December 14, 2015 03:09
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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