From 23b2c6dcd08574e4622a1e5137befb81879c6d1b Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Sun, 17 Feb 2019 00:43:12 +0800 Subject: [PATCH] Fix bug in sorting of entryList --- src/Lib.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Lib.hs b/src/Lib.hs index 80cf44f..a0f089e 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -31,10 +31,10 @@ type EntryList = [(Text, [(Text, [(Text, BlogEntry)])])] format t format = fromString $ formatTime defaultTimeLocale format $ utcToLocalTime (hoursToTimeZone 8) t myGroup :: (Eq a, Ord a) => [(a, b)] -> [(a, [b])] -myGroup = map (\l -> (fst . head $ l, map snd l)) . groupBy ((==) `on` fst) +myGroup = map (\l -> (fst . head $ l, map snd l)) . groupBy ((==) `on` fst) . sortBy (comparing fst) stampsToEntryList :: [BlogEntry] -> EntryList -stampsToEntryList stamps = map (\(a,b) -> (a, reverse $ map (\(c,d) -> (c, map (\(x, y) -> ("0" `append` (fromString . show) x, y)) $ zip [1..] d)) b)) $ +stampsToEntryList stamps = reverse $ map (\(a,b) -> (a, reverse $ map (\(c,d) -> (c, map (\(x, y) -> ("0" `append` (fromString . show) x, y)) $ zip [1..] d)) b)) $ map (\(a, b) -> (a, myGroup b)) $ map (\(a, b) -> (a, concat b)) $ myGroup $ foldl (\c -> \v -> @@ -49,12 +49,13 @@ entryListToPaths el = concat $ concat $ map (\(year, months) month) entries) months) el entryListToIndex :: EntryList -> Text -entryListToIndex el = unorderedList Nothing $ map (\(year, monthList) -> unorderedList (Just year) $ map (\(month, entryList) -> unorderedList (Just month) $ map (\x -> " year <> "/" <> month <> "/" <> ((slugify . title . snd) x) <> ".html\">" <> (title . snd) x <> "") entryList) monthList) el +entryListToIndex el = unorderedList Nothing $ map (\(year, monthList) -> unorderedList (Just year) $ map (\(month, entryList) -> unorderedList (Just month) $ map (\x -> " year <> "/" <> month <> "/" <> ((urlify . title . snd) x) <> ".html\">" <> (title . snd) x <> "") entryList) monthList) el i2t :: Integer -> Text i2t = (fromString . show) slugify = toLower. replace " " "-" +urlify = slugify . replace "?" "" timeStampToDateString = fromString . formatTime defaultTimeLocale "%d %B %Y" . utcToLocalTime (hoursToTimeZone 8) @@ -97,7 +98,7 @@ exportEntry entry = do "build", format (postDate entry) "%Y", format (postDate entry) "%B", - slugify (title entry) `append` ".html"]) $ unpack $ entryToMarkup entry entryTemplate + urlify (title entry) `append` ".html"]) $ unpack $ entryToMarkup entry entryTemplate exportIndex :: EntryList -> IO() exportIndex entryList = do -- 2.11.0